[Distutils] Oops; here's my "checkpycs" script
Fred L. Drake
Fred L. Drake, Jr." <fdrake@acm.org
Tue, 30 Mar 1999 09:49:46 -0500 (EST)
--a87wwq6rQI
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit
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
--a87wwq6rQI
Content-Type: text/plain
Content-Description: check .pyc & .pyo sizes in comparison table
Content-Disposition: inline;
filename="checkpycs"
Content-Transfer-Encoding: 7bit
#! /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()
--a87wwq6rQI--