interact.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:topology 作者: HPENetworking 项目源码 文件源码
def interact(mgr):
    """
    Shell setup function.

    This function will setup the library, create the default namespace with
    shell symbols, setup the history file, the autocompleter and launch a shell
    session.
    """
    print('Engine nodes available for communication:')
    print('    {}'.format(', '.join(mgr.nodes.keys())))

    # Create and populate shell namespace
    ns = {
        'topology': mgr
    }
    for key, enode in mgr.nodes.items():
        ns[key] = enode

    # Configure readline, history and autocompleter
    import readline

    histfile = join(expanduser('~'), '.topology_history')
    if isfile(histfile):
        try:
            readline.read_history_file(histfile)
        except IOError:
            log.error(format_exc())
    register(readline.write_history_file, histfile)

    completer = NamespaceCompleter(ns)
    readline.set_completer(completer.complete)
    readline.parse_and_bind('tab: complete')

    # Python's Interactive
    from code import interact as pyinteract
    pyinteract('', None, ns)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号