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("/"):
17 target_file
= file(fullpath
, "wb")
19 target_file
.write(data
)
23 print "Usage: unzip zipfile [target_dir]"
25 if __name__
== "__main__":
26 if len(sys
.argv
) == 1:
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]))