diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2019-07-24 09:57:09 +0200 |
commit | c7665433b2004d2b404d6fb9d6fd064998486f63 (patch) | |
tree | 8525ef6d24f7c6ceb238945ebb2cc997c7afc905 /site_scons/zip_utils.py | |
parent | e48d2727885efda8369c7edbc2e3929a59532adc (diff) | |
parent | 6e228c305122f0564eda1e67d56651f8386d24d7 (diff) |
Merge branch 'release/debian/3.1.0+repack-1'debian/3.1.0+repack-1
Diffstat (limited to 'site_scons/zip_utils.py')
-rw-r--r-- | site_scons/zip_utils.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/site_scons/zip_utils.py b/site_scons/zip_utils.py new file mode 100644 index 0000000..3d5821e --- /dev/null +++ b/site_scons/zip_utils.py @@ -0,0 +1,54 @@ +import os.path + + +zcat = 'gzip -d -c' + +# +# Figure out if we can handle .zip files. +# +zipit = None +unzipit = None +try: + import zipfile + + def zipit(env, target, source): + print("Zipping %s:" % str(target[0])) + def visit(arg, dirname, filenames): + for filename in filenames: + path = os.path.join(dirname, filename) + if os.path.isfile(path): + arg.write(path) + # default ZipFile compression is ZIP_STORED + zf = zipfile.ZipFile(str(target[0]), 'w', compression=zipfile.ZIP_DEFLATED) + olddir = os.getcwd() + os.chdir(env['CD']) + try: + for dirname, dirnames, filenames in os.walk(env['PSV']): + visit(zf, dirname, filenames) + finally: + os.chdir(olddir) + zf.close() + + def unzipit(env, target, source): + print("Unzipping %s:" % str(source[0])) + zf = zipfile.ZipFile(str(source[0]), 'r') + for name in zf.namelist(): + dest = os.path.join(env['UNPACK_ZIP_DIR'], name) + dir = os.path.dirname(dest) + try: + os.makedirs(dir) + except: + pass + print(dest,name) + # 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): + with open(dest, 'wb') as fp: + fp.write(zf.read(name)) + +except ImportError: + if unzip and zip: + zipit = "cd $CD && $ZIP $ZIPFLAGS $( ${TARGET.abspath} $) $PSV" + unzipit = "$UNZIP $UNZIPFLAGS $SOURCES" |