##// END OF EJS Templates
- Add a new ipconfig() public function for manipulating the internal rc...
fptest -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1846 2006-10-28 07:51:56Z vivainio $"""
4 $Id: Magic.py 1879 2006-11-04 00:34:34Z fptest $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -502,16 +502,23 b' Currently the magic system has the following functions:\\n"""'
502 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
502 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
503
503
504 def magic_system_verbose(self, parameter_s = ''):
504 def magic_system_verbose(self, parameter_s = ''):
505 """Toggle verbose printing of system calls on/off."""
505 """Set verbose printing of system calls.
506
506
507 self.shell.rc_set_toggle('system_verbose')
507 If called without an argument, act as a toggle"""
508
509 if parameter_s:
510 val = bool(eval(parameter_s))
511 else:
512 val = None
513
514 self.shell.rc_set_toggle('system_verbose',val)
508 print "System verbose printing is:",\
515 print "System verbose printing is:",\
509 ['OFF','ON'][self.shell.rc.system_verbose]
516 ['OFF','ON'][self.shell.rc.system_verbose]
510
517
511 def magic_history(self, parameter_s = ''):
518 def magic_history(self, parameter_s = ''):
512 """Print input history (_i<n> variables), with most recent last.
519 """Print input history (_i<n> variables), with most recent last.
513
520
514 %history -> print at most 40 inputs (some may be multi-line)\\
521 %history -> print at most 40 inputs (some may be multi-line)\\
515 %history n -> print at most n inputs\\
522 %history n -> print at most n inputs\\
516 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
523 %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
517
524
@@ -1005,10 +1012,52 b' Currently the magic system has the following functions:\\n"""'
1005 del(user_ns[i])
1012 del(user_ns[i])
1006
1013
1007 def magic_config(self,parameter_s=''):
1014 def magic_config(self,parameter_s=''):
1008 """Show IPython's internal configuration."""
1015 """Handle IPython's internal configuration.
1009
1016
1010 page('Current configuration structure:\n'+
1017 If called without arguments, it will print IPython's complete internal
1011 pformat(self.shell.rc.dict()))
1018 configuration.
1019
1020 If called with one argument, it will print the value of that key in
1021 the configuration.
1022
1023 If called with more than one argument, the first is interpreted as a
1024 key and the rest as a Python expression which gets eval()'d.
1025
1026 Examples:
1027
1028 In [1]: s='A Python string'
1029
1030 In [2]: !echo $s
1031 A Python string
1032
1033 In [3]: config system_verbose True
1034
1035 In [4]: !echo $s
1036 IPython system call: echo A Python string
1037 A Python string
1038
1039 In [5]: %config system_header 'sys> '
1040
1041 In [6]: !echo $s
1042 sys> echo A Python string
1043 A Python string
1044
1045 # Notice the extra quotes to protect the string after interpolation:
1046 In [7]: header = "'sys2> '"
1047
1048 In [8]: %config system_header $header
1049
1050 In [9]: !echo $s
1051 sys2> echo A Python string
1052 A Python string
1053 """
1054
1055 args = parameter_s.split(None,1)
1056 key = args[0]
1057 if len(args)==1:
1058 self.shell.ipconfig(key)
1059 else:
1060 self.shell.ipconfig(key,eval(args[1]))
1012
1061
1013 def magic_logstart(self,parameter_s=''):
1062 def magic_logstart(self,parameter_s=''):
1014 """Start logging anywhere in a session.
1063 """Start logging anywhere in a session.
@@ -1,5 +1,5 b''
1 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
1 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
2 # $Id: ipythonrc 1329 2006-05-26 07:52:45Z fperez $
2 # $Id: ipythonrc 1879 2006-11-04 00:34:34Z fptest $
3
3
4 #***************************************************************************
4 #***************************************************************************
5 #
5 #
@@ -340,6 +340,15 b' xmode Context'
340
340
341 multi_line_specials 1
341 multi_line_specials 1
342
342
343
344 # System calls: When IPython makes system calls (e.g. via special syntax like
345 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
346 # executing to standard output, prefixed by a header string.
347
348 system_header "IPython system call: "
349
350 system_verbose 1
351
343 # wxversion: request a specific wxPython version (used for -wthread)
352 # wxversion: request a specific wxPython version (used for -wthread)
344
353
345 # Set this to the value of wxPython you want to use, but note that this
354 # Set this to the value of wxPython you want to use, but note that this
@@ -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 1878 2006-11-03 23:00:22Z fptest $
9 $Id: iplib.py 1879 2006-11-04 00:34:34Z fptest $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -464,16 +464,18 b' class InteractiveShell(object,Magic):'
464 # and it allows interpolation of variables in the user's namespace.
464 # and it allows interpolation of variables in the user's namespace.
465 self.system = lambda cmd: \
465 self.system = lambda cmd: \
466 shell(self.var_expand(cmd,depth=2),
466 shell(self.var_expand(cmd,depth=2),
467 header='IPython system call: ',
467 header=self.rc.system_header,
468 verbose=self.rc.system_verbose)
468 verbose=self.rc.system_verbose)
469
469 # These are for getoutput and getoutputerror:
470 # These are for getoutput and getoutputerror:
470 self.getoutput = lambda cmd: \
471 self.getoutput = lambda cmd: \
471 getoutput(self.var_expand(cmd,depth=2),
472 getoutput(self.var_expand(cmd,depth=2),
472 header='IPython system call: ',
473 header=self.rc.system_header,
473 verbose=self.rc.system_verbose)
474 verbose=self.rc.system_verbose)
475
474 self.getoutputerror = lambda cmd: \
476 self.getoutputerror = lambda cmd: \
475 getoutputerror(self.var_expand(cmd,depth=2),
477 getoutputerror(self.var_expand(cmd,depth=2),
476 header='IPython system call: ',
478 header=self.rc.system_header,
477 verbose=self.rc.system_verbose)
479 verbose=self.rc.system_verbose)
478
480
479 # RegExp for splitting line contents into pre-char//first
481 # RegExp for splitting line contents into pre-char//first
@@ -726,6 +728,7 b' class InteractiveShell(object,Magic):'
726 ipmagic = self.ipmagic,
728 ipmagic = self.ipmagic,
727 ipalias = self.ipalias,
729 ipalias = self.ipalias,
728 ipsystem = self.ipsystem,
730 ipsystem = self.ipsystem,
731 ipconfig = self.ipconfig,
729 _ip = self.api
732 _ip = self.api
730 )
733 )
731 for biname,bival in builtins_new.items():
734 for biname,bival in builtins_new.items():
@@ -961,6 +964,29 b' class InteractiveShell(object,Magic):'
961 else:
964 else:
962 error("Alias `%s` not found." % alias_name)
965 error("Alias `%s` not found." % alias_name)
963
966
967 def ipconfig(self,key=None,value=None):
968 """Manipulate the IPython config.
969
970 This provides a python interface to
971 If called with no arguments, it prints the internal IPython config
972
973 Optional arguments:
974
975 - key(None): if given, what key of the rc structure to return.
976
977 - value(None): if given, set the key to this value."""
978
979 if key is None:
980 page('Current configuration structure:\n'+
981 pformat(self.rc.dict()))
982 else:
983 if value is None:
984 print '%s -> %s' % (key,self.rc[key])
985 else:
986 if key not in self.rc:
987 raise KeyError(str(key))
988 self.rc[key] = value
989
964 def ipsystem(self,arg_s):
990 def ipsystem(self,arg_s):
965 """Make a system call, using IPython."""
991 """Make a system call, using IPython."""
966
992
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6
6
7 This file contains the main make_IPython() starter function.
7 This file contains the main make_IPython() starter function.
8
8
9 $Id: ipmaker.py 1384 2006-06-29 20:04:37Z vivainio $"""
9 $Id: ipmaker.py 1879 2006-11-04 00:34:34Z fptest $"""
10
10
11 #*****************************************************************************
11 #*****************************************************************************
12 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
12 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -218,6 +218,7 b" object? -> Details about 'object'. ?object also works, ?? prints more."
218 separate_in = '\n',
218 separate_in = '\n',
219 separate_out = '\n',
219 separate_out = '\n',
220 separate_out2 = '',
220 separate_out2 = '',
221 system_header = 'IPython system call: ',
221 system_verbose = 0,
222 system_verbose = 0,
222 gthread = 0,
223 gthread = 0,
223 qthread = 0,
224 qthread = 0,
@@ -299,7 +299,16 b' def main():'
299 runners = dict(ipython=IPythonRunner,
299 runners = dict(ipython=IPythonRunner,
300 python=PythonRunner,
300 python=PythonRunner,
301 sage=SAGERunner)
301 sage=SAGERunner)
302 runners[opts.mode]().main(args)
302
303 try:
304 ext = os.path.splitext(args[0])
305 except IndexError:
306 ext = ''
307 modes = {'.ipy':'ipython',
308 '.py':'python',
309 '.sage':'sage'}
310 mode = modes.get(ext,opts.mode)
311 runners[mode]().main(args)
303
312
304 if __name__ == '__main__':
313 if __name__ == '__main__':
305 main()
314 main()
@@ -1,3 +1,16 b''
1 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (InteractiveShell.ipconfig): new builtin, also
4 visible in ipapi as ip.config(), to programatically control the
5 internal rc object. There's an accompanying %config magic for
6 interactive use, which has been enhanced to match the
7 funtionality in ipconfig.
8
9 * IPython/Magic.py (magic_system_verbose): Change %system_verbose
10 so it's not just a toggle, it now takes an argument. Add support
11 for a customizable header when making system calls, as the new
12 system_header variable in the ipythonrc file.
13
1 2006-11-03 Walter Doerwald <walter@livinglogic.de>
14 2006-11-03 Walter Doerwald <walter@livinglogic.de>
2
15
3 * IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now
16 * IPython/Extensions/ipipe.py: xrepr(), xiter() and xattrs() are now
General Comments 0
You need to be logged in to leave comments. Login now