[Python-checkins] python/dist/src/Tools/scripts byext.py,1.1,1.2

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 09 Apr 2003 12:10:51 -0700


Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv23373

Modified Files:
	byext.py 
Log Message:
Various improvements to the way the table is formatted, to deal with
exceptionally large totals etc.


Index: byext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/byext.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** byext.py	1 Jan 2003 14:41:25 -0000	1.1
--- byext.py	9 Apr 2003 19:10:46 -0000	1.2
***************
*** 31,34 ****
--- 31,38 ----
          names.sort()
          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)
              if os.path.islink(full):
***************
*** 43,47 ****
          head, base = os.path.split(file)
          if ext == base:
!             ext = "" # .cvsignore is deemed not to have an extension
          self.addstats(ext, "files", 1)
          try:
--- 47,54 ----
          head, base = os.path.split(file)
          if ext == base:
!             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)
          try:
***************
*** 71,75 ****
  
      def report(self):
-         totals = {}
          exts = self.stats.keys()
          exts.sort()
--- 78,81 ----
***************
*** 80,107 ****
          cols = columns.keys()
          cols.sort()
!         minwidth = 7
!         extwidth = max([len(ext) for ext in exts])
!         print "%*s" % (extwidth, "ext"),
          for col in cols:
!             width = max(len(col), minwidth)
!             print "%*s" % (width, col),
!         print
!         for ext in exts:
!             print "%*s" % (extwidth, ext),
!             for col in cols:
!                 width = max(len(col), minwidth)
                  value = self.stats[ext].get(col)
                  if value is None:
!                     s = ""
                  else:
!                     s = "%d" % value
!                     totals[col] = totals.get(col, 0) + value
!                 print "%*s" % (width, s),
              print
!         print "%*s" % (extwidth, "TOTAL"),
!         for col in cols:
!             width = max(len(col), minwidth)
!             print "%*s" % (width, totals[col]),
!         print
  
  def main():
--- 86,122 ----
          cols = columns.keys()
          cols.sort()
!         colwidth = {}
!         colwidth["ext"] = max([len(ext) for ext in exts])
!         minwidth = 6
!         self.stats["TOTAL"] = {}
          for col in cols:
!             total = 0
!             cw = max(minwidth, len(col))
!             for ext in exts:
                  value = self.stats[ext].get(col)
                  if value is None:
!                     w = 0
                  else:
!                     w = len("%d" % value)
!                     total += value
!                 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
!         printheader()
!         for ext in exts:
!             for col in cols:
!                 value = self.stats[ext].get(col, "")
!                 print "%*s" % (colwidth[col], value),
!             print
!         printheader() # Another header at the bottom
  
  def main():