aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Mason2011-08-08 16:58:31 -0700
committerSeth Mason2011-08-08 16:58:31 -0700
commit729d75d59fbc313f2e421a953bbf16961bba0744 (patch)
tree4703b80f28298661aa5cd3d82beabd6b49822a41
parent96e46c6cfe3299ad2c5dca606671f5652e0eb4d4 (diff)
downloaddjango-debug-toolbar-729d75d59fbc313f2e421a953bbf16961bba0744.tar.bz2
Fixes issue #92 -- ipython API changed so debugsqlshell stopped working.
Instead of copying and pasting, just import django.core.management.commands.shell.Command.
-rw-r--r--debug_toolbar/management/commands/debugsqlshell.py60
1 files changed, 1 insertions, 59 deletions
diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py
index eaeafd4..71723fa 100644
--- a/debug_toolbar/management/commands/debugsqlshell.py
+++ b/debug_toolbar/management/commands/debugsqlshell.py
@@ -1,8 +1,8 @@
import os
from optparse import make_option
-from django.core.management.base import NoArgsCommand
from django.db.backends import util
+from django.core.management.commands.shell import Command
from debug_toolbar.utils import sqlparse
@@ -16,61 +16,3 @@ class PrintQueryWrapper(util.CursorDebugWrapper):
print
util.CursorDebugWrapper = PrintQueryWrapper
-
-# The rest is copy/paste from django/core/management/commands/shell.py
-
-class Command(NoArgsCommand):
- option_list = NoArgsCommand.option_list + (
- make_option('--plain', action='store_true', dest='plain',
- help='Tells Django to use plain Python, not IPython.'),
- )
- help = "Runs a Python interactive interpreter. Tries to use IPython, if it's available."
-
- requires_model_validation = False
-
- def handle_noargs(self, **options):
- # XXX: (Temporary) workaround for ticket #1796: force early loading of all
- # models from installed apps.
- from django.db.models.loading import get_models
- loaded_models = get_models()
-
- use_plain = options.get('plain', False)
-
- try:
- if use_plain:
- # Don't bother loading IPython, because the user wants plain Python.
- raise ImportError
- import IPython
- # Explicitly pass an empty list as arguments, because otherwise IPython
- # would use sys.argv from this script.
- shell = IPython.Shell.IPShell(argv=[])
- shell.mainloop()
- except ImportError:
- import code
- # Set up a dictionary to serve as the environment for the shell, so
- # that tab completion works on objects that are imported at runtime.
- # See ticket 5082.
- imported_objects = {}
- try: # Try activating rlcompleter, because it's handy.
- import readline
- except ImportError:
- pass
- else:
- # We don't have to wrap the following import in a 'try', because
- # we already know 'readline' was imported successfully.
- import rlcompleter
- readline.set_completer(rlcompleter.Completer(imported_objects).complete)
- readline.parse_and_bind("tab:complete")
-
- # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
- # conventions and get $PYTHONSTARTUP first then import user.
- if not use_plain:
- pythonrc = os.environ.get("PYTHONSTARTUP")
- if pythonrc and os.path.isfile(pythonrc):
- try:
- execfile(pythonrc)
- except NameError:
- pass
- # This will import .pythonrc.py as a side-effect
- import user
- code.interact(local=imported_objects)