|
@@ -0,0 +1,32 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+
|
|
|
+import sys
|
|
|
+import zipfile
|
|
|
+import argparse
|
|
|
+
|
|
|
+parser = argparse.ArgumentParser(description="accept to and from encodings")
|
|
|
+parser.add_argument('-O', metavar='decode', default="shift-jis")
|
|
|
+parser.add_argument('-I', metavar='encode', default="cp437")
|
|
|
+args, files = parser.parse_known_args();
|
|
|
+
|
|
|
+def unzip(filename, encode, decode):
|
|
|
+ code = 0
|
|
|
+ with zipfile.ZipFile(filename) as myzip:
|
|
|
+ for info in myzip.infolist():
|
|
|
+ try:
|
|
|
+ info.filename = info.filename.encode(encode, 'strict').decode(decode, 'strict')
|
|
|
+ myzip.extract(info)
|
|
|
+ except Exception as e:
|
|
|
+ code = 1
|
|
|
+ print("failed to extract {0}: {1}".format(info.filename, e))
|
|
|
+ return code
|
|
|
+
|
|
|
+def main(files, encode, decode):
|
|
|
+ code = 0
|
|
|
+ for file in files:
|
|
|
+ if unzip(file, encode, decode) == 1:
|
|
|
+ code = 1
|
|
|
+ return code
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ sys.exit(main(files, args.I, args.O))
|