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)
评论列表
文章目录