Show More
@@ -9,8 +9,10 b' def pylaunchers():' | |||||
9 | This is useful if you want to invoke .py scripts from ipykit session, |
|
9 | This is useful if you want to invoke .py scripts from ipykit session, | |
10 | just adding .py files in PATH does not work without file association. |
|
10 | just adding .py files in PATH does not work without file association. | |
11 |
|
11 | |||
|
12 | .ipy files will be run like macros. | |||
|
13 | ||||
12 | """ |
|
14 | """ | |
13 | fs = glob.glob('*.py*') |
|
15 | fs = glob.glob('*.?py*') | |
14 | for f in fs: |
|
16 | for f in fs: | |
15 | l = PyLauncher(f) |
|
17 | l = PyLauncher(f) | |
16 | n = os.path.splitext(f)[0] |
|
18 | n = os.path.splitext(f)[0] |
@@ -24,10 +24,17 b' import os,re,fnmatch,sys' | |||||
24 | def selflaunch(ip,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\ipyt |
|
27 | e.g. d:\foo\ipykit.exe a.py | |
28 |
|
28 | |||
29 | """ |
|
29 | """ | |
30 | cmd = sys.executable + ' ' + line.split(None,1)[1] |
|
30 | ||
|
31 | tup = line.split(None,1) | |||
|
32 | if len(tup) == 1: | |||
|
33 | print "Launching nested ipython session" | |||
|
34 | os.system(sys.executable) | |||
|
35 | return | |||
|
36 | ||||
|
37 | cmd = sys.executable + ' ' + tup[1] | |||
31 | print ">",cmd |
|
38 | print ">",cmd | |
32 | os.system(cmd) |
|
39 | os.system(cmd) | |
33 |
|
40 | |||
@@ -41,9 +48,13 b' class PyLauncher:' | |||||
41 | def __init__(self,script): |
|
48 | def __init__(self,script): | |
42 | self.script = os.path.abspath(script) |
|
49 | self.script = os.path.abspath(script) | |
43 | def __call__(self, ip, line): |
|
50 | def __call__(self, ip, line): | |
44 | selflaunch("py " + self.script + ' ' + line) |
|
51 | if self.script.endswith('.ipy'): | |
|
52 | ip.runlines(open(self.script).read()) | |||
|
53 | else: | |||
|
54 | selflaunch("py " + self.script + ' ' + line) | |||
45 | def __repr__(self): |
|
55 | def __repr__(self): | |
46 | return 'PyLauncher("%s")' % self.script |
|
56 | return 'PyLauncher("%s")' % self.script | |
|
57 | ||||
47 | def rehashdir_f(self,arg): |
|
58 | def rehashdir_f(self,arg): | |
48 | """ Add executables in all specified dirs to alias table |
|
59 | """ Add executables in all specified dirs to alias table | |
49 |
|
60 |
General Comments 0
You need to be logged in to leave comments.
Login now