Show More
@@ -20,21 +20,21 b' ip = IPython.ipapi.get()' | |||
|
20 | 20 | |
|
21 | 21 | import shutil,os,shlex |
|
22 | 22 | from IPython.external import mglob |
|
23 | class IpyShellCmdException(Exception): | |
|
24 | pass | |
|
23 | ||
|
24 | from IPython.ipapi import UsageError | |
|
25 | 25 | |
|
26 | 26 | def parse_args(args): |
|
27 | 27 | """ Given arg string 'CMD files... target', return ([files], target) """ |
|
28 | 28 | |
|
29 | 29 | tup = args.split(None, 1) |
|
30 | 30 | if len(tup) == 1: |
|
31 |
raise |
|
|
31 | raise UsageError("Expected arguments for " + tup[0]) | |
|
32 | 32 | |
|
33 | 33 | tup2 = shlex.split(tup[1]) |
|
34 | 34 | |
|
35 | 35 | flist, trg = mglob.expand(tup2[0:-1]), tup2[-1] |
|
36 | 36 | if not flist: |
|
37 |
raise |
|
|
37 | raise UsageError("No files found:" + str(tup2[0:-1])) | |
|
38 | 38 | return flist, trg |
|
39 | 39 | |
|
40 | 40 | def icp(ip,arg): |
@@ -50,9 +50,12 b' def icp(ip,arg):' | |||
|
50 | 50 | import distutils.dir_util |
|
51 | 51 | |
|
52 | 52 | fs, targetdir = parse_args(arg) |
|
53 | if not os.path.isdir(targetdir): | |
|
53 | if not os.path.isdir(targetdir) and len(fs) > 1: | |
|
54 | 54 | distutils.dir_util.mkpath(targetdir,verbose =1) |
|
55 | 55 | for f in fs: |
|
56 | if os.path.isdir(f): | |
|
57 | shutil.copytree(f, targetdir) | |
|
58 | else: | |
|
56 | 59 | shutil.copy2(f,targetdir) |
|
57 | 60 | return fs |
|
58 | 61 | ip.defalias("icp",icp) |
@@ -76,7 +79,10 b' def irm(ip,arg):' | |||
|
76 | 79 | |
|
77 | 80 | Remove file[s] or dir[s] path. Dirs are deleted recursively. |
|
78 | 81 | """ |
|
82 | try: | |
|
79 | 83 | paths = mglob.expand(arg.split(None,1)[1]) |
|
84 | except IndexError: | |
|
85 | raise UsageError("%irm paths...") | |
|
80 | 86 | import distutils.dir_util |
|
81 | 87 | for p in paths: |
|
82 | 88 | print "rm",p |
General Comments 0
You need to be logged in to leave comments.
Login now