Beispiel #1
0
def dependencies_graph(username, modules=[]):
    depfile = os.path.join(ServerSettings.yang_path(username),
                           'dependencies.xml')
    if not os.path.exists(depfile):
        (rc, msg) = Compiler.compile_pyimport(username, None)
        if not rc:
            return rc, msg

    dgraph = DYGraph(depfile)
    g = dgraph.digraph([m.text.split('.yang')[0] for m in modules])
    if g is None:
        return (
            False,
            """Failed to generate dependency graph, please make sure that grapviz
python package is installed !!""")

    try:
        g.render(filename=os.path.join(settings.BASE_DIR, 'static', 'graph'))
    except:
        return (
            False,
            """Failed to render dependency graph, please make sure that grapviz
binaries (http://www.graphviz.org/Download.php) are installed on
the server !!""")

    return True, g.comment
Beispiel #2
0
def _compile_dependecies(user, modules):
    """ Compile affected modules """
    logging.debug('Compiling dependency ..')
    
    yangdst = _get_yang_path(user)
    dfile = os.path.join(yangdst, 'dependencies.xml')
    if not os.path.exists(dfile):
        logging.debug('Dependency file not found!!')
        return

    dmodules = Set([])
    dgraph = DYGraph(dfile)
    for m in modules:
        module = dgraph.dependency_module(m)
        if module is None:
            continue
        for name in module.imports:
            dmodules.add(name) 
        for name in module.depends:
            dmodules.add(name)

    dmodules_list = list(dmodules)
    for yangfile in glob.glob(os.path.join(yangdst, '*.yang')):
        basename = os.path.basename(yangfile)
        #skip dependency module itself
        if basename in modules:
            continue

        base = os.path.splitext(basename)[0]
        if '@' in base:
            base = base.split('@')[0]
        if base in dmodules_list:
            (rc, msgs) = Compiler.compile_cxml(user, None, yangfile)
Beispiel #3
0
    def get_dependencies(username, modules, session):
        """
        return dependencies for given yang models
        """
        session_dir = ''
        logging.debug("get_dependencies: Target Modules " + str(modules))
        if session is not None:
            session_dir = ServerSettings.session_path(session)
            dfile = os.path.join(session_dir, 'dependencies.xml')
        else:
            dfile = os.path.join(ServerSettings.yang_path(username), 'dependencies.xml')

        if not os.path.exists(dfile):
            logging.error('get_dependencies: dependency file %s missing!!', dfile)
            return []

        if session_dir:
            session_files = [os.path.basename(_file) for _file in glob.glob(os.path.join(session_dir, '*.yang'))]

        yang_path = ServerSettings.yang_path(username)
        yang_files = [os.path.basename(_file) for _file in glob.glob(os.path.join(yang_path, '*.yang'))]

        dmodules = Set([])
        dgraph = DYGraph(dfile)
        for m in modules:
            module = dgraph.dependency_module(m)
            if module is None:
                continue
            for name in module.imports:
                dmodules.add(name)
            for name in module.includes:
                dmodules.add(name)
            for name in module.depends:
                dmodules.add(name)

        dmodules_list = list(dmodules)

        deplist = []
        for _file in dmodules_list:
            # prefer freshly uploaded files
            if session_dir:
                depfile = _find_matching(_file, session_dir, session_files)
            else:
                depfile = _find_matching(_file, yang_path, yang_files)

            if depfile is not None:
                deplist.append(depfile)
            else:
                logging.warning("get_dependencies: Dependency (%s) not satisfied, compilation will fail !!" %  _file)

        logging.debug("get_dependencies: Computed " + str(deplist))
        return deplist
Beispiel #4
0
def dependencies_graph(username, modules=[]):
    depfile = os.path.join(ServerSettings.yang_path(username), 'dependencies.xml')
    if not os.path.exists(depfile):
        (rc, msg) = Compiler.compile_pyimport(username, None)
        if not rc: return (rc, msg)

    dgraph = DYGraph(depfile)
    g = dgraph.digraph([m.text.split('.yang')[0] for m in modules])
    if g is None:
        return (False, """Failed to generate dependency graph, please make sure that grapviz
python package is installed !!""")

    try:
        g.render(filename=os.path.join(settings.BASE_DIR, 'static', 'graph'))
    except:
        return (False, """Failed to render dependency graph, please make sure that grapviz
binaries (http://www.graphviz.org/Download.php) are installed on
the server !!""")

    return (True, g.comment)
Beispiel #5
0
    def get_dependencies(username, modules, session):
        """
        return dependencies for given yang models
        """
        session_dir = ''
        logging.debug("get_dependencies: Target Modules " + str(modules))
        if session is not None:
            session_dir = ServerSettings.session_path(session)
            dfile = os.path.join(session_dir, 'dependencies.xml')
        else:
            dfile = os.path.join(ServerSettings.yang_path(username),
                                 'dependencies.xml')

        if not os.path.exists(dfile):
            logging.error('get_dependencies: dependency file %s missing!!',
                          dfile)
            return []

        if session_dir:
            session_files = [
                os.path.basename(_file)
                for _file in glob.glob(os.path.join(session_dir, '*.yang'))
            ]

        yang_path = ServerSettings.yang_path(username)
        yang_files = [
            os.path.basename(_file)
            for _file in glob.glob(os.path.join(yang_path, '*.yang'))
        ]

        dmodules = Set([])
        dgraph = DYGraph(dfile)
        for m in modules:
            module = dgraph.dependency_module(m)
            if module is None:
                continue
            for name in module.imports:
                dmodules.add(name)
            for name in module.includes:
                dmodules.add(name)
            for name in module.depends:
                dmodules.add(name)

        dmodules_list = list(dmodules)

        deplist = []
        for _file in dmodules_list:
            # prefer freshly uploaded files
            if session_dir:
                depfile = _find_matching(_file, session_dir, session_files)
            else:
                depfile = _find_matching(_file, yang_path, yang_files)

            if depfile is not None:
                deplist.append(depfile)
            else:
                logging.warning(
                    "get_dependencies: Dependency (%s) not satisfied, compilation may fail !!"
                    % _file)

        logging.debug("get_dependencies: Computed " + str(deplist))
        return deplist