view startXena.py @ 8:c1388ebe8662

Fixed an XML bug in the tool wrapper
author melissacline
date Tue, 23 Sep 2014 20:39:18 -0700
parents 733fa93086c5
children ed83452c5f8e
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)
   sys.exit(error_level)

    
def run(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" % (return_code, stderr))



def main():

   jarPath = os.getenv("XENA_JAR_PATH", "~")
   xenaJarPath = os.path.join(jarPath, "xena.jar")
   xenaBaseDir = os.getenv("XENA_BASE_DIR", "~")
   xenaPort = os.getenv("XENA_PORT", 1236)
   cmdline = "java -jar %s -r %s/files -d %s/db -t %s/tmp -p %d -H 0.0.0.0" % (xenaJarPath, xenaBaseDir, 
                                                                               xenaBaseDir, xenaBaseDir,
                                                                               xenaPort)
   for ii in range(1,len(sys.argv)):
       cmdline = "%s %s" % (cmdline, sys.argv[ii])
   cmd += " &"
   print "Xena VM invoked with command", cmdline
   subprocess.call(cmd, shell=True)

if __name__ == '__main__':
    main( )