From 2d72d5a7147680e68705a8641adae2de1951ec10 Mon Sep 17 00:00:00 2001 From: chrisbeardy <20585410+chrisbeardy@users.noreply.github.com> Date: Sun, 6 Feb 2022 13:22:57 +0000 Subject: [PATCH] cpu data is only saved on command line option --save --- vizex/cli.py | 4 ++-- vizex/vizexdu/cpu.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/vizex/cli.py b/vizex/cli.py index d5d38a1..83e6886 100644 --- a/vizex/cli.py +++ b/vizex/cli.py @@ -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" ) @@ -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 diff --git a/vizex/vizexdu/cpu.py b/vizex/vizexdu/cpu.py index 5b6b1ec..22a42a2 100644 --- a/vizex/vizexdu/cpu.py +++ b/vizex/vizexdu/cpu.py @@ -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' @@ -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], @@ -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() @@ -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")