Skip to content

Commit

Permalink
ignore processor parameters with default value
Browse files Browse the repository at this point in the history
additionally evaluate string parameters and handle lambda code
  • Loading branch information
rkoschmitzky committed Jun 15, 2020
1 parent f29ebb9 commit 5b4b980
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions dispatch/trixterdispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# ######################################################################################################################

import re
import os
import sys
import textwrap
Expand Down Expand Up @@ -63,6 +64,14 @@ def __init__(self, iterable):
super(List, self).__init__(iterable)


class Lambda(object):
def __init__(self, code):
self._code = code

def __repr__(self):
return self._code


class TaskTemplate(object):
def __init__(self, name):
self.name = name
Expand Down Expand Up @@ -128,15 +137,28 @@ def __init__(self, name="Jobtronaut"):
self.addChild(taskfile_location_plug)

@staticmethod
def _get_named_values(parent, plug_name):
def _get_named_values(parent, plug_name, ignore_if_default=False):
mapped = {}
for plug in parent.getChild(plug_name).values():
if plug.getChild("enabled"):
value = plug.getChild("value").getValue()
if isinstance(value, (
IECore.IntVectorData, IECore.StringVectorData, IECore.FloatVectorData, IECore.BoolVectorData)):
value = list(value)
mapped[plug.getChild("name").getValue()] = value
elif isinstance(value, basestring):
if re.match(r"^\s*lambda\s+.*", value):
value = Lambda(value)
else:
try:
value = eval(value)
except SyntaxError:
pass

if ignore_if_default:
if not plug.getChild("value").isSetToDefault():
mapped[plug.getChild("name").getValue()] = value
else:
mapped[plug.getChild("name").getValue()] = value

return mapped

Expand All @@ -161,7 +183,7 @@ def dispatch(self, nodes):
processor = ProcessorDefinitionTemplate(processor_node.getName())
processor.scope = list(processor_node.getChild("scope").getValue())

processor.parameters = self._get_named_values(processor_node, "parameters")
processor.parameters = self._get_named_values(processor_node, "parameters", ignore_if_default=True)

template.argument_processors.append(processor)

Expand Down

0 comments on commit 5b4b980

Please sign in to comment.