Commit 21123ab7 authored by Guido van Rossum's avatar Guido van Rossum

Various improvements to the way the table is formatted, to deal with

exceptionally large totals etc.
parent a12fe4e8
...@@ -30,6 +30,10 @@ class Stats: ...@@ -30,6 +30,10 @@ class Stats:
return return
names.sort() names.sort()
for name in names: for name in names:
if name.startswith(".#"):
continue # Skip CVS temp files
if name.endswith("~"):
continue# Skip Emacs backup files
full = os.path.join(dir, name) full = os.path.join(dir, name)
if os.path.islink(full): if os.path.islink(full):
self.addstats("<lnk>", "links", 1) self.addstats("<lnk>", "links", 1)
...@@ -42,7 +46,10 @@ class Stats: ...@@ -42,7 +46,10 @@ class Stats:
head, ext = os.path.splitext(file) head, ext = os.path.splitext(file)
head, base = os.path.split(file) head, base = os.path.split(file)
if ext == base: if ext == base:
ext = "" # .cvsignore is deemed not to have an extension ext = "" # E.g. .cvsignore is deemed not to have an extension
ext = os.path.normcase(ext)
if not ext:
ext = "<none>"
self.addstats(ext, "files", 1) self.addstats(ext, "files", 1)
try: try:
f = open(file, "rb") f = open(file, "rb")
...@@ -70,7 +77,6 @@ class Stats: ...@@ -70,7 +77,6 @@ class Stats:
d[key] = d.get(key, 0) + n d[key] = d.get(key, 0) + n
def report(self): def report(self):
totals = {}
exts = self.stats.keys() exts = self.stats.keys()
exts.sort() exts.sort()
# Get the column keys # Get the column keys
...@@ -79,30 +85,39 @@ class Stats: ...@@ -79,30 +85,39 @@ class Stats:
columns.update(self.stats[ext]) columns.update(self.stats[ext])
cols = columns.keys() cols = columns.keys()
cols.sort() cols.sort()
minwidth = 7 colwidth = {}
extwidth = max([len(ext) for ext in exts]) colwidth["ext"] = max([len(ext) for ext in exts])
print "%*s" % (extwidth, "ext"), minwidth = 6
self.stats["TOTAL"] = {}
for col in cols: for col in cols:
width = max(len(col), minwidth) total = 0
print "%*s" % (width, col), cw = max(minwidth, len(col))
print for ext in exts:
for ext in exts:
print "%*s" % (extwidth, ext),
for col in cols:
width = max(len(col), minwidth)
value = self.stats[ext].get(col) value = self.stats[ext].get(col)
if value is None: if value is None:
s = "" w = 0
else: else:
s = "%d" % value w = len("%d" % value)
totals[col] = totals.get(col, 0) + value total += value
print "%*s" % (width, s), cw = max(cw, w)
cw = max(cw, len(str(total)))
colwidth[col] = cw
self.stats["TOTAL"][col] = total
exts.append("TOTAL")
for ext in exts:
self.stats[ext]["ext"] = ext
cols.insert(0, "ext")
def printheader():
for col in cols:
print "%*s" % (colwidth[col], col),
print print
print "%*s" % (extwidth, "TOTAL"), printheader()
for col in cols: for ext in exts:
width = max(len(col), minwidth) for col in cols:
print "%*s" % (width, totals[col]), value = self.stats[ext].get(col, "")
print print "%*s" % (colwidth[col], value),
print
printheader() # Another header at the bottom
def main(): def main():
args = sys.argv[1:] args = sys.argv[1:]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment