Mercurial > repos > melissacline > start_xena
view startXena.py @ 5:16c3fad9bac5
Fixed inconsistencies in the naming of the xena base dir
author | melissacline |
---|---|
date | Mon, 08 Sep 2014 13:08:04 -0700 |
parents | 82755b0ee5a5 |
children | 733fa93086c5 |
line wrap: on
line source
#!/usr/bin/env python import argparse import os import subprocess import sys def stop_err(msg, error_level=1): """Print error message to stdout and quit with given error level.""" sys.stderr.write("%s\n" % msg) #fp.write("%s\n" % msg) #fp.write("error code %d\n" % error_level) sys.exit(error_level) def run(cmd): #Avoid using shell=True when we call subprocess to ensure if the Python #script is killed, so too is the child process. print cmd try: child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except Exception, err: stop_err("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) #Use .communicate as can get deadlocks with .wait(), stdout, stderr = child.communicate() return_code = child.returncode if return_code: if stderr and stdout: stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, err, stdout, stderr)) else: stop_err("Return code %i from command:\n%s\n%s" % (return_code, err, stderr)) def main(): #parser = argparse.ArgumentParser() #parser.add_argument("-H", "--host", type=str) #parser.add_argument("-p", "--port", type=str) #args = parser.parse_args() jarPath = os.getenv("JAVA_JAR_PATH", "~") xenaJarPath = os.path.join(jarPath, "xena.jar") xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") cmdline = "java -jar %s -r %s/files -d %s/db -t %s/tmp >& /inside/home/cline/tmp/xena.errout" % (xenaJarPath, xenaBaseDir, xenaBaseDir, xenaBaseDir) for ii in range(1,len(sys.argv)): cmdline = "%s %s" % (cmdline, sys.argv[ii]) #fp = open("/inside/home/cline/tmp/xena.out", "w") #fp.write("cmdline %s\n" % cmdline) #fp.close() run(cmdline) if __name__ == '__main__': main( )