X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=bin%2Fzip.py;h=e99c9a8283ed6829e824388994eee5a043a51652;hb=HEAD;hp=eebbaeb736a04c2421c9d47b5111cab424ce7948;hpb=f46bd4d41cc7f243bc8a321effee5200aa69e709;p=dotfiles.git diff --git a/bin/zip.py b/bin/zip.py index eebbaeb..bf55a08 100755 --- a/bin/zip.py +++ b/bin/zip.py @@ -1,12 +1,12 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Zip (zip -r9) with encoded filenames - Written by Oleg Broytman. Copyright (C) 2009, 2010 PhiloSoft Design. + Written by Oleg Broytman. Copyright (C) 2009-2023 PhiloSoft Design. """ import sys, os from getopt import getopt, GetoptError -from zipfile import ZipFile, ZIP_DEFLATED +from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED from m_lib.defenc import default_encoding def usage(): @@ -21,10 +21,21 @@ if len(arguments) < 2: usage() def addToZip(zf, path): - if os.path.isfile(path): - print path - recoded_path = path.decode(default_encoding).encode('cp866') - zf.write(path, recoded_path, ZIP_DEFLATED) + if os.path.isfile(path) or os.path.islink(path): + print(path) + if isinstance(path, bytes): + recoded_path = path.decode(default_encoding).encode('cp866') + else: + recoded_path = path + if os.path.islink(path): + # http://www.mail-archive.com/python-list@python.org/msg34223.html + zipInfo = ZipInfo(recoded_path) + zipInfo.create_system = 3 + # say, symlink attr magic... + zipInfo.external_attr = 0xA1ED0000 + zf.writestr(zipInfo, os.readlink(path)) + else: + zf.write(path, recoded_path, ZIP_DEFLATED) elif os.path.isdir(path): for nm in os.listdir(path): addToZip(zf, os.path.join(path, nm))