tracker_types.add_argument('-p', '--path', type=str, help='Track total disk usage of a given path')
tracker_types.add_argument('-c', '--command', type=str, help='Track value returned by a shell command; this should return a single number, optionally followed by K/M/G/T')
args = parser.parse_args()
def parse_value(v):
suffix = v[-1].upper()
if suffix in SUFFIXES:
exponent = 3*(SUFFIXES.find(suffix)+1)
return int(v[:-1])*(10**exponent)
else:
return int(v)
def display_value(v):
suffix = ''
for c in SUFFIXES:
if v < 10**3:
break
v = v / 10**3
suffix = c
return '{:.1f}{}'.format(v, suffix)
def display_timedelta(d):
result = ''
if d.days != 0:
result += '{}d'.format(d.days)
result += '{}h'.format(d.seconds // 3600)
result += '{}m'.format((d.seconds % 3600) // 60)
return result
if args.path:
def current_val():
du = subprocess.run(['du', '--bytes', '--summarize', args.path], capture_output=True, text=True).stdout
return parse_value(du.split()[0])
else:
def current_val():
result = subprocess.run(args.command, shell=True, capture_output=True, text=True).stdout