def setupIpython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "BinPy:\\#> " cfg.PromptManager.out_template = "BinPy:\\#: " bpyShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) bpyShell.define_magic("clear", magic_clear) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1', 'BinPY:\\#>', '-pi2', ' .\\D.:', '-po', 'BinPy:\\#>', '-nosep'] bpyShell = IPShellEmbed(argsv) bpyShell.set_banner(banner) bpyShell.set_exit_msg(exit_msg) except ImportError: raise return bpyShell()
def invoke(cls, ns, banner): # pragma: nocover """ :param ns: local namespace :param banner: interactive shell startup banner Embed an interactive ipython shell. Try the InteractiveShellEmbed API first, fall back on IPShellEmbed for older IPython versions. """ try: from IPython.frontend.terminal.embed import ( InteractiveShellEmbed ) # try and load their default profile from IPython.frontend.terminal.ipapp import ( load_default_config ) config = load_default_config() shell = InteractiveShellEmbed(config=config, banner2=banner) shell(local_ns=ns) except ImportError: # Support for the IPython <= 0.10 shell API from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=[]) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=ns, global_ns={})
def setupIpython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "BinPy:\\#> " cfg.PromptManager.out_template = "BinPy:\\#: " bpyShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) bpyShell.define_magic("clear", magic_clear) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = [ '-pi1', 'BinPY:\\#>', '-pi2', ' .\\D.:', '-po', 'BinPy:\\#>', '-nosep' ] bpyShell = IPShellEmbed(argsv) bpyShell.set_banner(banner) bpyShell.set_exit_msg(exit_msg) except ImportError: raise return bpyShell()
def setup_ipython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "SimpleCV:\\#> " cfg.PromptManager.out_template = "SimpleCV:\\#: " #~ cfg.InteractiveShellEmbed.prompt_in1 = "SimpleCV:\\#> " #~ cfg.InteractiveShellEmbed.prompt_out="SimpleCV:\\#: " scvShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) scvShell.define_magic("tutorial", magic_tutorial) scvShell.define_magic("clear", magic_clear) scvShell.define_magic("example", magic_examples) scvShell.define_magic("forums", magic_forums) scvShell.define_magic("walkthrough", magic_walkthrough) scvShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = [ '-pi1', 'SimpleCV:\\#>', '-pi2', ' .\\D.:', '-po', 'SimpleCV:\\#>', '-nosep' ] scvShell = IPShellEmbed(argsv) scvShell.set_banner(banner) scvShell.set_exit_msg(exit_msg) scvShell.IP.api.expose_magic("tutorial", magic_tutorial) scvShell.IP.api.expose_magic("clear", magic_clear) scvShell.IP.api.expose_magic("example", magic_examples) scvShell.IP.api.expose_magic("forums", magic_forums) scvShell.IP.api.expose_magic("walkthrough", magic_walkthrough) scvShell.IP.api.expose_magic("docs", magic_docs) except ImportError: raise return scvShell()
def invoke(cls, ns, banner): # pragma: nocover """ :param ns: local namespace :param banner: interactive shell startup banner Embed an interactive ipython shell. Try the InteractiveShellEmbed API first, fall back on IPShellEmbed for older IPython versions. """ try: from IPython.frontend.terminal.embed import (InteractiveShellEmbed) # try and load their default profile from IPython.frontend.terminal.ipapp import (load_default_config) config = load_default_config() shell = InteractiveShellEmbed(config=config, banner2=banner) shell(local_ns=ns) except ImportError: # Support for the IPython <= 0.10 shell API from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=[]) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=ns, global_ns={})
def setup_ipython(): try: import IPython from IPython.config.loader import Config from IPython.frontend.terminal.embed import InteractiveShellEmbed cfg = Config() cfg.PromptManager.in_template = "SimpleCV:\\#> " cfg.PromptManager.out_template = "SimpleCV:\\#: " #~ cfg.InteractiveShellEmbed.prompt_in1 = "SimpleCV:\\#> " #~ cfg.InteractiveShellEmbed.prompt_out="SimpleCV:\\#: " scvShell = InteractiveShellEmbed(config=cfg, banner1=banner, exit_msg=exit_msg) scvShell.define_magic("tutorial", magic_tutorial) scvShell.define_magic("clear", magic_clear) scvShell.define_magic("example", magic_examples) scvShell.define_magic("forums", magic_forums) scvShell.define_magic("walkthrough", magic_walkthrough) scvShell.define_magic("docs", magic_docs) except ImportError: try: from IPython.Shell import IPShellEmbed argsv = ['-pi1', 'SimpleCV:\\#>', '-pi2', ' .\\D.:', '-po', 'SimpleCV:\\#>', '-nosep'] scvShell = IPShellEmbed(argsv) scvShell.set_banner(banner) scvShell.set_exit_msg(exit_msg) scvShell.IP.api.expose_magic("tutorial", magic_tutorial) scvShell.IP.api.expose_magic("clear", magic_clear) scvShell.IP.api.expose_magic("example", magic_examples) scvShell.IP.api.expose_magic("forums", magic_forums) scvShell.IP.api.expose_magic("walkthrough", magic_walkthrough) scvShell.IP.api.expose_magic("docs", magic_docs) except ImportError: raise return scvShell()
def _run_shell(self, base_module, locs, disable_ipython): banner = " All objects from %s are available\n" % base_module banner += " Additional Objects:\n" banner += " %-10s - %s\n" % ('wsgiapp', "This project's WSGI App instance") banner += " %-10s - %s\n" % ('app', 'WebTest.TestApp wrapped around wsgiapp') try: if disable_ipython: raise ImportError() # try to use IPython if possible try: # ipython >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(banner2=banner) except ImportError: # ipython < 0.11 from IPython.Shell import IPShellEmbed shell = IPShellEmbed() shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=locs, global_ns={}) except ImportError: import code py_prefix = sys.platform.startswith('java') and 'J' or 'P' newbanner = "TurboGears2 Interactive Shell\n%sython %s\n\n" % \ (py_prefix, sys.version) banner = newbanner + banner shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: pass shell.interact(banner)
def command(self): """Main command to create a new shell""" self.verbose = 3 if len(self.args) == 0: # Assume the .ini file is ./development.ini config_file = 'development.ini' if not os.path.isfile(config_file): raise BadCommand('%sError: CONFIG_FILE not found at: .%s%s\n' 'Please specify a CONFIG_FILE' % \ (self.parser.get_usage(), os.path.sep, config_file)) else: config_file = self.args[0] config_name = 'config:%s' % config_file here_dir = os.getcwd() locs = dict(__name__="pylons-admin") if not self.options.quiet: # Configure logging from the config file self.logging_file_config(config_file) # Load locals and populate with objects for use in shell sys.path.insert(0, here_dir) # Load the wsgi app first so that everything is initialized right wsgiapp = loadapp(config_name, relative_to=here_dir) test_app = paste.fixture.TestApp(wsgiapp) # Query the test app to setup the environment tresponse = test_app.get('/_test_vars') request_id = int(tresponse.body) # Disable restoration during test_app requests test_app.pre_request_hook = lambda self: \ paste.registry.restorer.restoration_end() test_app.post_request_hook = lambda self: \ paste.registry.restorer.restoration_begin(request_id) # Restore the state of the Pylons special objects # (StackedObjectProxies) paste.registry.restorer.restoration_begin(request_id) # Determine the package name from the pylons.config object pkg_name = pylons.config['pylons.package'] # Start the rest of our imports now that the app is loaded if is_minimal_template(pkg_name, True): model_module = None helpers_module = pkg_name + '.helpers' base_module = pkg_name + '.controllers' else: model_module = pkg_name + '.model' helpers_module = pkg_name + '.lib.helpers' base_module = pkg_name + '.lib.base' if model_module and can_import(model_module): locs['model'] = sys.modules[model_module] if can_import(helpers_module): locs['h'] = sys.modules[helpers_module] exec ('from pylons import app_globals, config, request, response, ' 'session, tmpl_context, url') in locs exec ('from pylons.controllers.util import abort, redirect') in locs exec 'from pylons.i18n import _, ungettext, N_' in locs locs.pop('__builtins__', None) # Import all objects from the base module __import__(base_module) base = sys.modules[base_module] base_public = [__name for __name in dir(base) if not \ __name.startswith('_') or __name == '_'] locs.update((name, getattr(base, name)) for name in base_public) locs.update(dict(wsgiapp=wsgiapp, app=test_app)) mapper = tresponse.config.get('routes.map') if mapper: locs['mapper'] = mapper banner = " All objects from %s are available\n" % base_module banner += " Additional Objects:\n" if mapper: banner += " %-10s - %s\n" % ('mapper', 'Routes mapper object') banner += " %-10s - %s\n" % ('wsgiapp', "This project's WSGI App instance") banner += " %-10s - %s\n" % ('app', 'paste.fixture wrapped around wsgiapp') try: if self.options.disable_ipython: raise ImportError() # try to use IPython if possible try: # ipython >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(banner2=banner) except ImportError: # ipython < 0.11 from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=self.args) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) try: shell(local_ns=locs, global_ns={}) finally: paste.registry.restorer.restoration_end() except ImportError: import code py_prefix = sys.platform.startswith('java') and 'J' or 'P' newbanner = "Pylons Interactive Shell\n%sython %s\n\n" % \ (py_prefix, sys.version) banner = newbanner + banner shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: pass try: shell.interact(banner) finally: paste.registry.restorer.restoration_end()
def command(self): """Main command to create a new shell""" self.verbose = 3 if len(self.args) == 0: # Assume the .ini file is ./development.ini config_file = 'development.ini' if not os.path.isfile(config_file): raise BadCommand('%sError: CONFIG_FILE not found at: .%s%s\n' 'Please specify a CONFIG_FILE' % \ (self.parser.get_usage(), os.path.sep, config_file)) else: config_file = self.args[0] config_name = 'config:%s' % config_file here_dir = os.getcwd() locs = dict(__name__="pylons-admin") if not self.options.quiet: # Configure logging from the config file self.logging_file_config(config_file) # Load locals and populate with objects for use in shell sys.path.insert(0, here_dir) # Load the wsgi app first so that everything is initialized right wsgiapp = loadapp(config_name, relative_to=here_dir) test_app = paste.fixture.TestApp(wsgiapp) # Query the test app to setup the environment tresponse = test_app.get('/_test_vars') request_id = int(tresponse.body) # Disable restoration during test_app requests test_app.pre_request_hook = lambda self: \ paste.registry.restorer.restoration_end() test_app.post_request_hook = lambda self: \ paste.registry.restorer.restoration_begin(request_id) # Restore the state of the Pylons special objects # (StackedObjectProxies) paste.registry.restorer.restoration_begin(request_id) # Determine the package name from the pylons.config object pkg_name = pylons.config['pylons.package'] # Start the rest of our imports now that the app is loaded if is_minimal_template(pkg_name, True): model_module = None helpers_module = pkg_name + '.helpers' base_module = pkg_name + '.controllers' else: model_module = pkg_name + '.model' helpers_module = pkg_name + '.lib.helpers' base_module = pkg_name + '.lib.base' if model_module and can_import(model_module): locs['model'] = sys.modules[model_module] if can_import(helpers_module): locs['h'] = sys.modules[helpers_module] exec ('from pylons import app_globals, config, request, response, ' 'session, tmpl_context, url') in locs exec ('from pylons.controllers.util import abort, redirect') in locs exec 'from pylons.i18n import _, ungettext, N_' in locs locs.pop('__builtins__', None) # Import all objects from the base module __import__(base_module) base = sys.modules[base_module] base_public = [__name for __name in dir(base) if not \ __name.startswith('_') or __name == '_'] locs.update((name, getattr(base, name)) for name in base_public) locs.update(dict(wsgiapp=wsgiapp, app=test_app)) mapper = tresponse.config.get('routes.map') if mapper: locs['mapper'] = mapper banner = " All objects from %s are available\n" % base_module banner += " Additional Objects:\n" if mapper: banner += " %-10s - %s\n" % ('mapper', 'Routes mapper object') banner += " %-10s - %s\n" % ('wsgiapp', "This project's WSGI App instance") banner += " %-10s - %s\n" % ('app', 'paste.fixture wrapped around wsgiapp') try: if self.options.disable_ipython: raise ImportError() # try to use IPython if possible try: # ipython >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(banner2=banner) except ImportError: # ipython < 0.11 from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=self.args) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) try: shell(local_ns=locs, global_ns={}) finally: paste.registry.restorer.restoration_end() except ImportError: import code py_prefix = sys.platform.startswith('java') and 'J' or 'P' newbanner = "Pylons Interactive Shell\n%sython %s\n\n" % \ (py_prefix, sys.version) banner = newbanner + banner shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: pass try: shell.interact(banner) finally: paste.registry.restorer.restoration_end()
def take_action(self, opts): config_file = opts.config_file config_name = 'config:%s' % config_file here_dir = os.getcwd() locs = dict(__name__="tgshell") # Load locals and populate with objects for use in shell sys.path.insert(0, here_dir) # Load the wsgi app first so that everything is initialized right wsgiapp = loadapp(config_name, relative_to=here_dir) test_app = TestApp(wsgiapp) # Make available the tg.request and other global variables tresponse = test_app.get('/_test_vars') pkg_name = tg.config['package_name'] # Start the rest of our imports now that the app is loaded model_module = pkg_name + '.model' helpers_module = pkg_name + '.lib.helpers' base_module = pkg_name + '.lib.base' if self._can_import(model_module): locs['model'] = sys.modules[model_module] if self._can_import(helpers_module): locs['h'] = sys.modules[helpers_module] exec ('import tg') in locs exec ('from tg import app_globals, config, request, response, ' 'session, tmpl_context, url') in locs locs.pop('__builtins__', None) # Import all objects from the base module __import__(base_module) base = sys.modules[base_module] base_public = [__name for __name in dir(base) if not\ __name.startswith('_') or __name == '_'] locs.update((name, getattr(base, name)) for name in base_public) locs.update(dict(wsgiapp=wsgiapp, app=test_app)) mapper = tresponse.config.get('routes.map') if mapper: locs['mapper'] = mapper banner = " All objects from %s are available\n" % base_module banner += " Additional Objects:\n" if mapper: banner += " %-10s - %s\n" % ('mapper', 'Routes mapper object') banner += " %-10s - %s\n" % ('wsgiapp', "This project's WSGI App instance") banner += " %-10s - %s\n" % ('app', 'WebTest.TestApp wrapped around wsgiapp') try: if opts.disable_ipython: raise ImportError() # try to use IPython if possible try: # ipython >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(banner2=banner) except ImportError: # ipython < 0.11 from IPython.Shell import IPShellEmbed shell = IPShellEmbed() shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=locs, global_ns={}) except ImportError: import code py_prefix = sys.platform.startswith('java') and 'J' or 'P' newbanner = "TurboGears2 Interactive Shell\n%sython %s\n\n" %\ (py_prefix, sys.version) banner = newbanner + banner shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: pass shell.interact(banner)