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.
16 Usage: scons-unzip.py [-o outdir] zipfile
18 -o DIR, --out DIR Change output directory name to DIR
19 -v, --verbose Print file names when extracting
22 opts
, args
= getopt
.getopt(sys
.argv
[1:],
27 printname
= lambda x
: x
30 if o
== '-o' or o
== '--out':
32 elif o
== '-v' or o
== '--verbose':
37 sys
.stderr
.write("scons-unzip.py: \n")
40 zf
= zipfile
.ZipFile(str(args
[0]), 'r')
43 outdir
, _
= os
.path
.splitext(os
.path
.basename(args
[0]))
45 def outname(n
, outdir
=outdir
):
48 n
, tail
= os
.path
.split(n
)
54 return os
.path
.join(*l
)
56 for name
in zf
.namelist():
58 dir = os
.path
.dirname(dest
)
64 # if the file exists, then delete it before writing
65 # to it so that we don't end up trying to write to a symlink:
66 if os
.path
.isfile(dest
) or os
.path
.islink(dest
):
68 if not os
.path
.isdir(dest
):
69 open(dest
, 'w').write(zf
.read(name
))
73 # indent-tabs-mode:nil
75 # vim: set expandtab tabstop=4 shiftwidth=4: