Esempio n. 1
0
    def add_child_directive(self,
                            name,
                            parameters=None,
                            position=None):  # pragma: no cover
        """Adds a new DirectiveNode to the sequence of children"""

        if not parameters:
            raise errors.PluginError(
                "Directive requires parameters and none were set.")

        insertpath, realpath, before = self._aug_resolve_child_position(
            "directive", position)
        new_metadata = {"augeasparser": self.parser, "augeaspath": realpath}

        # Create the new directive
        self.parser.aug.insert(insertpath, "directive", before)
        # Set the directive key
        self.parser.aug.set(realpath, name)
        # Check if the file was included from the root config or initial state
        enabled = self.parser.parsed_in_original(
            apache_util.get_file_path(realpath))

        new_dir = AugeasDirectiveNode(
            name=name,
            parameters=parameters,
            enabled=enabled,
            ancestor=assertions.PASS,
            filepath=apache_util.get_file_path(realpath),
            metadata=new_metadata)
        return new_dir
Esempio n. 2
0
    def add_child_block(self,
                        name,
                        parameters=None,
                        position=None):  # pragma: no cover
        """Adds a new BlockNode to the sequence of children"""

        insertpath, realpath, before = self._aug_resolve_child_position(
            name, position)
        new_metadata = {"augeasparser": self.parser, "augeaspath": realpath}

        # Create the new block
        self.parser.aug.insert(insertpath, name, before)
        # Check if the file was included from the root config or initial state
        enabled = self.parser.parsed_in_original(
            apache_util.get_file_path(realpath))

        # Parameters will be set at the initialization of the new object
        new_block = AugeasBlockNode(
            name=name,
            parameters=parameters,
            enabled=enabled,
            ancestor=assertions.PASS,
            filepath=apache_util.get_file_path(realpath),
            metadata=new_metadata)
        return new_block
Esempio n. 3
0
    def _create_directivenode(self, path):
        """Helper function to create a DirectiveNode from Augeas path"""

        name = self.parser.get_arg(path)
        metadata = {"augeasparser": self.parser, "augeaspath": path}

        # Check if the file was included from the root config or initial state
        enabled = self.parser.parsed_in_original(
            apache_util.get_file_path(path))
        return AugeasDirectiveNode(name=name,
                                   ancestor=assertions.PASS,
                                   enabled=enabled,
                                   filepath=apache_util.get_file_path(path),
                                   metadata=metadata)
Esempio n. 4
0
    def _create_blocknode(self, path):
        """
        Helper function to create a BlockNode from Augeas path. This is used by
        AugeasParserNode.find_ancestors and AugeasBlockNode.
        and AugeasBlockNode.find_blocks

        """

        name = self._aug_get_name(path)
        metadata = {"augeasparser": self.parser, "augeaspath": path}

        # Check if the file was included from the root config or initial state
        enabled = self.parser.parsed_in_original(
            apache_util.get_file_path(path))

        return AugeasBlockNode(name=name,
                               enabled=enabled,
                               ancestor=assertions.PASS,
                               filepath=apache_util.get_file_path(path),
                               metadata=metadata)
Esempio n. 5
0
    def _create_commentnode(self, path):
        """Helper function to create a CommentNode from Augeas path"""

        comment = self.parser.aug.get(path)
        metadata = {"augeasparser": self.parser, "augeaspath": path}

        # Because of the dynamic nature of AugeasParser and the fact that we're
        # not populating the complete node tree, the ancestor has a dummy value
        return AugeasCommentNode(comment=comment,
                                 ancestor=assertions.PASS,
                                 filepath=apache_util.get_file_path(path),
                                 metadata=metadata)
Esempio n. 6
0
    def add_child_comment(self, comment="", position=None):
        """Adds a new CommentNode to the sequence of children"""

        insertpath, realpath, before = self._aug_resolve_child_position(
            "#comment", position)
        new_metadata = {"augeasparser": self.parser, "augeaspath": realpath}

        # Create the new comment
        self.parser.aug.insert(insertpath, "#comment", before)
        # Set the comment content
        self.parser.aug.set(realpath, comment)

        new_comment = AugeasCommentNode(
            comment=comment,
            ancestor=assertions.PASS,
            filepath=apache_util.get_file_path(realpath),
            metadata=new_metadata)
        return new_comment