| 4 | import os, sys, errno |
| 5 | |
| 6 | def main(): |
| 7 | total, d = None, {} |
| 8 | with os.popen('du ' + ' '.join(sys.argv[1:])) as p: |
| 9 | for line in p: |
| 10 | i = 0 |
| 11 | while line[i] in '0123456789': i = i+1 |
| 12 | size = eval(line[:i]) |
| 13 | while line[i] in ' \t': i = i+1 |
| 14 | filename = line[i:-1] |
| 15 | comps = filename.split('/') |
| 16 | if comps[0] == '': comps[0] = '/' |
| 17 | if comps[len(comps)-1] == '': del comps[len(comps)-1] |
| 18 | total, d = store(size, comps, total, d) |
| 19 | try: |
| 20 | display(total, d) |
| 21 | except IOError as e: |
| 22 | if e.errno != errno.EPIPE: |
| 23 | raise |
| 24 | |
| 25 | def store(size, comps, total, d): |
| 26 | if comps == []: |