Browse Source

Initial commit

master
Gavan Fantom 3 years ago
parent
commit
842fc7afd8
  1. 3
      README.md
  2. 55
      lstrend

3
README.md

@ -1,3 +1,6 @@
# lstrend
Show trend data for files changing size
usage: lstrend [-h] files [files ...]

55
lstrend

@ -0,0 +1,55 @@
#!/usr/bin/python3
import argparse
import os
import time
factor = 0.99
def get_sizes(files):
sizes = []
for file in files:
sizes.append(os.path.getsize(file))
return sizes
def human_format(num):
num = float('{:.3g}'.format(num))
magnitude = 0
while abs(num) >= 1024:
magnitude += 1
num /= 1024.0
return '{}{}'.format('{:.3f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'G', 'T', 'P'][magnitude])
def lstrend(files):
avgrates = None
sizes = None
stamp = None
while True:
lastsizes = sizes
laststamp = stamp
sizes = get_sizes(files)
stamp = time.monotonic()
if lastsizes:
diffs = [s-lastsizes[c] for c,s in enumerate(sizes)]
tdelta = stamp-laststamp
rates = [s/tdelta for s in diffs]
if avgrates:
avgrates = [avgrates[c]*factor+r*(1-factor) for c,r in enumerate(rates)]
else:
avgrates = rates
print()
for c,file in enumerate(files):
print("{: <20} {: >10} {: >10}".format(file, human_format(avgrates[c]), human_format(sizes[c])))
time.sleep(1)
def main():
parser = argparse.ArgumentParser(description='Show trend in file size')
parser.add_argument('files', nargs='+', help='files to list')
args = parser.parse_args()
lstrend(args.files)
if __name__ == "__main__":
main()
Loading…
Cancel
Save