ledger-du 950 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. import string
  3. import sys
  4. import os
  5. import time
  6. from stat import *
  7. from os.path import *
  8. def report_file(path):
  9. dir_elems = string.split(dirname(path), os.sep)
  10. if dir_elems[0] == "." or dir_elems[0] == "":
  11. dir_elems = dir_elems[1 :]
  12. account = string.join(dir_elems, ":")
  13. info = os.stat(path)
  14. print time.strftime("%Y/%m/%d", time.localtime(info[ST_MTIME])),
  15. print basename(path)
  16. print " ", account, " ", info[ST_SIZE], "b"
  17. print " Equity:Files"
  18. print
  19. def find_files(path):
  20. xacts = os.listdir(path)
  21. for xact in xacts:
  22. xact = join(path, xact)
  23. if not islink(xact):
  24. if isdir(xact) and xact != "/proc":
  25. find_files(xact)
  26. else:
  27. report_file(xact)
  28. args = sys.argv[1:]
  29. if len(args):
  30. paths = args
  31. else:
  32. paths = ["."]
  33. print """
  34. C 1.00 Kb = 1024 b
  35. C 1.00 Mb = 1024 Kb
  36. C 1.00 Gb = 1024 Mb
  37. C 1.00 Tb = 1024 Gb
  38. """
  39. for path in paths:
  40. find_files(path)