Index: chrome/common/extensions/docs/server2/file_system.py |
diff --git a/chrome/common/extensions/docs/server2/file_system.py b/chrome/common/extensions/docs/server2/file_system.py |
index 1e5b567dab59b3b1eea7229f2416ac8695fab1e2..1b49753cfb81c58aeee05e17ef70edd40752ac76 100644 |
--- a/chrome/common/extensions/docs/server2/file_system.py |
+++ b/chrome/common/extensions/docs/server2/file_system.py |
@@ -145,13 +145,14 @@ class FileSystem(object): |
''' |
raise NotImplementedError(self.__class__) |
- def Walk(self, root): |
+ def Walk(self, root, depth=-1): |
'''Recursively walk the directories in a file system, starting with root. |
Behaviour is very similar to os.walk from the standard os module, yielding |
(base, dirs, files) recursively, where |base| is the base path of |files|, |
|dirs| relative to |root|, and |files| and |dirs| the list of files/dirs in |
- |base| respectively. |
+ |base| respectively. If |depth| is specified and greater than 0, Walk will |
not at google - send to devlin
2014/08/15 15:45:50
Quick test for specifying depth=0, 1, or 2 plz.
|
+ only recurse |depth| times. |
Note that directories will always end with a '/', files never will. |
@@ -161,7 +162,9 @@ class FileSystem(object): |
AssertIsDirectory(root) |
basepath = root |
- def walk(root): |
+ def walk(root, depth): |
+ if depth == 0: |
+ return |
AssertIsDirectory(root) |
dirs, files = [], [] |
@@ -174,10 +177,10 @@ class FileSystem(object): |
yield root[len(basepath):].rstrip('/'), dirs, files |
for d in dirs: |
- for walkinfo in walk(root + d): |
+ for walkinfo in walk(root + d, depth - 1): |
yield walkinfo |
- for walkinfo in walk(root): |
+ for walkinfo in walk(root, depth): |
yield walkinfo |
def __eq__(self, other): |