GitLab will be upgraded on June 23th evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 4a7513ed authored by payno's avatar payno

[Workflow] add management of options and process_updater_key

When we want to generate a script from a workflow definition we are copying existing settings.

But sometime (for example for est with bm23) we would like ti update settings when calling the script.
With something like `python myscript --set-params-process1 param1name:param1value,param2name:param2value

To insure this feature we:
- add an option to the "with_opts" to the converter. If true then the signature of the generated main section will be (input_data, channel) instead of (input_data, channel, options)
- an optional 'attributes' of the ppf addon as aliases but named `settings_parameters` (there is an example of such an usage in est)
  it define for each process an optional attribute that we should be able to access from options.[process_name]
- client processes should implement the 'update_properties' function
parent f9f4bae3
Pipeline #40754 failed with stages
in 49 seconds
......@@ -147,13 +147,20 @@ class ProcessableWorkflow(_BaseWorkflow):
class Converter:
"""
Write a Workflow to a python file which can be executed later
:param workflow:
:param output_file:
:param bool with_opts: if true then will add a `options` parameter in the
`main` function and will add an line for each
process having a `settings_updater` defined.
"""
def __init__(self, workflow, output_file):
def __init__(self, workflow, output_file, with_opts=False):
if not isinstance(workflow, _BaseWorkflow):
raise TypeError("workflow should be an instance of `_BaseWorkflow`")
self.workflow = workflow
self.output_file = output_file
self._with_opts = with_opts
def process(self):
self._write_import()
......@@ -166,7 +173,10 @@ class Converter:
def _write_main_section(self):
with open(self.output_file, "a") as file_:
file_.write("\n\n")
file_.write("def main(input_data, channel):\n")
if self._with_opts:
file_.write("def main(input_data, channel, options):\n")
else:
file_.write("def main(input_data, channel):\n")
def _close_main_section(self):
with open(self.output_file, "a") as file_:
......@@ -193,23 +203,31 @@ class Converter:
file_.write(
" process_{} = {}.{}()\n".format(node.id, mod_name, class_name)
)
if mod_name != "pypushflow.utils" and class_name != "IgnoreProcess":
if hasattr(node.class_instance, "set_properties"):
# filter some orange properties
properties = node.properties
for param in (
"controlAreaVisible",
"savedWidgetGeometry",
"__version__",
"libraryListSource",
):
if param in properties:
del properties[param]
file_.write(
" process_{}.set_properties({})\n".format(
node.id, properties
)
# define set properties
if hasattr(node.class_instance, "set_properties"):
# filter some orange properties
properties = node.properties
for param in (
"controlAreaVisible",
"savedWidgetGeometry",
"__version__",
"libraryListSource",
):
if param in properties:
del properties[param]
file_.write(
" process_{}.set_properties({})\n".format(
node.id, properties
)
)
# define update_properties
if self._with_opts and hasattr(node.class_instance, "update_properties"):
if node.process_updater_key is not None:
file_.write(
" process_{}.update_properties(options.{})\n".format(
node.id, node.process_updater_key
)
)
def _write_processing(self):
for _, link in self.workflow._representation.links.items():
......
Subproject commit cc987598003c3a89021406b1842d68c3bd5b50cc
Subproject commit b3039c3e7e7eaf7ab4153757018799f406fb7520
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