uz 968 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. import sys
  3. import zipfile
  4. import argparse
  5. parser = argparse.ArgumentParser(description="accept to and from encodings")
  6. parser.add_argument('-O', metavar='decode', default="shift-jis")
  7. parser.add_argument('-I', metavar='encode', default="cp437")
  8. args, files = parser.parse_known_args();
  9. def unzip(filename, encode, decode):
  10. code = 0
  11. with zipfile.ZipFile(filename) as myzip:
  12. for info in myzip.infolist():
  13. try:
  14. info.filename = info.filename.encode(encode, 'strict').decode(decode, 'strict')
  15. myzip.extract(info)
  16. except Exception as e:
  17. code = 1
  18. print("failed to extract {0}: {1}".format(info.filename, e))
  19. return code
  20. def main(files, encode, decode):
  21. code = 0
  22. for file in files:
  23. if unzip(file, encode, decode) == 1:
  24. code = 1
  25. return code
  26. if __name__ == '__main__':
  27. sys.exit(main(files, args.I, args.O))