Beispiel #1
0
 def __init__(self, process_id, inputs, outputs, requirements, hints,
              script, context, engine, label, description):
     super(ExpressionTool, self).__init__(process_id,
                                          inputs,
                                          outputs,
                                          hints=hints,
                                          requirements=requirements,
                                          label=label,
                                          description=description)
     self.script = script
     self.evaluator = Evaluator()
     self.context = context
     self.engine = engine
Beispiel #2
0
 def __init__(self, process_id, inputs, outputs, requirements, hints,
              script, context, engine, label, description):
     super(ExpressionTool, self).__init__(
         process_id, inputs, outputs,
         hints=hints,
         requirements=requirements,
         label=label,
         description=description
     )
     self.script = script
     self.evaluator = Evaluator()
     self.context = context
     self.engine = engine
Beispiel #3
0
 def __init__(self, app_id, inputs, outputs, script, context,
              app_description=None,
              annotations=None,
              platform_features=None):
     super(ScriptApp, self).__init__(
         app_id, inputs, outputs,
         app_description=app_description,
         annotations=annotations,
         platform_features=platform_features
     )
     self.script = script
     self.evaluator = Evaluator()
     self.context = context
Beispiel #4
0
class ExpressionTool(Process):
    def __init__(self, process_id, inputs, outputs, requirements, hints,
                 script, context, engine, label, description):
        super(ExpressionTool, self).__init__(process_id,
                                             inputs,
                                             outputs,
                                             hints=hints,
                                             requirements=requirements,
                                             label=label,
                                             description=description)
        self.script = script
        self.evaluator = Evaluator()
        self.context = context
        self.engine = engine

    def run(self, job):
        result = self.evaluator.evaluate(self.engine, self.script,
                                         job.to_dict(self.context), None)
        return result

    def to_dict(self, context):
        d = super(ExpressionTool, self).to_dict(context)
        d.update({
            "class": "ExpressionTool",
            "script": self.script,
            "engine": self.engine
        })
        return d

    @classmethod
    def from_dict(cls, context, d):
        converted = {k: context.from_dict(v) for k, v in six.iteritems(d)}
        kwargs = Process.kwarg_dict(converted)
        kwargs.update({
            'script':
            d['script'],
            'engine':
            d['engine'],
            'context':
            context,
            'inputs': [
                InputParameter.from_dict(context, inp)
                for inp in converted.get('inputs', [])
            ],
            'outputs': [
                OutputParameter.from_dict(context, inp)
                for inp in converted.get('outputs', [])
            ]
        })
        return cls(**kwargs)
Beispiel #5
0
class ScriptApp(App):

    def __init__(self, app_id, inputs, outputs, script, context,
                 app_description=None,
                 annotations=None,
                 platform_features=None):
        super(ScriptApp, self).__init__(
            app_id, inputs, outputs,
            app_description=app_description,
            annotations=annotations,
            platform_features=platform_features
        )
        self.script = script
        self.evaluator = Evaluator()
        self.context = context

    def run(self, job):
        if isinstance(self.script, six.string_types):
            lang = 'javascript'
            expr = self.script
        elif isinstance(self.script, dict):
            lang = self.script['lang']
            expr = self.script['value']
        else:
            raise RabixError("invalid script")

        result = self.evaluator.evaluate(lang, expr, job.to_dict(self.context), None)
        return self.construct_outputs(result)

    def to_dict(self, context):
        d = super(ScriptApp, self).to_dict(context)
        d.update({
            "@type": "Script",
            "script": self.script,
            "inputs": self.inputs.schema,
            "outputs": self.outputs.schema
        })
        return d

    @classmethod
    def from_dict(cls, context, d):
        return cls(d.get('@id', six.text_type(uuid4())),
                   context.from_dict(d['inputs']),
                   context.from_dict(d['outputs']),
                   d['script'],
                   context,
                   app_description=d.get('appDescription'),
                   annotations=d.get('annotations'),
                   platform_features=d.get('platform_features'))
Beispiel #6
0
class ExpressionTool(Process):

    def __init__(self, process_id, inputs, outputs, requirements, hints,
                 script, context, engine, label, description):
        super(ExpressionTool, self).__init__(
            process_id, inputs, outputs,
            hints=hints,
            requirements=requirements,
            label=label,
            description=description
        )
        self.script = script
        self.evaluator = Evaluator()
        self.context = context
        self.engine = engine

    def run(self, job):
        result = self.evaluator.evaluate(self.engine, self.script, job.to_dict(self.context), None)
        return result

    def to_dict(self, context):
        d = super(ExpressionTool, self).to_dict(context)
        d.update({
            "class": "ExpressionTool",
            "script": self.script,
            "engine": self.engine
        })
        return d

    @classmethod
    def from_dict(cls, context, d):
        converted = {k: context.from_dict(v) for k, v in six.iteritems(d)}
        kwargs = Process.kwarg_dict(converted)
        kwargs.update({
            'script': d['script'],
            'engine': d['engine'],
            'context': context,
            'inputs': [InputParameter.from_dict(context, inp)
                       for inp in converted.get('inputs', [])],
            'outputs': [OutputParameter.from_dict(context, inp)
                        for inp in converted.get('outputs', [])]
        })
        return cls(**kwargs)