Ticket #9990: shell.diff
File shell.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django/core/management/commands/shell.py
2 2 from django.core.management.base import NoArgsCommand 3 3 from optparse import make_option 4 4 5 # XXX looks like we need it to be in globals 6 # else the test on readline.get_completer fails ??? 7 try: 8 import readline 9 except ImportError: 10 pass 11 12 5 13 class Command(NoArgsCommand): 6 14 option_list = NoArgsCommand.option_list + ( 7 15 make_option('--plain', action='store_true', dest='plain', … … 34 42 # that tab completion works on objects that are imported at runtime. 35 43 # See ticket 5082. 36 44 imported_objects = {} 37 try: # Try activating rlcompleter, because it's handy.38 import readline39 except ImportError:40 pass41 else:42 # We don't have to wrap the following import in a 'try', because43 # we already know 'readline' was imported successfully.44 import rlcompleter45 readline.set_completer(rlcompleter.Completer(imported_objects).complete)46 readline.parse_and_bind("tab:complete")47 45 48 # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system 49 # conventions and get $PYTHONSTARTUP first then import user. 46 # XXX if pythonrc already defines a (possibly better) completion, 47 # this screw up everything. 48 # so better to *first* load pythonrc, then test if it's necessary 49 # to add completion 50 50 if not use_plain: 51 51 pythonrc = os.environ.get("PYTHONSTARTUP") 52 52 if pythonrc and os.path.isfile(pythonrc): 53 try: 54 execfile(pythonrc) 53 try: 54 print "loading pythonrc file %s" % pythonrc 55 execfile(pythonrc, imported_objects) 55 56 except NameError: 56 57 pass 57 58 # This will import .pythonrc.py as a side-effect 58 59 import user 60 61 # XXX 62 try: # Try activating rlcompleter, because it's handy. 63 readline 64 except NameError: 65 pass 66 else: 67 # XXX check if completer is already setup by the pythonrc 68 # else add a simple completion 69 if not readline.get_completer(): 70 # We don't have to wrap the following import in a 'try', because 71 # we already know 'readline' was imported successfully. 72 import rlcompleter 73 readline.set_completer(rlcompleter.Completer(imported_objects).complete) 74 readline.parse_and_bind("tab:complete") 75 59 76 code.interact(local=imported_objects)