Skip to content

Commit

Permalink
shell: use proper ipython startup
Browse files Browse the repository at this point in the history
See django/django#512 for a detailed explanation why this startup method
is better.  Basically it ensures that the shell behaves like your
regular ipython shell instead of e.g. not running your ipython startup
files.
  • Loading branch information
ThiefMaster committed Apr 12, 2016
1 parent 6ecf886 commit b92643c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions indico/cli/shell.py
Expand Up @@ -90,7 +90,6 @@ def __init__(self):
super(IndicoShell, self).__init__(banner=banner, use_bpython=False)
self._context = None
self._info = None
self._quiet = False

def __call__(self, app, *args, **kwargs):
with app.test_request_context(base_url=Config.getInstance().getBaseURL()):
Expand All @@ -107,7 +106,34 @@ def run(self, no_ipython, use_bpython, quiet):
self.banner = strip_ansi(self.banner)
clearCache()
with context['dbi'].global_connection():
super(IndicoShell, self).run(no_ipython or use_bpython, not use_bpython)
self.run_shell(no_ipython or use_bpython, not use_bpython, quiet)

def run_shell(self, no_ipython, no_bpython, quiet):
# based on the flask-script Shell.run() method
context = self.get_context()

if not no_bpython:
try:
from bpython import embed
embed(banner=self.banner, locals_=context)
return
except ImportError:
pass

if not no_ipython:
try:
from IPython.terminal.ipapp import TerminalIPythonApp
ipython_app = TerminalIPythonApp.instance(user_ns=context, display_banner=not quiet)
ipython_app.initialize(argv=[])
ipython_app.shell.show_banner(self.banner)
ipython_app.start()
return
except ImportError:
pass

# Use basic python shell
import code
code.interact(self.banner, local=context)

def get_options(self):
return (
Expand Down

0 comments on commit b92643c

Please sign in to comment.