Show More
@@ -1,26 +1,33 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 | import IPython.ipapi |
|
3 | import IPython.ipapi | |
4 | ip = IPython.ipapi.get() |
|
4 | ip = IPython.ipapi.get() | |
5 |
|
5 | |||
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(line): | |
10 | global workdir |
|
10 | global workdir | |
11 | dummy,cmd = line.split(None,1) |
|
11 | dummy,cmd = line.split(None,1) | |
12 | if os.path.isdir(cmd): |
|
12 | if os.path.isdir(cmd): | |
13 | workdir = cmd |
|
13 | workdir = cmd | |
14 | print "Set workdir",workdir |
|
14 | print "Set workdir",workdir | |
15 | elif workdir is None: |
|
15 | elif workdir is None: | |
16 | print "Please set workdir first by doing e.g. 'workdir q:/'" |
|
16 | print "Please set workdir first by doing e.g. 'workdir q:/'" | |
17 | else: |
|
17 | else: | |
18 | print "Execute command in",workdir |
|
18 | sp = cmd.split(None,1) | |
|
19 | if len(sp) == 1: | |||
|
20 | head, tail = cmd, '' | |||
|
21 | else: | |||
|
22 | head, tail = sp | |||
|
23 | if os.path.isfile(head): | |||
|
24 | cmd = os.path.abspath(head) + ' ' + tail | |||
|
25 | print "Execute command",cmd,"in",workdir | |||
19 | ret = subprocess.call(cmd, shell = True, cwd = workdir) |
|
26 | ret = subprocess.call(cmd, shell = True, cwd = workdir) | |
20 |
|
27 | |||
21 | ip.defalias("workdir",workdir_f) |
|
28 | ip.defalias("workdir",workdir_f) | |
22 |
|
29 | |||
23 |
|
30 | |||
24 |
|
31 | |||
25 |
|
32 | |||
26 |
|
33 |
General Comments 0
You need to be logged in to leave comments.
Login now