Show More
@@ -1,26 +1,33 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | 3 | import IPython.ipapi |
|
4 | 4 | ip = IPython.ipapi.get() |
|
5 | 5 | |
|
6 | 6 | import os, subprocess |
|
7 | 7 | |
|
8 | 8 | workdir = None |
|
9 | 9 | def workdir_f(line): |
|
10 | 10 | global workdir |
|
11 | 11 | dummy,cmd = line.split(None,1) |
|
12 | 12 | if os.path.isdir(cmd): |
|
13 | 13 | workdir = cmd |
|
14 | 14 | print "Set workdir",workdir |
|
15 | 15 | elif workdir is None: |
|
16 | 16 | print "Please set workdir first by doing e.g. 'workdir q:/'" |
|
17 | 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 | 26 | ret = subprocess.call(cmd, shell = True, cwd = workdir) |
|
20 | 27 | |
|
21 | 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