示例#1
0
 def _deserialize_logical(self, node):
     """
     Reads the logical tag from the given node, returns a Condition object.
     
     node -- the xml node (xml.dom.minidom.Node)
     """
     term1_attrib = node.getAttribute('left-field')
     term1_value = node.getAttribute('left-value')
     op = node.nodeName.lower()
     term2_attrib = node.getAttribute('right-field')
     term2_value = node.getAttribute('right-value')
     kwargs = {}
     if not _op_map.has_key(op):
         _exc('Invalid operator')
     if term1_attrib != '' and term1_value != '':
         _exc('Both, left-field and left-value attributes found')
     elif term1_attrib == '' and term1_value == '':
         _exc('left-field or left-value attribute required')
     elif term1_value != '':
         left = term1_value
     else:
         left = operators.Attrib(term1_attrib)
     if term2_attrib != '' and term2_value != '':
         _exc('Both, right-field and right-value attributes found')
     elif term2_attrib == '' and term2_value == '':
         _exc('right-field or right-value attribute required')
     elif term2_value != '':
         right = term2_value
     else:
         right = operators.Attrib(term2_attrib)
     return _op_map[op](left, right)
    def _read_condition(self, node):
        """
        Reads the logical tag from the given node, returns a Condition object.

        node -- the xml node (xml.dom.minidom.Node)
        """
        term1 = node.getAttribute('field-value')
        op = node.nodeName.lower()
        term2 = node.getAttribute('other-value')
        if op not in _op_map:
            raise StorageException('Invalid operator in XML file')
        return _op_map[op](operators.Attrib(term1), operators.Attrib(term2))
示例#3
0
    def _deserialize_task_spec(self, workflow, start_node, read_specs):
        """
        Reads the task from the given node and returns a tuple
        (start, end) that contains the stream of objects that model
        the behavior.
        
        workflow -- the workflow with which the task is associated
        start_node -- the xml structure (xml.dom.minidom.Node)
        """
        # Extract attributes from the node.
        nodetype = start_node.nodeName.lower()
        name = start_node.getAttribute('name').lower()
        context = start_node.getAttribute('context').lower()
        mutex = start_node.getAttribute('mutex').lower()
        cancel = start_node.getAttribute('cancel').lower()
        success = start_node.getAttribute('success').lower()
        times = start_node.getAttribute('times').lower()
        times_field = start_node.getAttribute('times-field').lower()
        threshold = start_node.getAttribute('threshold').lower()
        threshold_field = start_node.getAttribute('threshold-field').lower()
        file = start_node.getAttribute('file').lower()
        file_field = start_node.getAttribute('file-field').lower()
        kwargs = {
            'lock': [],
            'data': {},
            'defines': {},
            'pre_assign': [],
            'post_assign': []
        }
        if not _spec_map.has_key(nodetype):
            _exc('Invalid task type "%s"' % nodetype)
        if nodetype == 'start-task':
            name = 'start'
        if name == '':
            _exc('Invalid task name "%s"' % name)
        if read_specs.has_key(name):
            _exc('Duplicate task name "%s"' % name)
        if cancel != '' and cancel != u'0':
            kwargs['cancel'] = True
        if success != '' and success != u'0':
            kwargs['success'] = True
        if times != '':
            kwargs['times'] = int(times)
        if times_field != '':
            kwargs['times'] = operators.Attrib(times_field)
        if threshold != '':
            kwargs['threshold'] = int(threshold)
        if threshold_field != '':
            kwargs['threshold'] = operators.Attrib(threshold_field)
        if file != '':
            kwargs['file'] = file
        if file_field != '':
            kwargs['file'] = operators.Attrib(file_field)
        if nodetype == 'choose':
            kwargs['choice'] = []
        if nodetype == 'trigger':
            context = [context]
        if mutex != '':
            context = mutex

        # Walk through the children of the node.
        successors = []
        for node in start_node.childNodes:
            if node.nodeType != minidom.Node.ELEMENT_NODE:
                continue
            if node.nodeName == 'description':
                kwargs['description'] = node.firstChild.nodeValue
            elif node.nodeName == 'successor' \
              or node.nodeName == 'default-successor':
                if node.firstChild is None:
                    _exc('Empty %s tag' % node.nodeName)
                successors.append((None, node.firstChild.nodeValue))
            elif node.nodeName == 'conditional-successor':
                successors.append(self._deserialize_condition(workflow, node))
            elif node.nodeName == 'define':
                key, value = self._deserialize_data(workflow, node)
                kwargs['defines'][key] = value
            # "property" tag exists for backward compatibility.
            elif node.nodeName == 'data' or node.nodeName == 'property':
                key, value = self._deserialize_data(workflow, node)
                kwargs['data'][key] = value
            elif node.nodeName == 'pre-assign':
                kwargs['pre_assign'].append(
                    self._deserialize_assign(workflow, node))
            elif node.nodeName == 'post-assign':
                kwargs['post_assign'].append(
                    self._deserialize_assign(workflow, node))
            elif node.nodeName == 'in':
                kwargs['in_assign'] = self._deserialize_assign_list(
                    workflow, node)
            elif node.nodeName == 'out':
                kwargs['out_assign'] = self._deserialize_assign_list(
                    workflow, node)
            elif node.nodeName == 'cancel':
                if node.firstChild is None:
                    _exc('Empty %s tag' % node.nodeName)
                if context == '':
                    context = []
                elif type(context) != type([]):
                    context = [context]
                context.append(node.firstChild.nodeValue)
            elif node.nodeName == 'lock':
                if node.firstChild is None:
                    _exc('Empty %s tag' % node.nodeName)
                kwargs['lock'].append(node.firstChild.nodeValue)
            elif node.nodeName == 'pick':
                if node.firstChild is None:
                    _exc('Empty %s tag' % node.nodeName)
                kwargs['choice'].append(node.firstChild.nodeValue)
            else:
                _exc('Unknown node: %s' % node.nodeName)

        # Create a new instance of the task spec.
        module = _spec_map[nodetype]
        if nodetype == 'start-task':
            spec = module(workflow, **kwargs)
        elif nodetype == 'multi-instance' or nodetype == 'thread-split':
            if times == '' and times_field == '':
                _exc('Missing "times" or "times-field" in "%s"' % name)
            elif times != '' and times_field != '':
                _exc('Both, "times" and "times-field" in "%s"' % name)
            spec = module(workflow, name, **kwargs)
        elif context == '':
            spec = module(workflow, name, **kwargs)
        else:
            spec = module(workflow, name, context, **kwargs)

        read_specs[name] = spec, successors