def shell(): from api.app import rowboat namespace = {} try: from IPython.terminal.interactiveshell import TerminalInteractiveShell console = TerminalInteractiveShell(user_ns=namespace) print 'Starting iPython Shell' except ImportError: import code import rlcompleter c = rlcompleter.Completer(namespace) # Setup readline for autocomplete. try: # noinspection PyUnresolvedReferences import readline readline.set_completer(c.complete) readline.parse_and_bind('tab: complete') readline.parse_and_bind('set show-all-if-ambiguous on') readline.parse_and_bind('"\C-r": reverse-search-history') readline.parse_and_bind('"\C-s": forward-search-history') except ImportError: pass console = code.InteractiveConsole(namespace) print 'Starting Poverty Shell (install IPython to use improved shell)' with rowboat.app.app_context(): console.interact()
def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cto_tree.settings") try: if len(sys.argv) >= 2 and sys.argv[1] == '--plain': raise ImportError user_ns = locals() if has_ushell: app = UmengIPythonApp.instance() app.initialize() app.shell.user_ns.update(user_ns) sys.exit(app.start()) else: from IPython.terminal.interactiveshell import TerminalInteractiveShell shell = TerminalInteractiveShell(user_ns=user_ns) shell.mainloop() except ImportError: import code shell = code.InteractiveConsole(locals=locals()) shell.interact()
def main(): url = sys.argv[1] context['url'] = url pkg = app.dispatch_url(url) context['pkg'] = pkg for item in pkg.to_dict().items(): print '{} = {}'.format(*item) def prepare_readline(): import os import readline import atexit readline.parse_and_bind('tab: complete') histfile = os.path.expanduser("~/.daenerys_history") try: readline.read_history_file(histfile) except IOError: pass def savehist(histfile): readline.write_history_file(histfile) atexit.register(savehist, histfile) del atexit try: from IPython.terminal.interactiveshell import TerminalInteractiveShell shell = TerminalInteractiveShell(user_ns=context) shell.mainloop() except ImportError: import code shell = code.InteractiveConsole(locals=context) shell.runcode(prepare_readline.__code__) shell.interact()
def console(**kwargs): """ An REPL fully configured for experimentation. usage: blueberrypy console [options] options: -e ENVIRONMENT, --environment=ENVIRONMENT apply the given config environment -C ENV_VAR_NAME, --env-var ENV_VAR_NAME add the given config from environment variable name [default: BLUEBERRYPY_CONFIG] --ipython use IPython shell instead of Python one -h, --help show this help message and exit """ banner = """ ***************************************************************************** * If the configuration file you specified contains a [sqlalchemy_engine*] * * section, a default SQLAlchemy engine and session should have been created * * for you automatically already. * ***************************************************************************** """ environment = kwargs.get("environment") config_dir = kwargs.get("config_dir") environment and cherrypy.config.update({"environment": environment}) configuration = BlueberryPyConfiguration( config_dir=config_dir, environment=environment, env_var_name=kwargs.get('env_var'), ) use_ipython = kwargs.get("ipython", False) package_name = shell.get_package_name(configuration) if use_ipython: try: from IPython.terminal.interactiveshell import TerminalInteractiveShell except ImportError as e: print(e) print("""Cannot import iPython. Did you install it?""") return try: app_package = import_module(package_name) except ImportError as e: print(e) app_package = None repl = TerminalInteractiveShell( user_ns=shell.get_user_namespace(configuration), user_module=app_package, display_completions='multicolumn', # oldstyle is 'readlinelike' mouse_support=True, space_for_menu=10, # reserve N lines for the completion menu ) repl.show_banner(banner) repl.mainloop() else: try: import readline except ImportError as e: print(e) else: import rlcompleter sys.ps1 = "[%s]>>> " % package_name sys.ps2 = "[%s]... " % package_name ns = shell.get_user_namespace(configuration, include_pkg=True) repl = InteractiveConsole(locals=ns) repl.prompt = package_name repl.interact(banner)