2 """Unzip with encoded filenames
4 Written by Oleg Broytman. Copyright (C) 2009-2016 PhiloSoft Design.
8 from getopt import getopt, GetoptError
9 from shutil import copyfileobj
10 from zipfile import ZipFile
11 from m_lib.defenc import default_encoding
14 sys.exit('Usage: %s file.zip' % sys.argv[0])
17 options, arguments = getopt(sys.argv[1:], '')
21 if len(arguments) != 1:
24 zf = ZipFile(arguments[0], 'r')
27 for zinfo in zf.infolist():
29 if isinstance(path, bytes):
30 path = path.decode('cp866')
31 recoded_path = path.encode(default_encoding)
34 if path.startswith('./'):
35 recoded_path = recoded_path[2:]
36 tgt = os.path.join(out, recoded_path)
38 tgtdir = os.path.dirname(tgt)
39 if not os.path.exists(tgtdir):
42 if not tgt.endswith('/'):
43 infile = zf.open(zinfo.filename)
45 copyfileobj(infile, fp)
48 dt = time.mktime(zinfo.date_time + (0, 0, -1))
49 os.utime(tgt, (dt, dt))