3 # A quick script to unzip a .zip archive and put the files in a
4 # subdirectory that matches the basename of the .zip file.
6 # This is actually generic functionality, it's not SCons-specific, but
7 # I'm using this to make it more convenient to manage working on multiple
8 # changes on Windows, where I don't have access to my Aegis tools.
17 Usage: scons-unzip.py [-o outdir] zipfile
19 -o DIR, --out DIR Change output directory name to DIR
20 -v, --verbose Print file names when extracting
23 opts, args = getopt.getopt(sys.argv[1:],
28 printname = lambda x: x
31 if o == '-o' or o == '--out':
33 elif o == '-v' or o == '--verbose':
38 sys.stderr.write("scons-unzip.py: \n")
41 zf = zipfile.ZipFile(str(args[0]), 'r')
44 outdir, _ = os.path.splitext(os.path.basename(args[0]))
46 def outname(n, outdir=outdir):
49 n, tail = os.path.split(n)
55 return os.path.join(*l)
57 for name in zf.namelist():
59 dir = os.path.dirname(dest)
65 # if the file exists, then delete it before writing
66 # to it so that we don't end up trying to write to a symlink:
67 if os.path.isfile(dest) or os.path.islink(dest):
69 if not os.path.isdir(dest):
70 open(dest, 'w').write(zf.read(name))
74 # indent-tabs-mode:nil
76 # vim: set expandtab tabstop=4 shiftwidth=4: