Skip to content

Commit

Permalink
inout: zip support added
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbalaci committed May 11, 2017
1 parent d902ec6 commit 4914c8d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions inout.py
Expand Up @@ -5,8 +5,13 @@
1) compress a directory and store the archive in another folder, and
2) uncompress an archive to a given folder
TODO:
* add zip support (currently only tar and tgz are supported)
Supported archiving / compression methods:
* tar
* tgz
* zip
Contributors:
* Gábor Szőcs <https://github.com/szocs08>, zip support
"""

import os
Expand Down Expand Up @@ -85,7 +90,7 @@ def compress():
die("# error: couldn't create the directory")
print("# directory created")
#
accepted = ["tar", "tgz"]
accepted = ["tar", "tgz", "zip"]
while True:
ext = my_input("> what compression to use ({})? ".format(", ".join(accepted)))
if ext not in accepted:
Expand All @@ -104,6 +109,15 @@ def compress():
dname=dname)
print("# " + cmd)
os.system(cmd)
zip_options = "-r"
if ext == "zip":
fname = str(dname) + ".zip"
cmd = "zip {options} {to_dir}/{fname} {dname}".format(options=zip_options,
to_dir=str(to_dir),
fname=fname,
dname=dname)
print("# " + cmd)
os.system(cmd)


def uncompress():
Expand Down Expand Up @@ -149,6 +163,12 @@ def uncompress():
fname=fname)
print("# " + cmd)
os.system(cmd)
if ftype == ZIP:
cmd = "unzip {fname} -d {to_dir}".format(options=tar_options,
to_dir=str(to_dir),
fname=fname)
print("# " + cmd)
os.system(cmd)


def main():
Expand Down

0 comments on commit 4914c8d

Please sign in to comment.