Mercurial > repos > melissacline > start_xena
comparison startXena.py @ 0:0676a227dbc6
Uploaded
author | melissacline |
---|---|
date | Wed, 03 Sep 2014 15:37:49 -0400 |
parents | |
children | 00ea1bdc1aed |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0676a227dbc6 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import argparse | |
4 import os | |
5 import subprocess | |
6 import sys | |
7 | |
8 def stop_err(msg, fp, error_level=1): | |
9 """Print error message to stdout and quit with given error level.""" | |
10 #sys.stderr.write("%s\n" % msg) | |
11 fp.write("%s\n" % msg) | |
12 fp.write("error code %d\n" % error_level) | |
13 sys.exit(error_level) | |
14 | |
15 | |
16 def run(cmd, fp): | |
17 #Avoid using shell=True when we call subprocess to ensure if the Python | |
18 #script is killed, so too is the child process. | |
19 try: | |
20 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
21 stderr=subprocess.PIPE, shell=True) | |
22 except Exception, err: | |
23 stop_err("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) | |
24 #Use .communicate as can get deadlocks with .wait(), | |
25 stdout, stderr = child.communicate() | |
26 return_code = child.returncode | |
27 if return_code: | |
28 if stderr and stdout: | |
29 stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, err, stdout, stderr), fp) | |
30 else: | |
31 stop_err("Return code %i from command:\n%s\n%s" % (return_code, err, stderr), fp) | |
32 | |
33 | |
34 | |
35 def main(): | |
36 jarPath = os.getenv("JAVA_JAR_PATH", "~") | |
37 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") | |
38 xenaJarPath = os.path.join(jarPath, "xena.jar") | |
39 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") | |
40 cmdline = "java -jar %s -r %s/xena/files -d %s/xena/db -t %s/xena/tmp" % (xenaJarPath, xenaBaseDir, xenaBaseDir, xenaBaseDir) | |
41 for ii in range(1,len(sys.argv)): | |
42 cmdline = "%s %s" % (cmdline, sys.argv[ii]) | |
43 print "executing", cmdline | |
44 fp = open("/inside/home/cline/tmp/xena.out", "w") | |
45 fp.write("jar path (not paht) %s\n" % (jarPath)) | |
46 fp.write("xena base dir %s\n" % (xenaBaseDir)) | |
47 fp.write(cmdline) | |
48 run(cmdline, fp) | |
49 fp.close() | |
50 | |
51 if __name__ == '__main__': | |
52 main( ) | |
53 |