Commit 8b7bcfbc authored by Jerome Mariette's avatar Jerome Mariette

handle multiple parameters from gui

parent b37e8f7c
......@@ -29,6 +29,7 @@ try:
except ImportError:
sys.exc_clear()
import jflow
from jflow.workflows_manager import WorkflowsManager
from jflow.config_reader import JFlowConfigReader
from jflow.workflow import Workflow
......@@ -39,6 +40,8 @@ from cctools.util import time_format
class JFlowServer (object):
MULTIPLE_TYPE_SPLITER = "._."
def __init__(self):
# Create a workflow manager to get access to our workflows
self.wfmanager = WorkflowsManager()
......@@ -113,15 +116,34 @@ class JFlowServer (object):
for instance in wf_instances:
parameters, parameters_per_groups, groups = [], {}, ["default"]
for param in instance.parameters:
# if it's a multiple action change the action by the name
if param.action == jflow.parameter.MiltipleAction:
action = "MiltipleAction"
elif param.action == jflow.parameter.MiltipleAppendAction:
action = "MiltipleAppendAction"
else:
action = param.action
hash_param = {"help": param.help,
"required": param.required,
"default": param.default,
"choices": param.choices,
"action": param.action,
"action": action,
"type": param.get_type(),
"name": param.name,
"display_name": param.display_name,
"group": param.group}
# if it's a multiple type add sub parameters
if type(param.type) == jflow.parameter.MultipleParameters:
hash_param["sub_parameters"] = []
for sub_param in param.sub_parameters:
hash_param["sub_parameters"].append({"help": sub_param.help,
"required": sub_param.required,
"default": sub_param.default,
"choices": sub_param.choices,
"action": sub_param.action,
"type": sub_param.get_type(),
"name": param.name + JFlowServer.MULTIPLE_TYPE_SPLITER + sub_param.flag,
"display_name": sub_param.display_name})
parameters.append(hash_param)
if parameters_per_groups.has_key(param.group):
parameters_per_groups[param.group].append(hash_param)
......@@ -138,7 +160,17 @@ class JFlowServer (object):
@cherrypy.expose
@jsonify
def run_workflow(self, **kwargs):
workflow = self.wfmanager.run_workflow(kwargs["workflow_class"], kwargs)
kwargs_modified = {}
for key in kwargs.keys():
parts = key.split(JFlowServer.MULTIPLE_TYPE_SPLITER)
if len(parts) == 1:
kwargs_modified[key] = kwargs[key]
elif len(parts) == 2:
if kwargs_modified.has_key(parts[0]):
kwargs_modified[parts[0]].append((parts[1], kwargs[key]))
else:
kwargs_modified[parts[0]] = [(parts[1], kwargs[key])]
workflow = self.wfmanager.run_workflow(kwargs_modified["workflow_class"], kwargs_modified)
return self.jsonify_workflow_status(workflow, True)
@cherrypy.expose
......
......@@ -295,7 +295,9 @@ class Workflow(threading.Thread):
# find the value
value = None
for values in arg:
if values[0] == sub_param.flag: value = values[1]
if values[0] == sub_param.flag:
try: value = values[1].encode('ascii','ignore')
except: value = values[1]
if value == None: value = sub_param.default
sub_hash[sub_param.name] = value
extended_args[param.name].append(sub_hash)
......@@ -321,7 +323,9 @@ class Workflow(threading.Thread):
# find the value
value = None
for values in args[param.name]:
if values[0] == sub_param.flag: value = values[1]
if values[0] == sub_param.flag:
try: value = values[1].encode('ascii','ignore')
except: value = values[1]
if value == None: value = sub_param.default
extended_args[param.name][sub_param.name] = value
else:
......
This diff is collapsed.
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