Show More
@@ -7,13 +7,11 b' ip = IPython.ipapi.get()' | |||
|
7 | 7 | |
|
8 | 8 | import os,sys |
|
9 | 9 | |
|
10 | def restore_env(self): | |
|
10 | def restore_env(self): | |
|
11 | 11 | ip = self.getapi() |
|
12 | 12 | env = ip.db.get('stored_env', {'set' : {}, 'add' : [], 'pre' : []}) |
|
13 | 13 | for k,v in env['set'].items(): |
|
14 | #print "restore alias",k,v # dbg | |
|
15 | 14 | os.environ[k] = v |
|
16 | self.alias_table[k] = v | |
|
17 | 15 | for k,v in env['add']: |
|
18 | 16 | os.environ[k] = os.environ.get(k,"") + v |
|
19 | 17 | for k,v in env['pre']: |
@@ -90,9 +90,11 b' def main():' | |||
|
90 | 90 | def mapper(s): return s.lower() |
|
91 | 91 | |
|
92 | 92 | for cmd in syscmds: |
|
93 |
#print " |
|
|
93 | # print "sys",cmd #dbg | |
|
94 | 94 | noext, ext = os.path.splitext(cmd) |
|
95 | ip.IP.alias_table[mapper(noext)] = (0,cmd) | |
|
95 | key = mapper(noext) | |
|
96 | if key not in ip.IP.alias_table: | |
|
97 | ip.defalias(key, cmd) | |
|
96 | 98 | |
|
97 | 99 | if 'ls' in syscmds: |
|
98 | 100 | # use the colors of cygwin ls (recommended) |
@@ -184,6 +184,9 b' class IPApi:' | |||
|
184 | 184 | self.IP = ip |
|
185 | 185 | |
|
186 | 186 | self.extensions = {} |
|
187 | ||
|
188 | self.dbg = DebugTools(self) | |
|
189 | ||
|
187 | 190 | global _recent |
|
188 | 191 | _recent = self |
|
189 | 192 | |
@@ -222,6 +225,11 b' class IPApi:' | |||
|
222 | 225 | |
|
223 | 226 | import new |
|
224 | 227 | im = new.instancemethod(func,self.IP, self.IP.__class__) |
|
228 | old = getattr(self.IP, "magic_" + magicname, None) | |
|
229 | if old: | |
|
230 | self.dbg.debug_stack("Magic redefinition '%s', old %s" % (magicname, | |
|
231 | old)) | |
|
232 | ||
|
225 | 233 | setattr(self.IP, "magic_" + magicname, im) |
|
226 | 234 | |
|
227 | 235 | def ex(self,cmd): |
@@ -355,7 +363,15 b' class IPApi:' | |||
|
355 | 363 | |
|
356 | 364 | Creates a new alias named 'bb' in ipython user namespace |
|
357 | 365 | """ |
|
366 | ||
|
367 | self.dbg.check_hotname(name) | |
|
358 | 368 | |
|
369 | ||
|
370 | if name in self.IP.alias_table: | |
|
371 | self.dbg.debug_stack("Alias redefinition: '%s' => '%s' (old '%s')" % | |
|
372 | (name, cmd, self.IP.alias_table[name])) | |
|
373 | ||
|
374 | ||
|
359 | 375 | if callable(cmd): |
|
360 | 376 | self.IP.alias_table[name] = cmd |
|
361 | 377 | import IPython.shadowns |
@@ -368,7 +384,11 b' class IPApi:' | |||
|
368 | 384 | raise Exception('The %s and %l specifiers are mutually exclusive ' |
|
369 | 385 | 'in alias definitions.') |
|
370 | 386 | |
|
371 |
self.IP.alias_table[name] = (nargs,cmd) |
|
|
387 | self.IP.alias_table[name] = (nargs,cmd) | |
|
388 | return | |
|
389 | ||
|
390 | # just put it in - it's probably (0,'foo') | |
|
391 | self.IP.alias_table[name] = cmd | |
|
372 | 392 | |
|
373 | 393 | def defmacro(self, *args): |
|
374 | 394 | """ Define a new macro |
@@ -419,7 +439,35 b' class IPApi:' | |||
|
419 | 439 | m.init_ipython(self) |
|
420 | 440 | self.extensions[mod] = m |
|
421 | 441 | return m |
|
442 | ||
|
443 | ||
|
444 | class DebugTools: | |
|
445 | """ Used for debugging mishaps in api usage | |
|
446 | ||
|
447 | So far, tracing redefinitions is supported. | |
|
448 | """ | |
|
449 | ||
|
450 | def __init__(self, ip): | |
|
451 | self.ip = ip | |
|
452 | self.debugmode = False | |
|
453 | self.hotnames = set() | |
|
454 | ||
|
455 | ||
|
456 | def hotname(self, name_to_catch): | |
|
457 | self.hotnames.add(name_to_catch) | |
|
458 | ||
|
459 | def debug_stack(self, msg = None): | |
|
460 | if not self.debugmode: | |
|
461 | return | |
|
422 | 462 | |
|
463 | import traceback | |
|
464 | if msg is not None: | |
|
465 | print '====== %s ========' % msg | |
|
466 | traceback.print_stack() | |
|
467 | ||
|
468 | def check_hotname(self,name): | |
|
469 | if name in self.hotnames: | |
|
470 | self.debug_stack( "HotName '%s' caught" % name) | |
|
423 | 471 | |
|
424 | 472 | def launch_new_instance(user_ns = None): |
|
425 | 473 | """ Make and start a new ipython instance. |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py 26 |
|
|
9 | $Id: iplib.py 2646 2007-08-20 16:28:48Z vivainio $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -579,12 +579,13 b' class InteractiveShell(object,Magic):' | |||
|
579 | 579 | else: |
|
580 | 580 | auto_alias = () |
|
581 | 581 | self.auto_alias = [s.split(None,1) for s in auto_alias] |
|
582 | # Call the actual (public) initializer | |
|
583 | self.init_auto_alias() | |
|
584 | 582 | |
|
585 | 583 | # Produce a public API instance |
|
586 | 584 | self.api = IPython.ipapi.IPApi(self) |
|
587 | 585 | |
|
586 | # Call the actual (public) initializer | |
|
587 | self.init_auto_alias() | |
|
588 | ||
|
588 | 589 | # track which builtins we add, so we can clean up later |
|
589 | 590 | self.builtins_added = {} |
|
590 | 591 | # This method will add the necessary builtins for operation, but |
@@ -1017,7 +1018,8 b' class InteractiveShell(object,Magic):' | |||
|
1017 | 1018 | These are ALL parameter-less aliases""" |
|
1018 | 1019 | |
|
1019 | 1020 | for alias,cmd in self.auto_alias: |
|
1020 |
self. |
|
|
1021 | self.getapi().defalias(alias,cmd) | |
|
1022 | ||
|
1021 | 1023 | |
|
1022 | 1024 | def alias_table_validate(self,verbose=0): |
|
1023 | 1025 | """Update information about the alias table. |
@@ -1268,7 +1270,9 b' want to merge them back into the new files.""" % locals()' | |||
|
1268 | 1270 | def init_readline(self): |
|
1269 | 1271 | """Command history completion/saving/reloading.""" |
|
1270 | 1272 | |
|
1273 | ||
|
1271 | 1274 | import IPython.rlineimpl as readline |
|
1275 | ||
|
1272 | 1276 | if not readline.have_readline: |
|
1273 | 1277 | self.has_readline = 0 |
|
1274 | 1278 | self.readline = None |
@@ -1618,7 +1622,7 b' want to merge them back into the new files.""" % locals()' | |||
|
1618 | 1622 | # Mark activity in the builtins |
|
1619 | 1623 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1620 | 1624 | |
|
1621 |
if |
|
|
1625 | if self.has_readline: | |
|
1622 | 1626 | self.readline_startup_hook(self.pre_readline) |
|
1623 | 1627 | # exit_now is set by a call to %Exit or %Quit |
|
1624 | 1628 |
General Comments 0
You need to be logged in to leave comments.
Login now