Skip to content

Commit

Permalink
Add compress command + oratiomodulezipper module
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-daniels committed Jun 25, 2015
1 parent 654bbe7 commit 76b5866
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 19 additions & 1 deletion oratio-cli
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import requests # requires the requests library to be installed
import appdirs # requires the appdirs library to be installed

from oratioignoreparser import OratioIgnoreParser

import oratiomodulezipper

def main():
if len(sys.argv) < 2:
Expand Down Expand Up @@ -41,6 +41,8 @@ def exec_cmd(cmd, args):
auth()
elif cmd == "rmsession":
rmsession()
elif cmd == "compress":
compress()
elif cmd == "login":
login()
elif cmd == "logout":
Expand Down Expand Up @@ -132,6 +134,22 @@ def rmsession():
print("No OAuth session found.")


def compress():
if os.path.isfile("oratiomodule.tar.gz"):
yn = input("oratiomodule.tar.gz already exists. Overwrite? (y/n) ").lower()
if yn == "n":
print("Compression cancelled.")
return
elif yn != "n" and yn != "y":
print("Invalid input. Stopping.")
return
parser = OratioIgnoreParser()
if os.path.isfile(".oratio-ignore"):
parser.load(".oratio-ignore")
oratiomodulezipper.compress_module(parser.list_files(".")[0], "oratiomodule.tar.gz")
print("Compressed to oratiomodule.tar.gz")


# Obsolete commands can be found below this line.
# They will get removed soon, when the other,
# non-obsolete functions have been implemented.
Expand Down
7 changes: 7 additions & 0 deletions oratiomodulezipper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tarfile


def compress_module(file_list, output_file):
with tarfile.open(output_file, "w:gz") as tf:
for file_name in file_list:
tf.add(file_name)

0 comments on commit 76b5866

Please sign in to comment.