##// END OF EJS Templates
added 'shell_hook' for hooking own 'system()' implementations
vivainio -
Show More
@@ -32,7 +32,7 b" ip.set_hook('editor', calljed)"
32 You can then enable the functionality by doing 'import myiphooks'
32 You can then enable the functionality by doing 'import myiphooks'
33 somewhere in your configuration files or ipython command line.
33 somewhere in your configuration files or ipython command line.
34
34
35 $Id: hooks.py 2899 2007-12-28 08:32:59Z fperez $"""
35 $Id: hooks.py 2951 2008-01-19 11:32:18Z vivainio $"""
36
36
37 #*****************************************************************************
37 #*****************************************************************************
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
@@ -48,14 +48,14 b' __license__ = Release.license'
48 __version__ = Release.version
48 __version__ = Release.version
49
49
50 import os,bisect
50 import os,bisect
51 from genutils import Term
51 from genutils import Term,shell
52 from pprint import PrettyPrinter
52 from pprint import PrettyPrinter
53
53
54 # List here all the default hooks. For now it's just the editor functions
54 # List here all the default hooks. For now it's just the editor functions
55 # but over time we'll move here all the public API for user-accessible things.
55 # but over time we'll move here all the public API for user-accessible things.
56 __all__ = ['editor', 'fix_error_editor', 'result_display',
56 __all__ = ['editor', 'fix_error_editor', 'result_display',
57 'input_prefilter', 'shutdown_hook', 'late_startup_hook',
57 'input_prefilter', 'shutdown_hook', 'late_startup_hook',
58 'generate_prompt', 'generate_output_prompt' ]
58 'generate_prompt', 'generate_output_prompt','shell_hook']
59
59
60 pformat = PrettyPrinter().pformat
60 pformat = PrettyPrinter().pformat
61
61
@@ -213,3 +213,9 b' def generate_prompt(self, is_continuation):'
213 def generate_output_prompt(self):
213 def generate_output_prompt(self):
214 ip = self.api
214 ip = self.api
215 return str(ip.IP.outputcache.prompt_out)
215 return str(ip.IP.outputcache.prompt_out)
216
217 def shell_hook(self,cmd):
218 """ Run system/shell command a'la os.system() """
219
220 shell(cmd, header=self.rc.system_header, verbose=self.rc.system_verbose)
221
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 2930 2008-01-11 07:03:11Z vivainio $
9 $Id: iplib.py 2951 2008-01-19 11:32:18Z vivainio $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -490,9 +490,7 b' class InteractiveShell(object,Magic):'
490 # The first is similar to os.system, but it doesn't return a value,
490 # The first is similar to os.system, but it doesn't return a value,
491 # and it allows interpolation of variables in the user's namespace.
491 # and it allows interpolation of variables in the user's namespace.
492 self.system = lambda cmd: \
492 self.system = lambda cmd: \
493 shell(self.var_expand(cmd,depth=2),
493 self.hooks.shell_hook(self.var_expand(cmd,depth=2))
494 header=self.rc.system_header,
495 verbose=self.rc.system_verbose)
496
494
497 # These are for getoutput and getoutputerror:
495 # These are for getoutput and getoutputerror:
498 self.getoutput = lambda cmd: \
496 self.getoutput = lambda cmd: \
General Comments 0
You need to be logged in to leave comments. Login now