0
|
1 from os.path import dirname, join, abspath
|
|
2 import sys
|
|
3 from optparse import OptionParser
|
|
4 from ConfigParser import SafeConfigParser
|
|
5 import subprocess
|
|
6
|
|
7 DEBUG = False
|
|
8
|
|
9
|
|
10 def main():
|
|
11 (options, args) = _parse_args()
|
|
12 for executable, config_path in zip(options.executables, options.configs):
|
|
13 command_handler = COMMAND_HANDLERS.get(executable, _run_mzmatch)
|
|
14 command_handler(executable, config_path)
|
|
15
|
|
16
|
|
17 def _run_shell(executable, config_path):
|
|
18 command = open(config_path, "r").read().strip()
|
|
19 if DEBUG:
|
|
20 print "Running shell command %s" % command
|
|
21 _exec(command)
|
|
22
|
|
23
|
|
24 def _run_mzmatch(executable, config_path):
|
|
25 command_prefix = "java -cp %s" % _jar_path()
|
|
26 java_class = "mzmatch.ipeak.%s" % executable
|
|
27 args = open(config_path, "r").read().strip()
|
|
28 _exec("%s %s %s" % (command_prefix, java_class, args))
|
|
29
|
|
30
|
|
31 def _jar_path():
|
|
32 py_path = __file__
|
|
33 jar_path = join(dirname(py_path), "mzmatch_2.0.jar")
|
|
34 return jar_path
|
|
35
|
|
36 COMMAND_HANDLERS = {
|
|
37 "__SHELL__": _run_shell,
|
|
38 }
|
|
39
|
|
40
|
|
41 def _exec(command):
|
|
42 proc = subprocess.Popen(args=command, shell=True)
|
|
43 return_code = proc.wait()
|
|
44 if return_code != 0:
|
|
45 print "Error executing command [%s], return code is %d" % (command, return_code)
|
|
46 sys.exit(return_code)
|
|
47
|
|
48
|
|
49 def _parse_args():
|
|
50 parser = OptionParser()
|
|
51 parser.add_option("-e", "--executable", dest="executables", default=[], action="append")
|
|
52 parser.add_option("-c", "--config", dest="configs", default=[], action="append")
|
|
53 return parser.parse_args()
|
|
54
|
|
55
|
|
56 def _load_options(config_path):
|
|
57 config_parser = SafeConfigParser()
|
|
58 config_parser.optionxform = str
|
|
59 config_parser.read(config_path)
|
|
60 return config_parser
|
|
61
|
|
62 if __name__ == "__main__":
|
|
63 main()
|