view startXena.py @ 1:00ea1bdc1aed

Updated the repo in the test toolshed - this should work now
author melissacline
date Thu, 04 Sep 2014 15:03:32 -0700
parents 0676a227dbc6
children 82755b0ee5a5
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.
    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", "~")
   #xenaBaseDir = os.getenv("__tool_data_path__", "~") + "/shared/xena"
   #xenaBaseDir = args.toolDataPath + "/shared/xena"
   cmdline = "java -jar %s -r %s/files -d %s/xena/db -t %s/tmp" % (xenaJarPath, xenaBaseDir, xenaBaseDir, xenaBaseDir)
   for ii in range(1,len(sys.argv)):
       cmdline = "%s %s" % (cmdline, sys.argv[ii])
   fp = open("/Users/melissacline/tmp/xena.out", "w")
   fp.write("jar path (not paht) %s\n" % (jarPath))
   fp.write("xena base dir %s\n" % (xenaBaseDir))
   fp.write(cmdline)
   run(cmdline)
   fp.close()

if __name__ == '__main__':
    main( )