Last active
December 15, 2015 06:49
-
-
Save hyounggyu/5219203 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys, getopt, zipfile, shutil, os | |
| import os.path as osp | |
| f = "cp949" | |
| t = "utf-8" | |
| def usage(): | |
| print sys.argv[0] + " -f shift-jis -t utf-8 <filename>" | |
| def main(): | |
| global f, t | |
| try: | |
| opts, args = getopt.getopt(sys.argv[1:], "f:t:") | |
| except getopt.GetOptError, err: | |
| print str(err) | |
| usage() | |
| sys.exit(2) | |
| for o, a in opts: | |
| if o == "-f": | |
| f = a | |
| elif o == "-t": | |
| t = a | |
| else: | |
| assert False, "unhandled option" | |
| if (len(args) != 1): | |
| usage() | |
| sys.exit(2) | |
| zfname = args[0] | |
| zf = zipfile.ZipFile(zfname) | |
| for info in zf.infolist(): | |
| fname_t = info.orig_filename.decode(f,"ignore") | |
| segments = fname_t.split("/") | |
| if len(segments) > 1: | |
| try: | |
| os.makedirs("/".join(segments[:-1])) | |
| except OSError: | |
| pass | |
| print fname_t | |
| open(fname_t, "w").write(zf.open(info).read()) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment