-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMCP
More file actions
executable file
·61 lines (51 loc) · 2.31 KB
/
MCP
File metadata and controls
executable file
·61 lines (51 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/soft/packages/python/2.6/bin/python
import argparse
import os
import json
import sys
import re
import syslog
import getpass
# Getting path to MCP
MCP_path = os.path.realpath(__file__)
matchObj = re.match(r'(^.*\/)', MCP_path)
MCP_dir = matchObj.group(0)
user = getpass.getuser()
syslog.openlog("[MCP] [INFO] [" + user + "] [" + MCP_path + "] ", syslog.LOG_PID, syslog.LOG_LOCAL1)
# Adding modules directory to path
path = list(sys.path)
sys.path.insert(0, MCP_dir+"mcp_modules/")
if 'MCP_CONF' not in os.environ.keys() or os.environ['MCP_CONF'] == '':
sys.stderr.write("ERROR: please set MCP_CONF environment variable to the location of the MCP configuration file.\n")
sys.exit()
json_conf_file_path = os.environ['MCP_CONF']
json_conf_file = open(json_conf_file_path)
json_conf = json.load(json_conf_file)
def main():
parser = argparse.ArgumentParser(description='MG-RAST Control Program (MCP)')
parser.add_argument('subsystem', metavar='subsystem',
help="An MG-RAST subsystem. The current list of subsystems includes: '" +
"', '".join(json_conf["global"]["subsystems"])+"'")
parser.add_argument('params', metavar='params', nargs=argparse.REMAINDER,
help='Additional arguments should specify a function followed by function parameters.')
args = parser.parse_args()
subsystem = args.subsystem
params = args.params
if subsystem in json_conf["global"]["subsystems"]:
# Retrieve the appropriate "subsystem" python module and class (module and class names should be identical)
module = __import__(subsystem)
myclass = getattr(module, subsystem)
# Create the python class instance dynamically
mysubsystem = myclass(MCP_dir, json_conf_file_path)
function, function_params = mysubsystem.parse_subsystem_params(params)
myfunction = getattr(mysubsystem, function)
if(len(params) == 1):
msg = "Calling the subsystem: " + subsystem + " with the function: " + function
else:
msg = "Calling the subsystem: " + subsystem + " with the function: " + function + " and the parameters: " + ", ".join(params[1:])
syslog.syslog(syslog.LOG_INFO, msg)
myfunction(function_params)
syslog.closelog()
return 0
if __name__ == "__main__":
sys.exit( main() )