Documentation fixes. OC has been replaced by TH in the public headers.
[xiph/unicode.git] / positron / test / unzip.py
blobbfa2882e75246727bfa78c834f6bb86623fb07d6
1 import sys
2 import os
3 from os import path
4 import zipfile
6 def unzip(source_file, target_dir):
7 """Unzips source_file and writes the contents to target_dir"""
9 zip = zipfile.ZipFile(source_file)
11 for item in zip.namelist():
12 fullpath = path.join(target_dir, item)
14 if fullpath.endswith("/"):
15 os.mkdir(fullpath)
16 else:
17 target_file = file(fullpath, "wb")
18 data = zip.read(item)
19 target_file.write(data)
20 target_file.close()
22 def unzip_usage():
23 print "Usage: unzip zipfile [target_dir]"
25 if __name__ == "__main__":
26 if len(sys.argv) == 1:
27 unzip_usage()
28 elif len(sys.argv) == 2:
29 unzip(sys.argv[1], path.abspath("."))
30 elif len(sys.argv) == 3:
31 unzip(sys.argv[1], path.abspath(sys.argv[2]))
32 else:
33 unzip_usage()