Skip to content

Commit

Permalink
Replaced os.system() with subprocess.run()
Browse files Browse the repository at this point in the history
This is some groundwork for #31, since the `subprocess` module might have some capabilities that will help us capture and process the output.
  • Loading branch information
wleoncio committed Nov 14, 2023
1 parent ae06f7a commit f1f0e82
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions history.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/python3
import os
from os.path import exists, expanduser
import sys
from datetime import datetime

import subprocess

#Fetch LOGPATH into variable "log_path"
def get_log_path():
Expand All @@ -12,20 +10,21 @@ def get_log_path():
config_location = home_folder + "/.config/workoutPlan.conf"
stream = open(config_location, "r")
if exists(config_location):
log_path = home_folder + "/" + stream.readline().strip("LOGPATH=~")
log_path = home_folder + stream.readline().strip("LOGPATH=~")
log_path = log_path.strip()
return log_path
except FileNotFoundError as e:
sys.exit("No config file found to determine LOGPATH")

def display_files(arg1):
log_path = (get_log_path())
log_path = get_log_path()
if arg1 == "abc":
print("Sorting alfabetically")
os.system('tree ' + log_path + ' -i --dirsfirst')
command = ["tree", log_path, "-i", "--dirsfirst"]
else:
print("Sorting by time")
os.system('tree ' + log_path + ' -t --timefmt "%a %d-%b" --noreport')
command = ["tree", log_path, "-t", "--timefmt", "%a %d-%b", "--noreport"]
subprocess.run(command)

if len(sys.argv) == 2:
display_files(sys.argv[1])
Expand Down

0 comments on commit f1f0e82

Please sign in to comment.