Skip to content

Commit

Permalink
cpu data is only saved on command line option --save
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbeardy committed Feb 6, 2022
1 parent 0d4239d commit 2d72d5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions vizex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def dirs_files(sort: str, all: str, desc: str, path: str, alias: str) -> None:
metavar='command')
@click.option(
"--save",
help="Export your disk usage data into a CSV or JSON file:"
help="Export your disk/cpu usage data into a CSV or JSON file:"
+ "Takes a full path with a file name as an argument. "
+ "File type will be defined based on a <.type> of the filename"
)
Expand Down Expand Up @@ -265,7 +265,7 @@ def disk_usage(arg, save, path, every,
print('Battery not found!')
elif arg == 'cpu':
cpus = CPUFreq()
cpus.display_separately()
cpus.display_separately(filename=save)
else:
renderer = DiskUsage(
path=path, exclude=exclude_list, details=details, every=every
Expand Down
12 changes: 8 additions & 4 deletions vizex/vizexdu/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def min_freq(self, minimum: int) -> None:
def __init__(self) -> None:
return

def display_separately(self, save=True) -> None:
def display_separately(self, filename="") -> None:
os.system('cls' if os.name == 'nt' else 'clear')
ch = HorizontalBarChart()
ch.options.graph_color = 'white'
Expand All @@ -54,7 +54,7 @@ def display_separately(self, save=True) -> None:
current=i.current - self._min
)

if save:
if filename:
cpu = {
'user': [getpass.getuser()],
'cpu': [n],
Expand All @@ -63,7 +63,11 @@ def display_separately(self, save=True) -> None:
'usage': [percent]
}

tools.save_to_csv(cpu, '~/cpus.csv')
if (filename.split(".")[-1].lower()) == 'csv':
tools.save_to_csv(cpu, filename)
else:
raise NameError("Not supported file type, please indicate "
+ ".CSV at the end of the filename")

print()

Expand Down Expand Up @@ -95,4 +99,4 @@ def display_combined(self) -> None:

if __name__ == '__main__':
cpu_freq = CPUFreq()
cpu_freq.display_separately()
cpu_freq.display_separately("~/cpu.csv")

0 comments on commit 2d72d5a

Please sign in to comment.