Exemplo n.º 1
0
    def find_path(self, path):
        node_set = ffi.gc(lib.ly_ctx_find_path(self._ctx, str2c(path)),
                          lib.ly_set_free)
        if not node_set:
            raise self.error('cannot find path')

        for i in range(node_set.number):
            yield Node.new(self, node_set.set.s[i])
Exemplo n.º 2
0
    def __init__(
            self,
            search_path: Optional[str] = None,
            disable_searchdir_cwd: bool = True,
            pointer=None,  # C type: "struct ly_ctx *"
            cdata=None,  # C type: "struct ly_ctx *"
    ):
        if pointer is not None:
            deprecated("pointer=", "cdata=", "2.0.0")
            cdata = pointer
        if cdata is not None:
            self.cdata = ffi.cast("struct ly_ctx *", cdata)
            return  # already initialized

        options = 0
        if disable_searchdir_cwd:
            options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD

        self.cdata = ffi.gc(
            lib.ly_ctx_new(ffi.NULL, options),
            lambda ctx: lib.ly_ctx_destroy(ctx, ffi.NULL),
        )
        if not self.cdata:
            raise self.error("cannot create context")

        search_dirs = []
        if "YANGPATH" in os.environ:
            search_dirs.extend(
                os.environ["YANGPATH"].strip(": \t\r\n'\"").split(":"))
        elif "YANG_MODPATH" in os.environ:
            search_dirs.extend(
                os.environ["YANG_MODPATH"].strip(": \t\r\n'\"").split(":"))
        if search_path:
            search_dirs.extend(search_path.strip(": \t\r\n'\"").split(":"))

        for path in search_dirs:
            if not os.path.isdir(path):
                continue
            if lib.ly_ctx_set_searchdir(self.cdata, str2c(path)) != 0:
                raise self.error("cannot set search dir")
Exemplo n.º 3
0
    def __init__(self, search_path=None,
                 options=lib.LY_CTX_DISABLE_SEARCHDIR_CWD):
        self._ctx = ffi.gc(lib.ly_ctx_new(ffi.NULL, options),
                           lambda c: lib.ly_ctx_destroy(c, ffi.NULL))
        if not self._ctx:
            raise self.error('cannot create context')

        search_dirs = []
        if 'YANGPATH' in os.environ:
            search_dirs.extend(
                os.environ['YANGPATH'].strip(': \t\r\n\'"').split(':'))
        elif 'YANG_MODPATH' in os.environ:
            search_dirs.extend(
                os.environ['YANG_MODPATH'].strip(': \t\r\n\'"').split(':'))
        if search_path:
            search_dirs.extend(search_path.strip(': \t\r\n\'"').split(':'))

        for path in search_dirs:
            if not os.path.isdir(path):
                continue
            if lib.ly_ctx_set_searchdir(self._ctx, str2c(path)) != 0:
                raise self.error('cannot set search dir')
Exemplo n.º 4
0
 def data_path(self):
     return c2str(ffi.gc(lib.lypy_data_path_pattern(self._node), lib.free))
Exemplo n.º 5
0
 def schema_path(self):
     return c2str(ffi.gc(lib.lys_path(self._node, 0), lib.free))
Exemplo n.º 6
0
 def fullname(self):
     return c2str(ffi.gc(lib.lypy_node_fullname(self._node), lib.free))