#!/usr/local/bin/python # $Id: bldpdb3.py,v 1.100 2012/06/09 03:39:17 tundra Exp $ # This version opens up all the ZIP files in a given directory at once # and extracts their comments using a pipe instead of a tempfile. import commands import os import string root = "/usr/home/pdbase/pub" # Top of the Zip archive column = 55 # Column to place Zip Comment padchar = ' ' # Padding character raw = [] def BuildList(args, dir, files): cmd = "/usr/local/bin/unzip -z " filarg = "\""+dir + "/*\"" redir = " 2>/dev/null" ReadZip = cmd + filarg + redir buffer = commands.getoutput(ReadZip) + "\n" x = z = 0 y = len(buffer) while (x < y): if buffer[z] != "\n": # Keep reading 'til EOL z += 1 else: z += 1 # Then append to raw list raw.append(buffer[x:z]) x = z os.chdir(root) os.path.walk("./", BuildList, None) x = 0 y = len(raw) while (x < y): if (raw[x][:7] == "Archive") and (string.lower(raw[x][-4:-1]) == "zip"): name = raw[x][9:-1] comment = raw[x+1][:-1] pad = column - len(name) print name + pad * padchar + comment x += 2 else: x += 1