##// END OF EJS Templates
jobctrl: publish in _ip namespace after installation
vivainio -
Show More
@@ -1,44 +1,53 b''
1 """ Preliminary "job control" extensions for IPython
1 """ Preliminary "job control" extensions for IPython
2
2
3 requires python 2.4 (or separate 'subprocess' module
3 requires python 2.4 (or separate 'subprocess' module
4
4
5 At the moment this is in a very "unhelpful" form, will be extended in the future.
5 At the moment this is in a very "unhelpful" form, will be extended in the future.
6
6
7 Usage:
7 Usage:
8
8
9 [ipython]|2> import jobctrl
9 [ipython]|2> import jobctrl
10 [ipython]|3> &ls
10 [ipython]|3> &ls
11 <3> <jobctrl.IpyPopen object at 0x00D87FD0>
11 <3> <jobctrl.IpyPopen object at 0x00D87FD0>
12 [ipython]|4> _3.go
12 [ipython]|4> _3.go
13 -----------> _3.go()
13 -----------> _3.go()
14 ChangeLog
14 ChangeLog
15 IPython
15 IPython
16 MANIFEST.in
16 MANIFEST.in
17 README
17 README
18 README_Windows.txt
18 README_Windows.txt
19
19
20 ...
20 ...
21 """
21 """
22
22
23 from subprocess import Popen,PIPE
23 from subprocess import Popen,PIPE
24
24
25 from IPython import genutils
25 from IPython import genutils
26
26
27 import IPython.ipapi
28
27 class IpyPopen(Popen):
29 class IpyPopen(Popen):
28 def go(self):
30 def go(self):
29 print self.communicate()[0]
31 print self.communicate()[0]
32 def __repr__(self):
33 return '<IPython job "%s">' % self.line
30
34
31 def job(job):
35 def startjob(job):
32 #p = Popen(r"q:\opt\vlc\vlc.exe http://di.fm/mp3/djmixes.pls")
33 p = IpyPopen(job, stdout=PIPE)
36 p = IpyPopen(job, stdout=PIPE)
34 p.line = job
37 p.line = job
35 return p
38 return p
36
39
37 def jobctrl_prefilter_f(self,line):
40 def jobctrl_prefilter_f(self,line):
38 if line.startswith('&'):
41 if line.startswith('&'):
39 return 'jobctrl.job(%s)' % genutils.make_quoted_expr(line[1:])
42 return '_ip.startjob(%s)' % genutils.make_quoted_expr(line[1:])
40
43
41 raise IPython.ipapi.TryNext
44 raise IPython.ipapi.TryNext
42
45
43 import IPython.ipapi
46 def install():
44 IPython.ipapi.get().set_hook('input_prefilter', jobctrl_prefilter_f)
47
48 ip = IPython.ipapi.get()
49 # needed to make startjob visible as _ip.startjob('blah')
50 ip.startjob = startjob
51 ip.set_hook('input_prefilter', jobctrl_prefilter_f)
52
53 install() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now