mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
Minimal changes to make byext.py script work with Python 3 syntax.
This commit is contained in:
parent
63144c6444
commit
1ce5d181d7
1 changed files with 10 additions and 13 deletions
|
@ -23,12 +23,11 @@ class Stats:
|
||||||
def statdir(self, dir):
|
def statdir(self, dir):
|
||||||
self.addstats("<dir>", "dirs", 1)
|
self.addstats("<dir>", "dirs", 1)
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dir)
|
names = sorted(os.listdir(dir))
|
||||||
except os.error, err:
|
except os.error as err:
|
||||||
sys.stderr.write("Can't list %s: %s\n" % (dir, err))
|
sys.stderr.write("Can't list %s: %s\n" % (dir, err))
|
||||||
self.addstats("<dir>", "unlistable", 1)
|
self.addstats("<dir>", "unlistable", 1)
|
||||||
return
|
return
|
||||||
names.sort()
|
|
||||||
for name in names:
|
for name in names:
|
||||||
if name.startswith(".#"):
|
if name.startswith(".#"):
|
||||||
continue # Skip CVS temp files
|
continue # Skip CVS temp files
|
||||||
|
@ -53,14 +52,14 @@ class Stats:
|
||||||
self.addstats(ext, "files", 1)
|
self.addstats(ext, "files", 1)
|
||||||
try:
|
try:
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
except IOError, err:
|
except IOError as err:
|
||||||
sys.stderr.write("Can't open %s: %s\n" % (filename, err))
|
sys.stderr.write("Can't open %s: %s\n" % (filename, err))
|
||||||
self.addstats(ext, "unopenable", 1)
|
self.addstats(ext, "unopenable", 1)
|
||||||
return
|
return
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
self.addstats(ext, "bytes", len(data))
|
self.addstats(ext, "bytes", len(data))
|
||||||
if '\0' in data:
|
if b'\0' in data:
|
||||||
self.addstats(ext, "binary", 1)
|
self.addstats(ext, "binary", 1)
|
||||||
return
|
return
|
||||||
if not data:
|
if not data:
|
||||||
|
@ -77,14 +76,12 @@ class Stats:
|
||||||
d[key] = d.get(key, 0) + n
|
d[key] = d.get(key, 0) + n
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
exts = self.stats.keys()
|
exts = sorted(self.stats.keys())
|
||||||
exts.sort()
|
|
||||||
# Get the column keys
|
# Get the column keys
|
||||||
columns = {}
|
columns = {}
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
columns.update(self.stats[ext])
|
columns.update(self.stats[ext])
|
||||||
cols = columns.keys()
|
cols = sorted(columns.keys())
|
||||||
cols.sort()
|
|
||||||
colwidth = {}
|
colwidth = {}
|
||||||
colwidth["ext"] = max([len(ext) for ext in exts])
|
colwidth["ext"] = max([len(ext) for ext in exts])
|
||||||
minwidth = 6
|
minwidth = 6
|
||||||
|
@ -109,14 +106,14 @@ class Stats:
|
||||||
cols.insert(0, "ext")
|
cols.insert(0, "ext")
|
||||||
def printheader():
|
def printheader():
|
||||||
for col in cols:
|
for col in cols:
|
||||||
print "%*s" % (colwidth[col], col),
|
print("%*s" % (colwidth[col], col), end=" ")
|
||||||
print
|
print()
|
||||||
printheader()
|
printheader()
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
for col in cols:
|
for col in cols:
|
||||||
value = self.stats[ext].get(col, "")
|
value = self.stats[ext].get(col, "")
|
||||||
print "%*s" % (colwidth[col], value),
|
print("%*s" % (colwidth[col], value), end=" ")
|
||||||
print
|
print()
|
||||||
printheader() # Another header at the bottom
|
printheader() # Another header at the bottom
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue