Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Tools/scripts/byext.py

    r2 r391  
    22
    33"""Show file statistics by extension."""
     4
     5from __future__ import print_function
    46
    57import os
     
    2426        self.addstats("<dir>", "dirs", 1)
    2527        try:
    26             names = os.listdir(dir)
    27         except os.error, err:
     28            names = sorted(os.listdir(dir))
     29        except os.error as err:
    2830            sys.stderr.write("Can't list %s: %s\n" % (dir, err))
    2931            self.addstats("<dir>", "unlistable", 1)
    3032            return
    31         names.sort()
    3233        for name in names:
    3334            if name.startswith(".#"):
     
    5455        try:
    5556            f = open(filename, "rb")
    56         except IOError, err:
     57        except IOError as err:
    5758            sys.stderr.write("Can't open %s: %s\n" % (filename, err))
    5859            self.addstats(ext, "unopenable", 1)
     
    6162        f.close()
    6263        self.addstats(ext, "bytes", len(data))
    63         if '\0' in data:
     64        if b'\0' in data:
    6465            self.addstats(ext, "binary", 1)
    6566            return
     
    7879
    7980    def report(self):
    80         exts = self.stats.keys()
    81         exts.sort()
     81        exts = sorted(self.stats.keys())
    8282        # Get the column keys
    8383        columns = {}
    8484        for ext in exts:
    8585            columns.update(self.stats[ext])
    86         cols = columns.keys()
    87         cols.sort()
     86        cols = sorted(columns.keys())
    8887        colwidth = {}
    8988        colwidth["ext"] = max([len(ext) for ext in exts])
     
    110109        def printheader():
    111110            for col in cols:
    112                 print "%*s" % (colwidth[col], col),
    113             print
     111                print("%*s" % (colwidth[col], col), end=" ")
     112            print()
    114113        printheader()
    115114        for ext in exts:
    116115            for col in cols:
    117116                value = self.stats[ext].get(col, "")
    118                 print "%*s" % (colwidth[col], value),
    119             print
     117                print("%*s" % (colwidth[col], value), end=" ")
     118            print()
    120119        printheader() # Another header at the bottom
    121120
Note: See TracChangeset for help on using the changeset viewer.