diff options
author | Steven Knight <knight@baldmt.com> | 2004-07-29 18:55:37 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-07-29 18:55:37 (GMT) |
commit | 7707cce18557e7a8285fe7e0c2e1479e6e86b8d0 (patch) | |
tree | 3295b2cc20efc7006c60d0122fa23022dc09a80a /bin/scons-unzip.py | |
parent | 89330e2ad1be10e91444afc5b3979a23d1b853fe (diff) | |
download | SCons-7707cce18557e7a8285fe7e0c2e1479e6e86b8d0.zip SCons-7707cce18557e7a8285fe7e0c2e1479e6e86b8d0.tar.gz SCons-7707cce18557e7a8285fe7e0c2e1479e6e86b8d0.tar.bz2 |
Enhance runtest.py and add a script for automated regression-test runs.
Diffstat (limited to 'bin/scons-unzip.py')
-rw-r--r-- | bin/scons-unzip.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/scons-unzip.py b/bin/scons-unzip.py new file mode 100644 index 0000000..f772dd5 --- /dev/null +++ b/bin/scons-unzip.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# +# A quick script to unzip a .zip archive and put the files in a +# subdirectory that matches the basename of the .zip file. +# +# This is actually generic functionality, it's not SCons-specific, but +# I'm using this to make it more convenient to manage working on multiple +# changes on Windows, where I don't have access to my Aegis tools. +# + +import getopt +import os.path +import sys +import zipfile + +helpstr = """\ +Usage: scons-unzip.py [-o outdir] zipfile +Options: + -o DIR, --out DIR Change output directory name to DIR + -v, --verbose Print file names when extracting +""" + +opts, args = getopt.getopt(sys.argv[1:], + "o:v", + ['out=', 'verbose']) + +outdir = None +printname = lambda x: x + +for o, a in opts: + if o == '-o' or o == '--out': + outdir = a + elif o == '-v' or o == '--verbose': + def printname(x): + print x + +if len(args) != 1: + sys.stderr.write("scons-unzip.py: \n") + sys.exit(1) + +zf = zipfile.ZipFile(str(args[0]), 'r') + +if outdir is None: + outdir, _ = os.path.splitext(os.path.basename(args[0])) + +def outname(n, outdir=outdir): + l = [] + while 1: + n, tail = os.path.split(n) + if not n: + break + l.append(tail) + l.append(outdir) + l.reverse() + return apply(os.path.join, l) + +for name in zf.namelist(): + dest = outname(name) + dir = os.path.dirname(dest) + try: + os.makedirs(dir) + except: + pass + printname(dest) + # if the file exists, then delete it before writing + # to it so that we don't end up trying to write to a symlink: + if os.path.isfile(dest) or os.path.islink(dest): + os.unlink(dest) + if not os.path.isdir(dest): + open(dest, 'w').write(zf.read(name)) |