##// END OF EJS Templates
rename ext_rehashdir.py to ipy_rehashdir.py
vivainio -
Show More
1 NO CONTENT: file renamed from IPython/Extensions/ext_rehashdir.py to IPython/Extensions/ipy_rehashdir.py
@@ -1,24 +1,23 b''
1 1 """ System wide configuration file for IPython.
2 2
3 3 This will be imported by ipython for all users.
4 4
5 5 After this ipy_user_conf.py is imported, user specific configuration
6 6 should reside there.
7 7
8 8 """
9 9
10 10 import IPython.ipapi
11 11 ip = IPython.ipapi.get()
12 12
13 13 # add system wide configuration information, import extensions etc. here.
14 14 # nothing here is essential
15 15
16 16 import sys
17 17
18 import ext_rehashdir # %rehashdir magic
19 18 import ext_rescapture # var = !ls and var = %magic
20 19 import pspersistence # %store magic
21 20 import clearcmd # %clear
22 21 # Basic readline config
23 22
24 23 o = ip.options
@@ -1,196 +1,197 b''
1 1 """Shell mode for IPython.
2 2
3 3 Start ipython in shell mode by invoking "ipython -p sh"
4 4
5 5 (the old version, "ipython -p pysh" still works but this is the more "modern"
6 6 shell mode and is recommended for users who don't care about pysh-mode
7 7 compatibility)
8 8 """
9 9
10 10 from IPython import ipapi
11 11 import os,textwrap
12 12
13 13 # The import below effectively obsoletes your old-style ipythonrc[.ini],
14 14 # so consider yourself warned!
15 15
16 16 import ipy_defaults
17 17
18 18 def main():
19 19 ip = ipapi.get()
20 20 o = ip.options
21 21 # autocall to "full" mode (smart mode is default, I like full mode)
22 22
23 23 o.autocall = 2
24 24
25 25 # Jason Orendorff's path class is handy to have in user namespace
26 26 # if you are doing shell-like stuff
27 27 try:
28 28 ip.ex("from path import path" )
29 29 except ImportError:
30 30 pass
31 31
32 32 # beefed up %env is handy in shell mode
33 33 import envpersist
34 34 import ipy_which
35 35 import ipy_stock_completers
36 import ipy_rehashdir
36 37
37 38
38 39 ip.ex('import os')
39 40 ip.ex("def up(): os.chdir('..')")
40 41
41 42 # Nice prompt
42 43
43 44 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#> '
44 45 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green> '
45 46 o.prompt_out= '<\#> '
46 47
47 48 from IPython import Release
48 49
49 50 import sys
50 51 # I like my banner minimal.
51 52 o.banner = "Py %s IPy %s\n" % (sys.version.split('\n')[0],Release.version)
52 53
53 54 # make 'd' an alias for ls -F
54 55
55 56 ip.magic('alias d ls -F --color=auto')
56 57
57 58 ip.IP.default_option('cd','-q')
58 59
59 60 # If you only rarely want to execute the things you %edit...
60 61
61 62 #ip.IP.default_option('edit','-x')
62 63
63 64
64 65 o.prompts_pad_left="1"
65 66 # Remove all blank lines in between prompts, like a normal shell.
66 67 o.separate_in="0"
67 68 o.separate_out="0"
68 69 o.separate_out2="0"
69 70
70 71 # now alias all syscommands
71 72
72 73 db = ip.db
73 74
74 75 syscmds = db.get("syscmdlist",[] )
75 76 if not syscmds:
76 77 print textwrap.dedent("""
77 78 System command list not initialized, probably the first run...
78 79 running %rehashx to refresh the command list. Run %rehashx
79 80 again to refresh command list (after installing new software etc.)
80 81 """)
81 82 ip.magic('rehashx')
82 83 syscmds = db.get("syscmdlist")
83 84
84 85 # locase aliases on win#2 only
85 86 if os.name == 'posix':
86 87 mapper = lambda s:s
87 88 else:
88 89 def mapper(s): return s.lower()
89 90
90 91 for cmd in syscmds:
91 92 #print "al",cmd
92 93 noext, ext = os.path.splitext(cmd)
93 94 ip.IP.alias_table[mapper(noext)] = (0,cmd)
94 95 extend_shell_behavior(ip)
95 96
96 97 def extend_shell_behavior(ip):
97 98
98 99 # Instead of making signature a global variable tie it to IPSHELL.
99 100 # In future if it is required to distinguish between different
100 101 # shells we can assign a signature per shell basis
101 102 ip.IP.__sig__ = 0xa005
102 103 # mark the IPSHELL with this signature
103 104 ip.IP.user_ns['__builtins__'].__dict__['__sig__'] = ip.IP.__sig__
104 105
105 106 from IPython.Itpl import ItplNS
106 107 from IPython.genutils import shell
107 108 # utility to expand user variables via Itpl
108 109 # xxx do something sensible with depth?
109 110 ip.IP.var_expand = lambda cmd, lvars=None, depth=2: \
110 111 str(ItplNS(cmd.replace('#','\#'), ip.IP.user_ns, get_locals()))
111 112
112 113 def get_locals():
113 114 """ Substituting a variable through Itpl deep inside the IPSHELL stack
114 115 requires the knowledge of all the variables in scope upto the last
115 116 IPSHELL frame. This routine simply merges all the local variables
116 117 on the IPSHELL stack without worrying about their scope rules
117 118 """
118 119 import sys
119 120 # note lambda expression constitues a function call
120 121 # hence fno should be incremented by one
121 122 getsig = lambda fno: sys._getframe(fno+1).f_globals \
122 123 ['__builtins__'].__dict__['__sig__']
123 124 getlvars = lambda fno: sys._getframe(fno+1).f_locals
124 125 # trackback until we enter the IPSHELL
125 126 frame_no = 1
126 127 sig = ip.IP.__sig__
127 128 fsig = ~sig
128 129 while fsig != sig :
129 130 try:
130 131 fsig = getsig(frame_no)
131 132 except (AttributeError, KeyError):
132 133 frame_no += 1
133 134 except ValueError:
134 135 # stack is depleted
135 136 # call did not originate from IPSHELL
136 137 return {}
137 138 first_frame = frame_no
138 139 # walk further back until we exit from IPSHELL or deplete stack
139 140 try:
140 141 while(sig == getsig(frame_no+1)):
141 142 frame_no += 1
142 143 except (AttributeError, KeyError, ValueError):
143 144 pass
144 145 # merge the locals from top down hence overriding
145 146 # any re-definitions of variables, functions etc.
146 147 lvars = {}
147 148 for fno in range(frame_no, first_frame-1, -1):
148 149 lvars.update(getlvars(fno))
149 150 #print '\n'*5, first_frame, frame_no, '\n', lvars, '\n'*5 #dbg
150 151 return lvars
151 152
152 153 def _runlines(lines):
153 154 """Run a string of one or more lines of source.
154 155
155 156 This method is capable of running a string containing multiple source
156 157 lines, as if they had been entered at the IPython prompt. Since it
157 158 exposes IPython's processing machinery, the given strings can contain
158 159 magic calls (%magic), special shell access (!cmd), etc."""
159 160
160 161 # We must start with a clean buffer, in case this is run from an
161 162 # interactive IPython session (via a magic, for example).
162 163 ip.IP.resetbuffer()
163 164 lines = lines.split('\n')
164 165 more = 0
165 166 command = ''
166 167 for line in lines:
167 168 # skip blank lines so we don't mess up the prompt counter, but do
168 169 # NOT skip even a blank line if we are in a code block (more is
169 170 # true)
170 171 # if command is not empty trim the line
171 172 if command != '' :
172 173 line = line.strip()
173 174 # add the broken line to the command
174 175 if line and line[-1] == '\\' :
175 176 command += line[0:-1] + ' '
176 177 more = True
177 178 continue
178 179 else :
179 180 # add the last (current) line to the command
180 181 command += line
181 182 if command or more:
182 183 more = ip.IP.push(ip.IP.prefilter(command,more))
183 184 command = ''
184 185 # IPython's runsource returns None if there was an error
185 186 # compiling the code. This allows us to stop processing right
186 187 # away, so the user gets the error message at the right place.
187 188 if more is None:
188 189 break
189 190 # final newline in case the input didn't have it, so that the code
190 191 # actually does get executed
191 192 if more:
192 193 ip.IP.push('\n')
193 194
194 195 ip.IP.runlines = _runlines
195 196
196 197 main()
General Comments 0
You need to be logged in to leave comments. Login now