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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
1 #!/usr/bin/env python
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
2
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
3 import argparse
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
4 import os
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
5 import subprocess
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
6 import sys
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
7
1
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
8 def stop_err(msg, error_level=1):
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
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: 0
diff changeset
10 sys.stderr.write("%s\n" % msg)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
11 #fp.write("%s\n" % msg)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
12 #fp.write("error code %d\n" % error_level)
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
13 sys.exit(error_level)
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
14
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
15
1
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
16 def run(cmd):
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
17 #Avoid using shell=True when we call subprocess to ensure if the Python
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
18 #script is killed, so too is the child process.
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
19 try:
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
20 child = subprocess.Popen(cmd, stdout=subprocess.PIPE,
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
21 stderr=subprocess.PIPE, shell=True)
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
22 except Exception, err:
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
23 stop_err("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
24 #Use .communicate as can get deadlocks with .wait(),
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
25 stdout, stderr = child.communicate()
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
26 return_code = child.returncode
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
27 if return_code:
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
28 if stderr and stdout:
1
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
29 stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, err, stdout, stderr))
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
30 else:
1
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
31 stop_err("Return code %i from command:\n%s\n%s" % (return_code, err, stderr))
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
32
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
33
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
34
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
35 def main():
1
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
36 #parser = argparse.ArgumentParser()
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
37 #parser.add_argument("-H", "--host", type=str)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
38 #parser.add_argument("-p", "--port", type=str)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
39 #args = parser.parse_args()
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
40
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
41 jarPath = os.getenv("JAVA_JAR_PATH", "~")
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
42 xenaJarPath = os.path.join(jarPath, "xena.jar")
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
43 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~")
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
44 #xenaBaseDir = os.getenv("__tool_data_path__", "~") + "/shared/xena"
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
45 #xenaBaseDir = args.toolDataPath + "/shared/xena"
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff 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: 0
diff changeset
47 for ii in range(1,len(sys.argv)):
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
48 cmdline = "%s %s" % (cmdline, sys.argv[ii])
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
49 fp = open("/Users/melissacline/tmp/xena.out", "w")
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff 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: 0
diff changeset
51 fp.write("xena base dir %s\n" % (xenaBaseDir))
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
52 fp.write(cmdline)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
53 run(cmdline)
00ea1bdc1aed Updated the repo in the test toolshed - this should work now
melissacline
parents: 0
diff changeset
54 fp.close()
0
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
55
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
56 if __name__ == '__main__':
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
57 main( )
0676a227dbc6 Uploaded
melissacline
parents:
diff changeset
58