Mercurial > repos > melissacline > start_xena
annotate startXena.py @ 3:47bb7e16dd73
Tweaked the install dependencies script
| author | melissacline | 
|---|---|
| date | Thu, 04 Sep 2014 15:29:38 -0700 | 
| parents | 00ea1bdc1aed | 
| children | 82755b0ee5a5 | 
| rev | line source | 
|---|---|
| 0 | 1 #!/usr/bin/env python | 
| 2 | |
| 3 import argparse | |
| 4 import os | |
| 5 import subprocess | |
| 6 import sys | |
| 7 | |
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 8 def stop_err(msg, error_level=1): | 
| 0 | 9 """Print error message to stdout and quit with given error level.""" | 
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 10 sys.stderr.write("%s\n" % msg) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 11 #fp.write("%s\n" % msg) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 12 #fp.write("error code %d\n" % error_level) | 
| 0 | 13 sys.exit(error_level) | 
| 14 | |
| 15 | |
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 16 def run(cmd): | 
| 0 | 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: | |
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 29 stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, err, stdout, stderr)) | 
| 0 | 30 else: | 
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 31 stop_err("Return code %i from command:\n%s\n%s" % (return_code, err, stderr)) | 
| 0 | 32 | 
| 33 | |
| 34 | |
| 35 def main(): | |
| 1 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 36 #parser = argparse.ArgumentParser() | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 37 #parser.add_argument("-H", "--host", type=str) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 38 #parser.add_argument("-p", "--port", type=str) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 39 #args = parser.parse_args() | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 40 | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 41 jarPath = os.getenv("JAVA_JAR_PATH", "~") | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 42 xenaJarPath = os.path.join(jarPath, "xena.jar") | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 43 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 44 #xenaBaseDir = os.getenv("__tool_data_path__", "~") + "/shared/xena" | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 45 #xenaBaseDir = args.toolDataPath + "/shared/xena" | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 46 cmdline = "java -jar %s -r %s/files -d %s/xena/db -t %s/tmp" % (xenaJarPath, xenaBaseDir, xenaBaseDir, xenaBaseDir) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 47 for ii in range(1,len(sys.argv)): | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 48 cmdline = "%s %s" % (cmdline, sys.argv[ii]) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 49 fp = open("/Users/melissacline/tmp/xena.out", "w") | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 50 fp.write("jar path (not paht) %s\n" % (jarPath)) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 51 fp.write("xena base dir %s\n" % (xenaBaseDir)) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 52 fp.write(cmdline) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 53 run(cmdline) | 
| 
00ea1bdc1aed
Updated the repo in the test toolshed - this should work now
 melissacline parents: 
0diff
changeset | 54 fp.close() | 
| 0 | 55 | 
| 56 if __name__ == '__main__': | |
| 57 main( ) | |
| 58 | 
