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