On 11/2/07, William Stein <[EMAIL PROTECTED]> wrote: > Ah, that's very very nice. OK, I would really like > to see that implemented. Maybe Fernando Perez could > tell us how to hook into IPython to make that happen....
Should be fairly straightforward. In iplib.py, around line 500, you'll find this code: # Functions to call the underlying shell. # The first is similar to os.system, but it doesn't return a value, # and it allows interpolation of variables in the user's namespace. self.system = lambda cmd: \ shell(self.var_expand(cmd,depth=2), header=self.rc.system_header, verbose=self.rc.system_verbose) # These are for getoutput and getoutputerror: self.getoutput = lambda cmd: \ getoutput(self.var_expand(cmd,depth=2), header=self.rc.system_header, verbose=self.rc.system_verbose) self.getoutputerror = lambda cmd: \ getoutputerror(self.var_expand(cmd,depth=2), header=self.rc.system_header, verbose=self.rc.system_verbose) where 'shell', 'getoutput' and 'getoutputerror' are all defined in IPython.genutils. Simply take the ipython instance, and before you hand it to the user for 'live' usage, change its .system attribute to be your own routine which is similar to the above lambda, but does the additional extra checks you want. Basically code like (this is just a sketch): import new old_system = ipython_instance.system def sage_system(self,cmd): if cmd_in_sage_programs(): old_system(cmd) else: try: update_environment() old_system(cmd) finally: restore_environment() ipython_instance.system = new.instancemethod(ipython_instance,sage_system) This is obviously incomplete, but it should give you an idea of what's needed. Cheers, f ps - at the NSF CDI meeting in Washington http://www4.ncsu.edu/~kaltofen/CDI_SYMNUM_Itinerary.html I made sure to have in my talk a slide about SAGE and to point out its goals and importance. I didn't have much time for it, but hopefully every bit helps. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---