Show More
@@ -20,7 +20,7 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 |
|
23 | from IPython.Extensions.path import path | ||
24 | from IPython.ipapi import UsageError |
|
24 | from IPython.ipapi import UsageError | |
25 |
|
25 | |||
26 | def parse_args(args): |
|
26 | def parse_args(args): | |
@@ -184,24 +184,19 b' def pathobj_unmangle(s):' | |||||
184 | return s.replace('__',' ').replace('DOT','.') |
|
184 | return s.replace('__',' ').replace('DOT','.') | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | class FileObj: |
|
|||
188 | def __init__(self,p): |
|
|||
189 | self.path = p |
|
|||
190 | def __call__(self): |
|
|||
191 | os.startfile(self.path) |
|
|||
192 | def __str__(self): |
|
|||
193 | return self.path |
|
|||
194 |
|
187 | |||
195 | class PathObj: |
|
188 | class PathObj: | |
196 | def __init__(self,p): |
|
189 | def __init__(self,p): | |
197 | self.path = p |
|
190 | self.path = p | |
198 | if os.path.isdir(p): |
|
191 | if p != '.': | |
|
192 | self.ents = [pathobj_mangle(ent) for ent in os.listdir(p)] | |||
|
193 | else: | |||
199 | self.ents = None |
|
194 | self.ents = None | |
200 | self.ents = [pathobj_mangle(ent) for ent in os.listdir(p)] |
|
|||
201 | def __complete__(self): |
|
195 | def __complete__(self): | |
202 |
if self. |
|
196 | if self.path != '.': | |
203 | return self.ents |
|
197 | return self.ents | |
204 | return None |
|
198 | self.ents = [pathobj_mangle(ent) for ent in os.listdir('.')] | |
|
199 | return self.ents | |||
205 | def __getattr__(self,name): |
|
200 | def __getattr__(self,name): | |
206 | if name in self.ents: |
|
201 | if name in self.ents: | |
207 | if self.path.endswith('/'): |
|
202 | if self.path.endswith('/'): | |
@@ -214,7 +209,7 b' class PathObj:' | |||||
214 | if os.path.isdir(tgt): |
|
209 | if os.path.isdir(tgt): | |
215 | return PathObj(tgt) |
|
210 | return PathObj(tgt) | |
216 | if os.path.isfile(tgt): |
|
211 | if os.path.isfile(tgt): | |
217 |
return |
|
212 | return path(tgt) | |
218 |
|
213 | |||
219 | raise AttributeError, name # <<< DON'T FORGET THIS LINE !! |
|
214 | raise AttributeError, name # <<< DON'T FORGET THIS LINE !! | |
220 | def __str__(self): |
|
215 | def __str__(self): | |
@@ -231,7 +226,7 b' def complete_pathobj(obj, prev_completions):' | |||||
231 |
|
226 | |||
232 | if hasattr(obj,'__complete__'): |
|
227 | if hasattr(obj,'__complete__'): | |
233 | return obj.__complete__() |
|
228 | return obj.__complete__() | |
234 | raise TryNext |
|
229 | raise IPython.ipapi.TryNext | |
235 |
|
230 | |||
236 | complete_pathobj = IPython.generics.complete_object.when_type(PathObj)(complete_pathobj) |
|
231 | complete_pathobj = IPython.generics.complete_object.when_type(PathObj)(complete_pathobj) | |
237 |
|
232 | |||
@@ -241,6 +236,7 b' def test_pathobj():' | |||||
241 | #print p,p2 |
|
236 | #print p,p2 | |
242 | croot = PathObj("c:/") |
|
237 | croot = PathObj("c:/") | |
243 | startmenu = PathObj("d:/Documents and Settings/All Users/Start Menu/Programs") |
|
238 | startmenu = PathObj("d:/Documents and Settings/All Users/Start Menu/Programs") | |
244 | ip.to_user_ns("croot startmenu") |
|
239 | cwd = PathObj('.') | |
|
240 | ip.to_user_ns("croot startmenu cwd") | |||
245 |
|
241 | |||
246 | #test_pathobj() No newline at end of file |
|
242 | #test_pathobj() |
General Comments 0
You need to be logged in to leave comments.
Login now