Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/dutree.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 981fff7363b9 |
| children | 6b18a095c2e7 |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1269
diff
changeset
|
1 #! /usr/bin/env python |
| 687 | 2 # Format du output in a tree shape |
| 3 | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15932
diff
changeset
|
4 import os, sys, errno |
| 687 | 5 |
| 6 def main(): | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15932
diff
changeset
|
7 p = os.popen('du ' + ' '.join(sys.argv[1:]), 'r') |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
8 total, d = None, {} |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
9 for line in p.readlines(): |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
10 i = 0 |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
11 while line[i] in '0123456789': i = i+1 |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
12 size = eval(line[:i]) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
13 while line[i] in ' \t': i = i+1 |
|
29107
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
25219
diff
changeset
|
14 filename = line[i:-1] |
|
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
25219
diff
changeset
|
15 comps = filename.split('/') |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
16 if comps[0] == '': comps[0] = '/' |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
17 if comps[len(comps)-1] == '': del comps[len(comps)-1] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
18 total, d = store(size, comps, total, d) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
19 try: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
20 display(total, d) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
21 except IOError, e: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
22 if e.errno != errno.EPIPE: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
23 raise |
| 687 | 24 |
| 25 def store(size, comps, total, d): | |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
26 if comps == []: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
27 return size, d |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
28 if not d.has_key(comps[0]): |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
29 d[comps[0]] = None, {} |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
30 t1, d1 = d[comps[0]] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
31 d[comps[0]] = store(size, comps[1:], t1, d1) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
32 return total, d |
| 687 | 33 |
| 34 def display(total, d): | |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
35 show(total, d, '') |
| 687 | 36 |
| 37 def show(total, d, prefix): | |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
38 if not d: return |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
39 list = [] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
40 sum = 0 |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
41 for key in d.keys(): |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
42 tsub, dsub = d[key] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
43 list.append((tsub, key)) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
44 if tsub is not None: sum = sum + tsub |
|
15932
1881b968989b
Hand repair of cases where reindent changed lines of the form
Tim Peters <tim.peters@gmail.com>
parents:
15930
diff
changeset
|
45 ## if sum < total: |
|
1881b968989b
Hand repair of cases where reindent changed lines of the form
Tim Peters <tim.peters@gmail.com>
parents:
15930
diff
changeset
|
46 ## list.append((total - sum, os.curdir)) |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
47 list.sort() |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
48 list.reverse() |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
29107
diff
changeset
|
49 width = len(repr(list[0][0])) |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
50 for tsub, key in list: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
51 if tsub is None: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
52 psub = prefix |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
53 else: |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15932
diff
changeset
|
54 print prefix + repr(tsub).rjust(width) + ' ' + key |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
55 psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
56 if d.has_key(key): |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10503
diff
changeset
|
57 show(tsub, d[key][1], psub) |
| 687 | 58 |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
59 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
60 main() |
