##// END OF EJS Templates
callable aliases now get _ip as first arg
vivainio -
Show More
@@ -37,7 +37,7 b' def parse_args(args):'
37 raise IpyShellCmdException("No files found:" + str(tup2[0:-1]))
37 raise IpyShellCmdException("No files found:" + str(tup2[0:-1]))
38 return flist, trg
38 return flist, trg
39
39
40 def icp(arg):
40 def icp(ip,arg):
41 """ icp files... targetdir
41 """ icp files... targetdir
42
42
43 Copy all files to target, creating dirs for target if necessary
43 Copy all files to target, creating dirs for target if necessary
@@ -57,7 +57,7 b' def icp(arg):'
57 return fs
57 return fs
58 ip.defalias("icp",icp)
58 ip.defalias("icp",icp)
59
59
60 def imv(arg):
60 def imv(ip,arg):
61 """ imv src tgt
61 """ imv src tgt
62
62
63 Move source to target.
63 Move source to target.
@@ -71,7 +71,7 b' def imv(arg):'
71 return fs
71 return fs
72 ip.defalias("imv",imv)
72 ip.defalias("imv",imv)
73
73
74 def irm(arg):
74 def irm(ip,arg):
75 """ irm path[s]...
75 """ irm path[s]...
76
76
77 Remove file[s] or dir[s] path. Dirs are deleted recursively.
77 Remove file[s] or dir[s] path. Dirs are deleted recursively.
@@ -87,7 +87,7 b' def irm(arg):'
87
87
88 ip.defalias("irm",irm)
88 ip.defalias("irm",irm)
89
89
90 def imkdir(arg):
90 def imkdir(ip,arg):
91 """ imkdir path
91 """ imkdir path
92
92
93 Creates dir path, and all dirs on the road
93 Creates dir path, and all dirs on the road
@@ -98,7 +98,7 b' def imkdir(arg):'
98
98
99 ip.defalias("imkdir",imkdir)
99 ip.defalias("imkdir",imkdir)
100
100
101 def igrep(arg):
101 def igrep(ip,arg):
102 """ igrep PAT files...
102 """ igrep PAT files...
103
103
104 Very dumb file scan, case-insensitive.
104 Very dumb file scan, case-insensitive.
@@ -124,7 +124,7 b' def igrep(arg):'
124
124
125 ip.defalias("igrep",igrep)
125 ip.defalias("igrep",igrep)
126
126
127 def collect(arg):
127 def collect(ip,arg):
128 """ collect foo/a.txt rec:bar=*.py
128 """ collect foo/a.txt rec:bar=*.py
129
129
130 Copies foo/a.txt to ~/_ipython/collect/foo/a.txt and *.py from bar,
130 Copies foo/a.txt to ~/_ipython/collect/foo/a.txt and *.py from bar,
@@ -154,7 +154,7 b' def collect(arg):'
154
154
155 ip.defalias("collect",collect)
155 ip.defalias("collect",collect)
156
156
157 def inote(arg):
157 def inote(ip,arg):
158 """ inote Hello world
158 """ inote Hello world
159
159
160 Adds timestamp and Hello world to ~/_ipython/notes.txt
160 Adds timestamp and Hello world to ~/_ipython/notes.txt
@@ -170,5 +170,4 b' def inote(arg):'
170 except IndexError:
170 except IndexError:
171 ip.IP.hooks.editor(fname)
171 ip.IP.hooks.editor(fname)
172
172
173 ip.defalias("inote",inote)
173 ip.defalias("inote",inote)
174
@@ -21,7 +21,7 b' ip = IPython.ipapi.get()'
21
21
22 import os,re,fnmatch,sys
22 import os,re,fnmatch,sys
23
23
24 def selflaunch(line):
24 def selflaunch(ip,line):
25 """ Launch python script with 'this' interpreter
25 """ Launch python script with 'this' interpreter
26
26
27 e.g. d:\foo\ipython.exe a.py
27 e.g. d:\foo\ipython.exe a.py
@@ -40,7 +40,7 b' class PyLauncher:'
40 """
40 """
41 def __init__(self,script):
41 def __init__(self,script):
42 self.script = os.path.abspath(script)
42 self.script = os.path.abspath(script)
43 def __call__(self, line):
43 def __call__(self, ip, line):
44 selflaunch("py " + self.script + ' ' + line)
44 selflaunch("py " + self.script + ' ' + line)
45 def __repr__(self):
45 def __repr__(self):
46 return 'PyLauncher("%s")' % self.script
46 return 'PyLauncher("%s")' % self.script
@@ -6,11 +6,21 b' ip = IPython.ipapi.get()'
6 import os, subprocess
6 import os, subprocess
7
7
8 workdir = None
8 workdir = None
9 def workdir_f(line):
9 def workdir_f(ip,line):
10 """ Exceute commands residing in cwd elsewhere
11
12 Example::
13
14 workdir /myfiles
15 cd bin
16 workdir myscript.py
17
18 executes myscript.py (stored in bin, but not in path) in /myfiles
19 """
10 global workdir
20 global workdir
11 dummy,cmd = line.split(None,1)
21 dummy,cmd = line.split(None,1)
12 if os.path.isdir(cmd):
22 if os.path.isdir(cmd):
13 workdir = cmd
23 workdir = os.path.abspath(cmd)
14 print "Set workdir",workdir
24 print "Set workdir",workdir
15 elif workdir is None:
25 elif workdir is None:
16 print "Please set workdir first by doing e.g. 'workdir q:/'"
26 print "Please set workdir first by doing e.g. 'workdir q:/'"
@@ -22,12 +32,12 b' def workdir_f(line):'
22 head, tail = sp
32 head, tail = sp
23 if os.path.isfile(head):
33 if os.path.isfile(head):
24 cmd = os.path.abspath(head) + ' ' + tail
34 cmd = os.path.abspath(head) + ' ' + tail
25 print "Execute command",cmd,"in",workdir
35 print "Execute command '" + cmd+ "' in",workdir
26 ret = subprocess.call(cmd, shell = True, cwd = workdir)
36 olddir = os.getcwd()
37 os.chdir(workdir)
38 try:
39 os.system(cmd)
40 finally:
41 os.chdir(olddir)
27
42
28 ip.defalias("workdir",workdir_f)
43 ip.defalias("workdir",workdir_f)
29
30
31
32
33
@@ -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 2718 2007-09-05 21:54:50Z vivainio $
9 $Id: iplib.py 2719 2007-09-06 18:53:34Z vivainio $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -2174,9 +2174,9 b' want to merge them back into the new files.""" % locals()'
2174 # print "=>",tgt #dbg
2174 # print "=>",tgt #dbg
2175 if callable(tgt):
2175 if callable(tgt):
2176 if '$' in line_info.line:
2176 if '$' in line_info.line:
2177 call_meth = '(_ip.itpl(%s))'
2177 call_meth = '(_ip, _ip.itpl(%s))'
2178 else:
2178 else:
2179 call_meth = '(%s)'
2179 call_meth = '(_ip,%s)'
2180 line_out = ("%s_sh.%s" + call_meth) % (line_info.preWhitespace,
2180 line_out = ("%s_sh.%s" + call_meth) % (line_info.preWhitespace,
2181 line_info.iFun,
2181 line_info.iFun,
2182 make_quoted_expr(line_info.line))
2182 make_quoted_expr(line_info.line))
@@ -1,3 +1,10 b''
1 2007-09-06 Ville Vainio <vivainio@gmail.com>
2
3 * ipy_rehashdir.py, ipy_workdir.py, ipy_fsops.py, iplib.py:
4 Callable aliases now pass the _ip as first arg. This breaks
5 compatibility with earlier 0.8.2.svn series! (though they should
6 not have been in use yet outside these few extensions)
7
1 2007-09-05 Ville Vainio <vivainio@gmail.com>
8 2007-09-05 Ville Vainio <vivainio@gmail.com>
2
9
3 * external/mglob.py: expand('dirname') => ['dirname'], instead
10 * external/mglob.py: expand('dirname') => ['dirname'], instead
@@ -305,7 +312,7 b''
305
312
306 * IPython/Extensions/ipipe.py: Added a new table icap, which executes a
313 * IPython/Extensions/ipipe.py: Added a new table icap, which executes a
307 Python string and captures the output. (Idea and original patch by
314 Python string and captures the output. (Idea and original patch by
308 Stfan van der Walt)
315 Stefan van der Walt)
309
316
310 2007-06-01 Fernando Perez <Fernando.Perez@colorado.edu>
317 2007-06-01 Fernando Perez <Fernando.Perez@colorado.edu>
311
318
@@ -325,7 +332,7 b''
325 in the input line. Split the statusbar to be able to display the currently
332 in the input line. Split the statusbar to be able to display the currently
326 active refresh interval. (Patch by Nik Tautenhahn)
333 active refresh interval. (Patch by Nik Tautenhahn)
327
334
328 2007-05-29 Jrgen Stenarson <jorgen.stenarson@bostream.nu>
335 2007-05-29 Jorgen Stenarson <jorgen.stenarson@bostream.nu>
329
336
330 * fixing set_term_title to use ctypes as default
337 * fixing set_term_title to use ctypes as default
331
338
@@ -515,7 +522,7 b''
515 * UserConfig/ipy_user_conf.py, ipy_profile_sh.py: do not import
522 * UserConfig/ipy_user_conf.py, ipy_profile_sh.py: do not import
516 ipy_stock_completers on default profile, do import on sh profile.
523 ipy_stock_completers on default profile, do import on sh profile.
517
524
518 2007-04-22 Jrgen Stenarson <jorgen.stenarson@bostream.nu>
525 2007-04-22 Jorgen Stenarson <jorgen.stenarson@bostream.nu>
519
526
520 * Fix bug in iplib.py/safe_execfile when launching ipython with a script
527 * Fix bug in iplib.py/safe_execfile when launching ipython with a script
521 like ipython.py foo.py which raised a IndexError.
528 like ipython.py foo.py which raised a IndexError.
@@ -731,7 +738,7 b''
731 * IPython/iplib.py (raw_input): Fix mishandling of unicode at
738 * IPython/iplib.py (raw_input): Fix mishandling of unicode at
732 input. Patch sent by Stefan.
739 input. Patch sent by Stefan.
733
740
734 2007-03-20 Jrgen Stenarson <jorgen.stenarson@bostream.nu>
741 2007-03-20 Jorgen Stenarson <jorgen.stenarson@bostream.nu>
735 * IPython/Extensions/ipy_stock_completer.py
742 * IPython/Extensions/ipy_stock_completer.py
736 shlex_split, fix bug in shlex_split. len function
743 shlex_split, fix bug in shlex_split. len function
737 call was missing an if statement. Caused shlex_split to
744 call was missing an if statement. Caused shlex_split to
@@ -789,7 +796,7 b''
789
796
790 * Extensions/ipy_stock_completers.py: Fixed exception
797 * Extensions/ipy_stock_completers.py: Fixed exception
791 on mismatching quotes in %run completer. Patch by
798 on mismatching quotes in %run completer. Patch by
792 Jrgen Stenarson. Closes #127.
799 Jorgen Stenarson. Closes #127.
793
800
794 2007-03-14 Ville Vainio <vivainio@gmail.com>
801 2007-03-14 Ville Vainio <vivainio@gmail.com>
795
802
@@ -819,7 +826,7 b''
819 * IPython/Extensions/igrid.py: Patch by Nik Tautenhahn:
826 * IPython/Extensions/igrid.py: Patch by Nik Tautenhahn:
820 Close help window if exiting igrid.
827 Close help window if exiting igrid.
821
828
822 2007-03-02 Jrgen Stenarson <jorgen.stenarson@bostream.nu>
829 2007-03-02 Jorgen Stenarson <jorgen.stenarson@bostream.nu>
823
830
824 * IPython/Extensions/ipy_defaults.py: Check if readline is available
831 * IPython/Extensions/ipy_defaults.py: Check if readline is available
825 before calling functions from readline.
832 before calling functions from readline.
@@ -1,3 +1,6 b''
1 import sys
2 sys.path.append('..')
3
1 import IPython.ipapi
4 import IPython.ipapi
2
5
3 IPython.ipapi.make_session()
6 IPython.ipapi.make_session()
@@ -17,7 +20,8 b' def test_db():'
17 def test_defalias():
20 def test_defalias():
18 slot = [None]
21 slot = [None]
19 # test callable alias
22 # test callable alias
20 def cb(s):
23 def cb(localip,s):
24 assert localip is ip
21 slot[0] = s
25 slot[0] = s
22
26
23 ip.defalias('testalias', cb)
27 ip.defalias('testalias', cb)
General Comments 0
You need to be logged in to leave comments. Login now