Beispiel #1
0
    def ValidateUniqueIds(self):
        """Validate that 'name' attribute is unique in all nodes in this tree
    except for nodes that are children of <if> nodes.
    """
        unique_names = {}
        duplicate_names = []
        for node in self:
            if isinstance(node, message.PhNode):
                continue  # PhNode objects have a 'name' attribute which is not an ID
            if node.attrs.get('generateid', 'true') == 'false':
                continue  # Duplication not relevant in that case

            node_ids = node.GetTextualIds()
            if node_ids:
                for node_id in node_ids:
                    if util.SYSTEM_IDENTIFIERS.match(node_id):
                        continue  # predefined IDs are sometimes used more than once

                    # Don't complain about duplicate IDs if they occur in a node that is
                    # inside an <if> node.
                    if (node_id in unique_names
                            and node_id not in duplicate_names
                            and (not node.parent
                                 or not isinstance(node.parent, IfNode))):
                        duplicate_names.append(node_id)
                    unique_names[node_id] = 1

        if len(duplicate_names):
            raise exception.DuplicateKey(', '.join(duplicate_names))
Beispiel #2
0
    def ValidateUniqueIds(self):
        """Validate that 'name' attribute is unique in all nodes in this tree
    except for nodes that are children of <if> nodes.
    """
        unique_names = {}
        duplicate_names = []
        # To avoid false positives from mutually exclusive <if> clauses, check
        # against whatever the output condition happens to be right now.
        # TODO(benrg): do something better.
        for node in self.ActiveDescendants():
            if node.attrs.get('generateid', 'true') == 'false':
                continue  # Duplication not relevant in that case

            for node_id in node.GetTextualIds():
                if util.SYSTEM_IDENTIFIERS.match(node_id):
                    continue  # predefined IDs are sometimes used more than once

                if node_id in unique_names and node_id not in duplicate_names:
                    duplicate_names.append(node_id)
                unique_names[node_id] = 1

        if len(duplicate_names):
            raise exception.DuplicateKey(', '.join(duplicate_names))