Oops; here's my "checkpycs" script

Sorry, I forgot to attach the promised script. (That seems to be my standard ritual for attachments!) Anyway, the "checkpycs" script is attached, really. -Fred -- Fred L. Drake, Jr. <fdrake@acm.org> Corporation for National Research Initiatives #! /usr/bin/env python # -*- Python -*- import errno import os import stat import string import sys VERBOSE = 0 COLUMN_WIDTHS = (40, 10, 10, 10) s = '' for cw in COLUMN_WIDTHS: if s: s = "%s %%%ds" % (s, cw) else: s = "%%%ds" % cw FORMAT = s del s, cw def process_dirs(dirlist, verbose=VERBOSE): fp = os.popen("find %s -name \*.py -print" % string.join(dirlist)) writeline("", " .py Size", ".pyc Size", ".pyo Size") writeline("", "---------", "---------", "---------") while 1: line = fp.readline() if not line: break filename = line[:-1] pysize = os.stat(filename)[stat.ST_SIZE] or "0" pycsize = pyosize = None if os.path.isfile(filename + "c"): pycsize = os.stat(filename + "c")[stat.ST_SIZE] if os.path.isfile(filename + "o"): pyosize = os.stat(filename + "o")[stat.ST_SIZE] if pycsize or pyosize or VERBOSE: writeline(filename, pysize, pycsize, pyosize) def writeline(c1, c2, c3, c4): c1 = c1 or "" c2 = c2 or "" c3 = c3 or "" c4 = c4 or "" if len(c1) > COLUMN_WIDTHS[0]: c1 = "..." + c1[-(COLUMN_WIDTHS[0] - 3):] print FORMAT % (c1, c2, c3, c4) def main(): try: process_dirs(sys.argv[1:] or ["."]) except IOError, e: if e.errno != errno.EPIPE: raise if __name__ == "__main__": main()
participants (1)
-
Fred L. Drake