1 #! /usr/bin/env python3
2 """Zip (zip -r9) with encoded filenames
4 Written by Oleg Broytman. Copyright (C) 2009-2023 PhiloSoft Design.
8 from getopt import getopt, GetoptError
9 from zipfile import ZipFile, ZIP_DEFLATED
10 from m_lib.defenc import default_encoding
13 sys.exit('Usage: %s file.zip file1 dir2...' % sys.argv[0])
16 options, arguments = getopt(sys.argv[1:], '')
20 if len(arguments) < 2:
23 def addToZip(zf, path):
24 if os.path.isfile(path):
26 if isinstance(path, bytes):
27 recoded_path = path.decode(default_encoding).encode('cp866')
30 zf.write(path, recoded_path, ZIP_DEFLATED)
31 elif os.path.isdir(path):
32 for nm in os.listdir(path):
33 addToZip(zf, os.path.join(path, nm))
37 if os.path.splitext(zname)[1] not in ('.zip', '.ZIP'):
40 zf = ZipFile(zname, 'w', allowZip64=True)
42 for path in arguments[1:]: