Changeset 391 for python/trunk/Tools/scripts/byext.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Tools/scripts/byext.py
r2 r391 2 2 3 3 """Show file statistics by extension.""" 4 5 from __future__ import print_function 4 6 5 7 import os … … 24 26 self.addstats("<dir>", "dirs", 1) 25 27 try: 26 names = os.listdir(dir)27 except os.error ,err:28 names = sorted(os.listdir(dir)) 29 except os.error as err: 28 30 sys.stderr.write("Can't list %s: %s\n" % (dir, err)) 29 31 self.addstats("<dir>", "unlistable", 1) 30 32 return 31 names.sort()32 33 for name in names: 33 34 if name.startswith(".#"): … … 54 55 try: 55 56 f = open(filename, "rb") 56 except IOError ,err:57 except IOError as err: 57 58 sys.stderr.write("Can't open %s: %s\n" % (filename, err)) 58 59 self.addstats(ext, "unopenable", 1) … … 61 62 f.close() 62 63 self.addstats(ext, "bytes", len(data)) 63 if '\0' in data:64 if b'\0' in data: 64 65 self.addstats(ext, "binary", 1) 65 66 return … … 78 79 79 80 def report(self): 80 exts = self.stats.keys() 81 exts.sort() 81 exts = sorted(self.stats.keys()) 82 82 # Get the column keys 83 83 columns = {} 84 84 for ext in exts: 85 85 columns.update(self.stats[ext]) 86 cols = columns.keys() 87 cols.sort() 86 cols = sorted(columns.keys()) 88 87 colwidth = {} 89 88 colwidth["ext"] = max([len(ext) for ext in exts]) … … 110 109 def printheader(): 111 110 for col in cols: 112 print "%*s" % (colwidth[col], col),113 print 111 print("%*s" % (colwidth[col], col), end=" ") 112 print() 114 113 printheader() 115 114 for ext in exts: 116 115 for col in cols: 117 116 value = self.stats[ext].get(col, "") 118 print "%*s" % (colwidth[col], value),119 print 117 print("%*s" % (colwidth[col], value), end=" ") 118 print() 120 119 printheader() # Another header at the bottom 121 120
Note:
See TracChangeset
for help on using the changeset viewer.