2 # Format du output in a tree shape
7 p = os.popen('du ' + ' '.join(sys.argv[1:]), 'r')
9 for line in p.readlines():
11 while line[i] in '0123456789': i = i+1
13 while line[i] in ' \t': i = 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)
22 if e.errno != errno.EPIPE:
25 def store(size, comps, total, d):
28 if not d.has_key(comps[0]):
29 d[comps[0]] = None, {}
31 d[comps[0]] = store(size, comps[1:], t1, d1)
34 def display(total, d):
37 def show(total, d, prefix):
43 list.append((tsub, key))
44 if tsub is not None: sum = sum + tsub
46 ## list.append((total - sum, os.curdir))
49 width = len(repr(list[0][0]))
50 for tsub, key in list:
54 print prefix + repr(tsub).rjust(width) + ' ' + key
55 psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1)
57 show(tsub, d[key][1], psub)
59 if __name__ == '__main__':