diff options
author | kennyballou <kballou@onyx.boisestate.edu> | 2012-10-05 15:56:29 -0600 |
---|---|---|
committer | kballou <kballou@onyx.boisestate.edu> | 2012-10-05 15:56:29 -0600 |
commit | e515b4dc82e82cab67cf738a23b1860d9fb05afe (patch) | |
tree | 2e8b6df9d80e09fd80e6bf99ee8839a84db86ea7 /xnt/tasks.py | |
download | xnt-e515b4dc82e82cab67cf738a23b1860d9fb05afe.tar.gz xnt-e515b4dc82e82cab67cf738a23b1860d9fb05afe.tar.xz |
Initial commit
Diffstat (limited to 'xnt/tasks.py')
-rw-r--r-- | xnt/tasks.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/xnt/tasks.py b/xnt/tasks.py new file mode 100644 index 0000000..41577b4 --- /dev/null +++ b/xnt/tasks.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +import os +import sys +import subprocess +import time +import shutil +import zipfile +import contextlib + +#File associated tasks +def cp(src,dst): + if os.path.isdir(src): + shutil.copytree(src,dst) + else: + shutil.copy2(src,dst) + +def mv(src,dst): + shutil.move(src,dst) + +def mkdir(dir,mode=0777): + try: + os.mkdir(dir,mode) + except IOError: + pass + +def rm(path): + if os.path.isdir(path): + shutil.rmtree(path) + else: + os.remove(path) + +def zip(dir,zipfilename): + assert os.path.isdir(dir) and zipfilename + with contextlib.closing(zipfile.ZipFile( + zipfilename, + "w", + zipfile.ZIP_DEFLATED)) as z: + for root, dirs, files in os.walk(dir): + for fn in files: + absfn = os.path.join(root, fn) + zfn = absfn[len(dir)+len(os.sep):] + z.write(absfn, zfn) + +def make(path="",target=""): + makeCmd = ["ant", target] + if path and os.path.exists(path): + oldPath = os.getcwd() + os.chdir(os.path.abspath(path)) + result = subprocess.call(makeCmd) + os.chdir(os.path.abspath(oldPath)) + return result + +#Misc Tasks +def echo(message="",tofile=""): + if tofile: + with open(tofile, "w") as f: + subprocess.call(["echo", message], stdout=f) + else: + print(message) + +#HG Tasks +def hgclone(url): + subprocess.call(["hg", "clone", url]) + +def hgfetch(path): + oldPath = os.getcwd() + os.chdir(path) + subprocess.call(["hg", "pull", "-u"]) + os.chdir(oldPath) |