Commit 9ebe831e authored by Jerome Mariette's avatar Jerome Mariette
Browse files

code review: code factorisation

parent 98089fa0
......@@ -57,14 +57,6 @@ class JflowArgumentParser (argparse.ArgumentParser):
return new_arg_strings
def parse_parameters_rules(wf_instance, user_params):
# Check rules:
try:
wf_instance.check_parameters_rules(user_params)
except Exception as e:
sub_parser.error(e)
if __name__ == '__main__':
# Create a workflow manager to get access to our workflows
......@@ -153,9 +145,12 @@ if __name__ == '__main__':
parser.exit(0, "")
if args["cmd_object"] in wf_classes:
workflow = wfmanager.get_workflow_by_class(args["cmd_object"])
parse_parameters_rules(workflow, args)
wfmanager.run_workflow(args["cmd_object"], args)
try:
workflow = wfmanager.get_workflow_by_class(args["cmd_object"])
workflow.check_parameters_rules(args)
wfmanager.run_workflow(args["cmd_object"], args)
except Exception as e:
sub_parser.error(e)
elif args["cmd_object"] == "rerun":
wfmanager.rerun_workflow(args["workflow_id"])
elif args["cmd_object"] == "reset":
......
......@@ -311,45 +311,8 @@ class JFlowServer (object):
@jsonify
def run_workflow(self, **kwargs):
try:
kwargs_modified = {}
# handle MultiParameterList
multi_sub_params = {}
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
if len(parts) == 3:
if not parts[0] in kwargs_modified:
kwargs_modified[parts[0]] = []
multi_sub_params[parts[0]] = {}
if parts[2] in multi_sub_params[parts[0]]:
multi_sub_params[parts[0]][parts[2]].append((parts[1], kwargs[key]))
else:
multi_sub_params[parts[0]][parts[2]] = [(parts[1], kwargs[key])]
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
# split append values
new_values = kwargs[key].split(JFlowServer.APPEND_PARAM_SPLITER)
if len(new_values) == 1:
new_values = new_values[0]
# if this is a classic Parameter
if len(parts) == 1:
kwargs_modified[key] = new_values
# if this is a MultiParameter
elif len(parts) == 2:
if parts[0] in kwargs_modified:
kwargs_modified[parts[0]].append((parts[1], new_values))
else:
kwargs_modified[parts[0]] = [(parts[1], new_values)]
# handle MultiParameterList
for param in multi_sub_params:
kwargs_modified[param] = []
for sub_param in multi_sub_params[param]:
kwargs_modified[param].append(multi_sub_params[param][sub_param])
kwargs_modified = self.__update_kwargs(kwargs)
workflow = self.wfmanager.run_workflow(kwargs_modified["workflow_class"], kwargs_modified)
return { "status" : 0, "content" : self.jsonify_workflow_status(workflow, True) }
except Exception as err:
return { "status" : 1, "content" : str(err) }
......@@ -357,45 +320,8 @@ class JFlowServer (object):
@cherrypy.expose
@jsonify
def validate_workflow(self, **kwargs):
kwargs_modified = {}
# handle MultiParameterList
multi_sub_params = {}
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
if len(parts) == 3:
if not parts[0] in kwargs_modified:
kwargs_modified[parts[0]] = []
multi_sub_params[parts[0]] = {}
if parts[2] in multi_sub_params[parts[0]]:
multi_sub_params[parts[0]][parts[2]].append((parts[1], kwargs[key]))
else:
multi_sub_params[parts[0]][parts[2]] = [(parts[1], kwargs[key])]
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
# split append values
new_values = kwargs[key].split(JFlowServer.APPEND_PARAM_SPLITER)
if len(new_values) == 1:
new_values = new_values[0]
# if this is a classic Parameter
if len(parts) == 1:
kwargs_modified[key] = new_values
# if this is a MultiParameter
elif len(parts) == 2:
if parts[0] in kwargs_modified:
kwargs_modified[parts[0]].append((parts[1], new_values))
else:
kwargs_modified[parts[0]] = [(parts[1], new_values)]
# handle MultiParameterList
for param in multi_sub_params:
kwargs_modified[param] = []
for sub_param in multi_sub_params[param]:
kwargs_modified[param].append(multi_sub_params[param][sub_param])
kwargs_modified = self.__update_kwargs(kwargs)
workflow = self.wfmanager.get_workflow_by_class(kwargs_modified["workflow_class"])
try:
workflow.check_parameters_rules(kwargs_modified)
except Exception as e:
......@@ -540,6 +466,48 @@ class JFlowServer (object):
status["edges"] = g.edges()
return status
def __update_kwargs(self, **kwargs):
kwargs_modified = {}
# handle MultiParameterList
multi_sub_params = {}
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
if len(parts) == 3:
if not parts[0] in kwargs_modified:
kwargs_modified[parts[0]] = []
multi_sub_params[parts[0]] = {}
if parts[2] in multi_sub_params[parts[0]]:
multi_sub_params[parts[0]][parts[2]].append((parts[1], kwargs[key]))
else:
multi_sub_params[parts[0]][parts[2]] = [(parts[1], kwargs[key])]
for key in list(kwargs.keys()):
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
# split append values
new_values = kwargs[key].split(JFlowServer.APPEND_PARAM_SPLITER)
if len(new_values) == 1:
new_values = new_values[0]
# if this is a classic Parameter
if len(parts) == 1:
kwargs_modified[key] = new_values
# if this is a MultiParameter
elif len(parts) == 2:
if parts[0] in kwargs_modified:
kwargs_modified[parts[0]].append((parts[1], new_values))
else:
kwargs_modified[parts[0]] = [(parts[1], new_values)]
# handle MultiParameterList
for param in multi_sub_params:
kwargs_modified[param] = []
for sub_param in multi_sub_params[param]:
kwargs_modified[param].append(multi_sub_params[param][sub_param])
return kwargs_modified
def _webify_outputs(self, web_path, path):
work_dir = self.jflow_config_reader.get_work_directory()
if work_dir.endswith("/"): work_dir = work_dir[:-1]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment