visit() now returns paths in depth-first order. fixes issue #47
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									e3b34c9da3
								
							
						
					
					
						commit
						6ddea4a1bc
					
				|  | @ -278,20 +278,20 @@ newline will be removed from the end of each line. """ | ||||||
|         if rec:  |         if rec:  | ||||||
|             if isinstance(rec, str): |             if isinstance(rec, str): | ||||||
|                 rec = fnmatch(fil) |                 rec = fnmatch(fil) | ||||||
|             elif not py.builtin.callable(rec):  |             elif not hasattr(rec, '__call__'): | ||||||
|                 rec = lambda x: True  |                 rec = None | ||||||
|         reclist = [self] |         try: | ||||||
|         while reclist:  |             entries = self.listdir() | ||||||
|             current = reclist.pop(0) |         except ignore: | ||||||
|             try: |             return | ||||||
|                 dirlist = current.listdir()  |         dirs = [p for p in entries  | ||||||
|             except ignore: |                     if p.check(dir=1) and (rec is None or rec(p))] | ||||||
|                 return |         for subdir in dirs: | ||||||
|             for p in dirlist: |             for p in subdir.visit(fil=fil, rec=rec, ignore=ignore): | ||||||
|                 if fil is None or fil(p): |                 yield p | ||||||
|                     yield p |         for p in entries: | ||||||
|                 if p.check(dir=1) and (rec is None or rec(p)): |             if fil is None or fil(p): | ||||||
|                     reclist.append(p) |                 yield p | ||||||
| 
 | 
 | ||||||
|     def _sortlist(self, res, sort): |     def _sortlist(self, res, sort): | ||||||
|         if sort: |         if sort: | ||||||
|  |  | ||||||
|  | @ -334,12 +334,12 @@ class LocalPath(FSBase): | ||||||
|             assert self!=target |             assert self!=target | ||||||
|             copychunked(self, target) |             copychunked(self, target) | ||||||
|         else: |         else: | ||||||
|             target.ensure(dir=1) |  | ||||||
|             def rec(p): |             def rec(p): | ||||||
|                 return p.check(link=0) |                 return p.check(link=0) | ||||||
|             for x in self.visit(rec=rec): |             for x in self.visit(rec=rec): | ||||||
|                 relpath = x.relto(self) |                 relpath = x.relto(self) | ||||||
|                 newx = target.join(relpath) |                 newx = target.join(relpath) | ||||||
|  |                 newx.dirpath().ensure(dir=1) | ||||||
|                 if x.check(link=1): |                 if x.check(link=1): | ||||||
|                     newx.mksymlinkto(x.readlink()) |                     newx.mksymlinkto(x.readlink()) | ||||||
|                 elif x.check(file=1): |                 elif x.check(file=1): | ||||||
|  |  | ||||||
|  | @ -198,6 +198,15 @@ class TestLocalPath(common.CommonFSTests): | ||||||
|         l2 = tmpdir.join(newfilename) |         l2 = tmpdir.join(newfilename) | ||||||
|         assert l2.read() == 'foo' |         assert l2.read() == 'foo' | ||||||
| 
 | 
 | ||||||
|  |     def test_visit_depth_first(self, tmpdir): | ||||||
|  |         p1 = tmpdir.ensure("a","1") | ||||||
|  |         p2 = tmpdir.ensure("b","2") | ||||||
|  |         p3 = tmpdir.ensure("breadth") | ||||||
|  |         l = list(tmpdir.visit(lambda x: x.check(file=1))) | ||||||
|  |         assert l[0] == p1 | ||||||
|  |         assert l[1] == p2  | ||||||
|  |         assert l[2] == p3 | ||||||
|  | 
 | ||||||
| class TestExecutionOnWindows: | class TestExecutionOnWindows: | ||||||
|     disabled = py.std.sys.platform != 'win32' |     disabled = py.std.sys.platform != 'win32' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue