#!/usr/local/bin/python # $Id: bldpdb4.py,v 1.1 2012/06/09 03:39:16 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. # This version does in-place formatting instead of using a raw list # to buffer line extractions. 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 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): while buffer[z] != "\n": z += 1 z += 1 # x-> Beginning of 1st line and z-> Beginning of 2nd line # Check to see if we are at the beginning of an archive comment if (buffer[x: x+7] == "Archive") and (string.lower(buffer[z-4:z-1]) == "zip"): # We are, so get another line w = z while buffer[w] != "\n": w += 1 w += 1 # x-> Beginning of 1st Line, z-> Beginning of 2nd line, w-> Beginning of 3rd line name = buffer[x+9:z-1] comment = buffer[z:w-1] pad = column - len(name) print name + pad * padchar + comment x = w # We are not at the beginning of an archive comment else: x = z os.chdir(root) os.path.walk("./", BuildList, None)