Ticket #6682: ipy_profiles.py

File ipy_profiles.py, 2.1 KB (added by Eduardo de Oliveira Padoan, 15 years ago)
Line 
1Index: django/core/management/commands/shell.py
2===================================================================
3--- django/core/management/commands/shell.py (revision 9232)
4+++ django/core/management/commands/shell.py (working copy)
5@@ -6,6 +6,7 @@
6 option_list = NoArgsCommand.option_list + (
7 make_option('--plain', action='store_true', dest='plain',
8 help='Tells Django to use plain Python, not IPython.'),
9+ make_option('--profile', dest='profile', help='Loads IPython with the named profile')
10 )
11 help = "Runs a Python interactive interpreter. Tries to use IPython, if it's available."
12
13@@ -19,6 +20,8 @@
14
15 use_plain = options.get('plain', False)
16
17+ profile = options.get('profile', '')
18+
19 try:
20 if use_plain:
21 # Don't bother loading IPython, because the user wants plain Python.
22@@ -26,7 +29,11 @@
23 import IPython
24 # Explicitly pass an empty list as arguments, because otherwise IPython
25 # would use sys.argv from this script.
26- shell = IPython.Shell.IPShell(argv=[])
27+ if profile:
28+ argv = ['-p', profile]
29+ else:
30+ argv = []
31+ shell = IPython.Shell.IPShell(argv=argv)
32 shell.mainloop()
33 except ImportError:
34 import code
35@@ -47,12 +54,12 @@
36
37 # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
38 # conventions and get $PYTHONSTARTUP first then import user.
39- if not use_plain:
40- pythonrc = os.environ.get("PYTHONSTARTUP")
41- if pythonrc and os.path.isfile(pythonrc):
42- try:
43- execfile(pythonrc)
44- except NameError:
45+ if not use_plain:
46+ pythonrc = os.environ.get("PYTHONSTARTUP")
47+ if pythonrc and os.path.isfile(pythonrc):
48+ try:
49+ execfile(pythonrc)
50+ except NameError:
51 pass
52 # This will import .pythonrc.py as a side-effect
53 import user
Back to Top