#! /usr/bin/env python import sys import os from optparse import OptionParser def validate_cipres_root(cr): if not os.path.exists(cr): return False, "CIPRES_ROOT itself" bin_dir = os.path.join(cr, "bin") if not os.path.exists(bin_dir): return False, os.path.join("CIPRES_ROOT", "bin") return True, None def install_cipres_service(cipres_root, path_to_archive): install_script = os.path.join(cr, "bin", "install_service.py") args = [install_script, "-Darchive.path=%s" % path_to_archive, "-Dreinstall.service", ] os.execv(install_script, args) def uninstall_cipres_service(cipres_root, service_name): install_script = os.path.join(cr, "bin", "install_service.py") args = [install_script, "-Dservice.name=%s" % service_name, "-Duninstall.service", ] print args os.execv(install_script, args) if __name__ == "__main__": commands = ["install", "uninstall"] cmds_str = '"%s"' % '", "'.join(commands) usage = """ python %%prog command [options] where the valid commands are: %s""" % cmds_str parser = OptionParser(usage=usage) parser.add_option("", "--prefix", dest="prefix", help="specifies the path to the CIPRES_ROOT", metavar="DIR") (options, args) = parser.parse_args() if len(args) != 1: sys.exit('Expecting one of the commands (%s) as an argument' % cmds_str) cmd = args[0].lower() if cmd not in commands: msg = 'The command "%s" is unrecognized. Expecting one of the commands '\ '(%s) as an argument' % (cmd, cmds_str) sys.exit(msg) cr = options.prefix if cr is None: cr = os.environ.get("CIPRES_ROOT") if cr is None: sys.exit("The CIPRES_ROOT environmental variable must be set, or you must "\ "use a --prefix= argument where is the path to your "\ "CIPRES_ROOT directory.") valid, missing = validate_cipres_root(cr) if not valid: sys.exit("Make sure that you CIPRES_ROOT (or --prefix argument) is correct."\ "\nThe expected file %s is missing." % missing) service_path = os.path.dirname(os.path.abspath(sys.argv[0])) service_name = os.path.basename(service_path) if cmd == "install": install_cipres_service(cr, service_path) elif cmd == "uninstall": uninstall_cipres_service(cr, service_name)