#!/usr/bin/python 'simple "unzip" replacement' import sys, os, zipfile def unzip(zipped): ziphandle = zipfile.ZipFile(zipped) sys.stderr.write('unzipping %s\n' % zipped) for zippedfile in ziphandle.infolist(): unzippedfile = os.path.join(os.curdir, zippedfile.filename.rstrip()) if (not os.path.isdir(os.path.dirname(unzippedfile))) and \ zippedfile.file_size > 0: sys.stderr.write('creating folder %s\n' % os.path.dirname(unzippedfile)) os.mkdir(os.path.dirname(unzippedfile)) if zippedfile.file_size == 0: sys.stderr.write('creating folder %s\n' % unzippedfile) os.mkdir(unzippedfile) # assume a directory, not always correct else: sys.stderr.write('creating file %s\n' % unzippedfile) unzipped = open(unzippedfile, 'wb') unzipped.write(ziphandle.read(zippedfile.filename.rstrip())) unzipped.close() if __name__ == '__main__': for filename in sys.argv[1:]: unzip(filename)