Skip to content

Commit

Permalink
Merge pull request #47 from chrisbeardy/no_auto_cpu_save
Browse files Browse the repository at this point in the history
cpu data is only saved on command line option --save
  • Loading branch information
bexxmodd authored Feb 7, 2022
2 parents 203be1d + 2d72d5a commit a8c56d3
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 @@ -55,7 +55,7 @@ def display_separately(self, save=True) -> None:
current=current_freq - min_freq,
)

if save:
if filename:
cpu = {
'user': [getpass.getuser()],
'cpu': [i],
Expand All @@ -64,7 +64,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 a8c56d3

Please sign in to comment.