1
1
import os
2
2
from optparse import make_option
3
3
4
- from django .core .management .base import NoArgsCommand
5
4
from django .db .backends import util
5
+ from django .core .management .commands .shell import Command
6
6
7
7
from debug_toolbar .utils import sqlparse
8
8
@@ -16,61 +16,3 @@ def execute(self, sql, params=()):
16
16
print
17
17
18
18
util .CursorDebugWrapper = PrintQueryWrapper
19
-
20
- # The rest is copy/paste from django/core/management/commands/shell.py
21
-
22
- class Command (NoArgsCommand ):
23
- option_list = NoArgsCommand .option_list + (
24
- make_option ('--plain' , action = 'store_true' , dest = 'plain' ,
25
- help = 'Tells Django to use plain Python, not IPython.' ),
26
- )
27
- help = "Runs a Python interactive interpreter. Tries to use IPython, if it's available."
28
-
29
- requires_model_validation = False
30
-
31
- def handle_noargs (self , ** options ):
32
- # XXX: (Temporary) workaround for ticket #1796: force early loading of all
33
- # models from installed apps.
34
- from django .db .models .loading import get_models
35
- loaded_models = get_models ()
36
-
37
- use_plain = options .get ('plain' , False )
38
-
39
- try :
40
- if use_plain :
41
- # Don't bother loading IPython, because the user wants plain Python.
42
- raise ImportError
43
- import IPython
44
- # Explicitly pass an empty list as arguments, because otherwise IPython
45
- # would use sys.argv from this script.
46
- shell = IPython .Shell .IPShell (argv = [])
47
- shell .mainloop ()
48
- except ImportError :
49
- import code
50
- # Set up a dictionary to serve as the environment for the shell, so
51
- # that tab completion works on objects that are imported at runtime.
52
- # See ticket 5082.
53
- imported_objects = {}
54
- try : # Try activating rlcompleter, because it's handy.
55
- import readline
56
- except ImportError :
57
- pass
58
- else :
59
- # We don't have to wrap the following import in a 'try', because
60
- # we already know 'readline' was imported successfully.
61
- import rlcompleter
62
- readline .set_completer (rlcompleter .Completer (imported_objects ).complete )
63
- readline .parse_and_bind ("tab:complete" )
64
-
65
- # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
66
- # conventions and get $PYTHONSTARTUP first then import user.
67
- if not use_plain :
68
- pythonrc = os .environ .get ("PYTHONSTARTUP" )
69
- if pythonrc and os .path .isfile (pythonrc ):
70
- try :
71
- execfile (pythonrc )
72
- except NameError :
73
- pass
74
- # This will import .pythonrc.py as a side-effect
75
- import user
76
- code .interact (local = imported_objects )
0 commit comments