Пример #1
0
    def add(self, typename, instance):
        if not hasattr(instance, "keys"):
            raise error.ParseError("Expected mapping for %s" % typename, anchor=getattr(instance, "anchor", None))

        try:
            kls = ResourceType.resources[typename]
        except KeyError:
            raise error.ParseError(
                "There is no resource type of '%s'" % typename, anchor=instance.anchor)

        resource = kls(instance)
        if resource.id in self:
            raise error.ParseError(
                "'%s' cannot be defined multiple times" % resource.id, anchor=instance.anchor)

        self[resource.id] = resource

        # Create implicit File[] nodes for any watched files
        try:
            for watched in resource.watch:
                res = bind({
                    "name": watched,
                    "policy": "watched",
                })
                res.parent = instance
                w = self.add("File", res)
                w._original_hash = None
        except errors.NoMatching:
            pass

        return resource
Пример #2
0
    def add(self, typename, instance):
        if not hasattr(instance, "keys"):
            raise error.ParseError("Expected mapping for %s" % typename,
                                   anchor=getattr(instance, "anchor", None))

        try:
            kls = ResourceType.resources[typename]
        except KeyError:
            raise error.ParseError("There is no resource type of '%s'" %
                                   typename,
                                   anchor=instance.anchor)

        resource = kls(instance)
        if resource.id in self:
            raise error.ParseError("'%s' cannot be defined multiple times" %
                                   resource.id,
                                   anchor=instance.anchor)

        self[resource.id] = resource

        # Create implicit File[] nodes for any watched files
        try:
            for watched in resource.watch:
                res = bind({
                    "name": watched,
                    "policy": "watched",
                })
                res.parent = instance
                w = self.add("File", res)
                w._original_hash = None
        except errors.NoMatching:
            pass

        return resource
Пример #3
0
 def add(self, data):
     if not isinstance(data, dict):
         raise errors.ProgrammingError(
             "You must pass a dictionary to Config.add")
     bound = ast.bind(data)
     bound.parent = self
     bound.predecessor = self.node
     self.node = bound