Mercurial > cpython-lru_cache-weakref
annotate Demo/scripts/ftpstats.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 41524f9e2a2f |
| children |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1501
diff
changeset
|
1 #! /usr/bin/env python |
| 1501 | 2 |
| 3 # Extract statistics from ftp daemon log. | |
| 4 | |
| 5 # Usage: | |
| 6 # ftpstats [-m maxitems] [-s search] [file] | |
| 7 # -m maxitems: restrict number of items in "top-N" lists, default 25. | |
| 8 # -s string: restrict statistics to lines containing this string. | |
| 32721 | 9 # Default file is /usr/adm/ftpd; a "-" means read standard input. |
| 1501 | 10 |
| 11 # The script must be run on the host where the ftp daemon runs. | |
| 12 # (At CWI this is currently buizerd.) | |
| 13 | |
| 14 import os | |
| 15 import sys | |
|
37021
4727f260f6f8
Remove regsub, reconvert, regex, regex_syntax and everything under lib-old.
Neal Norwitz <nnorwitz@gmail.com>
parents:
33456
diff
changeset
|
16 import re |
| 1501 | 17 import string |
| 18 import getopt | |
| 19 | |
|
37021
4727f260f6f8
Remove regsub, reconvert, regex, regex_syntax and everything under lib-old.
Neal Norwitz <nnorwitz@gmail.com>
parents:
33456
diff
changeset
|
20 pat = '^([a-zA-Z0-9 :]*)!(.*)!(.*)!([<>].*)!([0-9]+)!([0-9]+)$' |
|
4727f260f6f8
Remove regsub, reconvert, regex, regex_syntax and everything under lib-old.
Neal Norwitz <nnorwitz@gmail.com>
parents:
33456
diff
changeset
|
21 prog = re.compile(pat) |
| 1501 | 22 |
| 23 def main(): | |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
24 maxitems = 25 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
25 search = None |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
26 try: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
27 opts, args = getopt.getopt(sys.argv[1:], 'm:s:') |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
28 except getopt.error, msg: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
29 print msg |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
30 print 'usage: ftpstats [-m maxitems] [file]' |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
31 sys.exit(2) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
32 for o, a in opts: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
33 if o == '-m': |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
34 maxitems = string.atoi(a) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
35 if o == '-s': |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
36 search = a |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
37 file = '/usr/adm/ftpd' |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
38 if args: file = args[0] |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
39 if file == '-': |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
40 f = sys.stdin |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
41 else: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
42 try: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
43 f = open(file, 'r') |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
44 except IOError, msg: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
45 print file, ':', msg |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
46 sys.exit(1) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
47 bydate = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
48 bytime = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
49 byfile = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
50 bydir = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
51 byhost = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
52 byuser = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
53 bytype = {} |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
54 lineno = 0 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
55 try: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
56 while 1: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
57 line = f.readline() |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
58 if not line: break |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
59 lineno = lineno + 1 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
60 if search and string.find(line, search) < 0: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
61 continue |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
62 if prog.match(line) < 0: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
63 print 'Bad line', lineno, ':', repr(line) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
64 continue |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
65 items = prog.group(1, 2, 3, 4, 5, 6) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
66 (logtime, loguser, loghost, logfile, logbytes, |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
67 logxxx2) = items |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
68 ## print logtime |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
69 ## print '-->', loguser |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
70 ## print '--> -->', loghost |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
71 ## print '--> --> -->', logfile |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
72 ## print '--> --> --> -->', logbytes |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
73 ## print '--> --> --> --> -->', logxxx2 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
74 ## for i in logtime, loghost, logbytes, logxxx2: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
75 ## if '!' in i: print '???', i |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
76 add(bydate, logtime[-4:] + ' ' + logtime[:6], items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
77 add(bytime, logtime[7:9] + ':00-59', items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
78 direction, logfile = logfile[0], logfile[1:] |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
79 # The real path probably starts at the last //... |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
80 while 1: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
81 i = string.find(logfile, '//') |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
82 if i < 0: break |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
83 logfile = logfile[i+1:] |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
84 add(byfile, logfile + ' ' + direction, items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
85 logdir = os.path.dirname(logfile) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
86 ## logdir = os.path.normpath(logdir) + '/.' |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
87 while 1: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
88 add(bydir, logdir + ' ' + direction, items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
89 dirhead = os.path.dirname(logdir) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
90 if dirhead == logdir: break |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
91 logdir = dirhead |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
92 add(byhost, loghost, items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
93 add(byuser, loguser, items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
94 add(bytype, direction, items) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
95 except KeyboardInterrupt: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
96 print 'Interrupted at line', lineno |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
97 show(bytype, 'by transfer direction', maxitems) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
98 show(bydir, 'by directory', maxitems) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
99 show(byfile, 'by file', maxitems) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
100 show(byhost, 'by host', maxitems) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
101 show(byuser, 'by user', maxitems) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
102 showbar(bydate, 'by date') |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
103 showbar(bytime, 'by time of day') |
| 1501 | 104 |
| 105 def showbar(dict, title): | |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
106 n = len(title) |
|
49164
41524f9e2a2f
#687648 from Robert Schuppenies: use classic division.
Andrew M. Kuchling <amk@amk.ca>
parents:
37021
diff
changeset
|
107 print '='*((70-n)//2), title, '='*((71-n)//2) |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
108 list = [] |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
109 keys = dict.keys() |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
110 keys.sort() |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
111 for key in keys: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
112 n = len(str(key)) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
113 list.append((len(dict[key]), key)) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
114 maxkeylength = 0 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
115 maxcount = 0 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
116 for count, key in list: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
117 maxkeylength = max(maxkeylength, len(key)) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
118 maxcount = max(maxcount, count) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
119 maxbarlength = 72 - maxkeylength - 7 |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
120 for count, key in list: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
121 barlength = int(round(maxbarlength*float(count)/maxcount)) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
122 bar = '*'*barlength |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
123 print '%5d %-*s %s' % (count, maxkeylength, key, bar) |
| 1501 | 124 |
| 125 def show(dict, title, maxitems): | |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
126 if len(dict) > maxitems: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
127 title = title + ' (first %d)'%maxitems |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
128 n = len(title) |
|
49164
41524f9e2a2f
#687648 from Robert Schuppenies: use classic division.
Andrew M. Kuchling <amk@amk.ca>
parents:
37021
diff
changeset
|
129 print '='*((70-n)//2), title, '='*((71-n)//2) |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
130 list = [] |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
131 keys = dict.keys() |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
132 for key in keys: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
133 list.append((-len(dict[key]), key)) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
134 list.sort() |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
135 for count, key in list[:maxitems]: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
136 print '%5d %s' % (-count, key) |
| 1501 | 137 |
| 138 def add(dict, key, item): | |
|
32735
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
139 if dict.has_key(key): |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
140 dict[key].append(item) |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
141 else: |
|
2bc66f1df7cc
Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents:
32721
diff
changeset
|
142 dict[key] = [item] |
| 1501 | 143 |
|
33456
487280cf71b9
Add 'if __name__ == "__main__":' to files already as a usable as a module.
Johannes Gijsbers <jlg@dds.nl>
parents:
32735
diff
changeset
|
144 if __name__ == "__main__": |
|
487280cf71b9
Add 'if __name__ == "__main__":' to files already as a usable as a module.
Johannes Gijsbers <jlg@dds.nl>
parents:
32735
diff
changeset
|
145 main() |
