コード例 #1
0
ファイル: process.py プロジェクト: tonich-sh/zope.wfmc
    def start(self, *arguments):
        if self.isStarted:
            raise TypeError("Already started")

        definition = self.definition
        data = self.workflowRelevantData
        evaluator = interfaces.IPythonExpressionEvaluator(self)

        # Assign data defaults.
        for id, datafield in definition.datafields.items():
            val = None
            if datafield.initialValue:
                val = evaluator.evaluate(datafield.initialValue)
            setattr(data, id, val)

        # Now apply input parameters on top of the defaults.
        args = arguments
        inputparams = [p for p in definition.parameters if p.input]
        for parameter in inputparams:
            if args:
                arg, args = args[0], args[1:]
            elif parameter.initialValue is not None:
                arg = evaluator.evaluate(parameter.initialValue)
            else:
                # __traceback_info__ = (self, args, definition.parameters)
                raise ValueError(
                    'Insufficient arguments passed to process.')
            setattr(data, parameter.__name__, arg)
        if args:
            raise TypeError("Too many arguments. Expected %s. got %s" %
                            (len(inputparams), len(arguments)))

        self.isStarted = True
        zope.event.notify(ProcessStarted(self))
        self.transition(None, (self.startTransition, ))
コード例 #2
0
ファイル: process.py プロジェクト: tonich-sh/zope.wfmc
    def __init__(self, process, definition):
        self.process = process
        self.activity_definition_identifier = definition.id
        self.workitems = {}
        self.finishedWorkitems = {}
        self.workitemIdSequence = Sequence()
        self.active = True

        # Didn't want to change the getter, but do want it set from the
        # constructor
        self._p_definition = definition

        self.id = self.process.activityIdSequence.next()
        if hasattr(self, "definition") and \
                self.definition.andJoinSetting and \
                not self.process.has_join_revert_data(self.definition):
            self.process.set_join_revert_data(self.definition, 0)

        self.deadlines = []
        for deadlinedef in self.definition.deadlines:
            evaluator = interfaces.IPythonExpressionEvaluator(self.process)
            if not deadlinedef.duration:
                log.warn('There is an empty deadline time in '
                          '{} for activity {}.'.format(process, definition.id))
                continue
            try:
                evaled = evaluator.evaluate(deadlinedef.duration,
                                            {'timedelta': timedelta,
                                             'datetime': datetime})
            except Exception as e:
                raise RuntimeError(
                    'Evaluating the deadline duration failed '
                    'for activity {}. Error: {}'.format(definition.id, e))

            if evaled is None:
                log.warn('There is an empty deadline time in '
                          '{} for activity {}.'.format(process, definition.id))
                continue

            if isinstance(evaled, timedelta):
                deadline_time = datetime.datetime.now() + evaled
            elif isinstance(evaled, datetime.datetime):
                deadline_time = evaled
            elif isinstance(evaled, int):
                deadline_time = datetime.datetime.now() + \
                    timedelta(seconds=evaled)
            else:
                raise ValueError(
                    'Deadline time was not a timedelta, datetime, or integer '
                    'number of seconds.\n{}'.format(evaled)
                )

            deadline = self.DeadlineFactory(self, deadline_time, deadlinedef)
            self.deadlines.append(deadline)
            self.process.deadlineTimer(deadline)

        self.activity_definition_identifier_path = \
            calculateActivityStackPath(self)
        self.createWorkItems()
コード例 #3
0
    def outputs(self):
        outputs = {}
        evaluator = interfaces.IPythonExpressionEvaluator(self)
        for parameter in self.definition.parameters:
            if parameter.output:
                if hasattr(self.workflowRelevantData, parameter.__name__):
                    value = getattr(self.workflowRelevantData,
                                    parameter.__name__)
                elif parameter.initialValue is not None:
                    value = evaluator.evaluate(parameter.initialValue)
                else:
                    __traceback_info__ = (self, parameter)
                    raise ValueError('Process finished, and there is an output '
                                     'parameter with no value in workflow vars '
                                     'and no initial value.')
                outputs[parameter.__name__] = value

        return outputs
コード例 #4
0
 def execute(self):
     evaluator = interfaces.IPythonExpressionEvaluator(self.process)
     evaluator.execute(self.code)
コード例 #5
0
def getEvaluator(process):
    """Return expression evaluator object for given proceess"""
    return interfaces.IPythonExpressionEvaluator(process)
コード例 #6
0
 def __call__(self, process, data={}):
     evaluator = interfaces.IPythonExpressionEvaluator(process)
     return evaluator.evaluate(self.source, data)