Пример #1
0
    def insert(self, path, label, before=True):
        """Create a new sibling 'label' for 'path' by inserting into the tree
        just before 'path' (if 'before' is True) or just after 'path'
        (if 'before' is False).

        'path' must match exactly one existing node in the tree, and 'label'
        must be a label, i.e. not contain a '/', '*' or end with a bracketed
        index '[N]'."""

        # Sanity checks
        if not isinstance(path, string_types):
            raise TypeError("path MUST be a string!")
        if not isinstance(label, string_types):
            raise TypeError("label MUST be a string!")
        if not self.__handle:
            raise RuntimeError("The Augeas object has already been closed!")

        # Call the function
        ret = lib.aug_insert(self.__handle, enc(path), enc(label), before and 1
                             or 0)
        if ret != 0:
            raise ValueError("Unable to insert label!")
Пример #2
0
    def insert(self, path, label, before=True):
        """
        Create a new sibling `label` for `path` by inserting into the tree
        just before `path` (if `before` is :py:obj:`True`) or just after `path`
        (if `before` is :py:obj:`False`).

        `path` must match exactly one existing node in the tree, and `label`
        must be a label, i.e. not contain a :samp:`/`, :samp:`*` or end with
        a bracketed index :samp:`[N]`.
        """

        # Sanity checks
        if not isinstance(path, string_types):
            raise TypeError("path MUST be a string!")
        if not isinstance(label, string_types):
            raise TypeError("label MUST be a string!")
        if not self.__handle:
            raise RuntimeError("The Augeas object has already been closed!")

        # Call the function
        ret = lib.aug_insert(self.__handle, enc(path),
                             enc(label), before and 1 or 0)
        if ret != 0:
            self._raise_error(AugeasValueError, "Augeas.insert() failed")