diff --git a/bldpdb.py b/bldpdb.py new file mode 100755 index 0000000..dc15429 --- /dev/null +++ b/bldpdb.py @@ -0,0 +1,47 @@ +#!/usr/local/bin/python +# $Id: bldpdb.py,v 1.1 2012/06/09 03:39:16 tundra Exp $ + +# Final Production Version + +# This version opens up all the ZIP files in a given directory at once +# and extracts their comments into a tmpfile for later formatted output. + +import os +import string +import tempfile + +root = "/pdbase/pub" # Top of the Zip archive +column = 55 # Column to place Zip Comment +padchar = ' ' # Padding character + +tmpfile = tempfile.mktemp() + +def BuildList(args, dir, files): + cmd = "/usr/local/bin/unzip -z " + filarg = "\""+dir + "/*\"" + redir = " 2>/dev/null >>" + tmpfile + ReadZip = cmd + filarg + redir + os.system(ReadZip) + +os.chdir(root) +os.path.walk("./", BuildList, None) + +f = open(tmpfile) +raw = f.readlines() +f.close() +os.unlink(tmpfile) + +x = 0 +y = len(raw) + +while (x < y): + if (raw[x][:7] == "Archive") and (string.lower(raw[x][-4:-1]) == "zip"): + name = raw[x][10:-1] + comment = raw[x+1][:-1] + pad = column - len(name) + print name + pad * padchar + comment + x += 2 + else: + x += 1 + + diff --git a/bldpdb1.py b/bldpdb1.py new file mode 100755 index 0000000..ddd8b32 --- /dev/null +++ b/bldpdb1.py @@ -0,0 +1,46 @@ +#!/usr/local/bin/python +# $Id: bldpdb1.py,v 1.1 2012/06/09 03:39:16 tundra Exp $ + +# This version opens each ZIP file individually to extract the comment +# and places the result in a tmpfile which is used for later formatted output. + +import os +import string +import tempfile + +root = "/usr/home/pdbase/pub" # Top of the Zip archive +column = 55 # Column to place Zip Comment +padchar = ' ' # Padding character + +tmpfile = tempfile.mktemp() + +def BuildList(args, dir, files): + for x in files: + if string.lower(x[-4:]) == ".zip": + cmd = "/usr/local/bin/unzip -z " + filarg = "\""+dir + "/" + x + "\"" + redir = ">>" + tmpfile + ReadZip = cmd + filarg + redir + os.system(ReadZip) + +os.chdir(root) +os.path.walk("./", BuildList, None) + +f = open(tmpfile) +raw = f.readlines() +f.close() +os.unlink(tmpfile) + + +x = 0 +y = len(raw) + +while (x < y): + name = raw[x][9:-1] + comment = raw[x+1][:-1] + pad = column - len(name) + print name + pad * padchar + comment + x += 2 + + + diff --git a/bldpdb2.py b/bldpdb2.py new file mode 100755 index 0000000..b86f1dd --- /dev/null +++ b/bldpdb2.py @@ -0,0 +1,48 @@ +#!/usr/local/bin/python +# $Id: bldpdb2.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 into a tmpfile for later formatted output. + +import os +import string +import tempfile + +root = "/usr/home/pdbase/pub" # Top of the Zip archive +column = 55 # Column to place Zip Comment +padchar = ' ' # Padding character + +tmpfile = tempfile.mktemp() + +def BuildList(args, dir, files): + cmd = "/usr/local/bin/unzip -z " + filarg = "\""+dir + "/*\"" + redir = " 2>/dev/null >>" + tmpfile + ReadZip = cmd + filarg + redir + os.system(ReadZip) + +os.chdir(root) +os.path.walk("./", BuildList, None) + +f = open(tmpfile) +raw = f.readlines() +f.close() +os.unlink(tmpfile) + + +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 + + + + diff --git a/bldpdb3.py b/bldpdb3.py new file mode 100755 index 0000000..851daaf --- /dev/null +++ b/bldpdb3.py @@ -0,0 +1,50 @@ +#!/usr/local/bin/python +# $Id: bldpdb3.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. + + +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 + + + diff --git a/bldpdb4.py b/bldpdb4.py new file mode 100755 index 0000000..a73dfbe --- /dev/null +++ b/bldpdb4.py @@ -0,0 +1,57 @@ +#!/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) + + + +