Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4490)

Unified Diff: chrome/common/extensions/docs/server2/file_system.py

Issue 521453003: Docserver: Override Walk in CachingFileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 49535c84e7d394facddfa188b801e32683dfb894..85809a7b8e21d0478aad701530116b9cff239da7 100644
--- a/chrome/common/extensions/docs/server2/file_system.py
+++ b/chrome/common/extensions/docs/server2/file_system.py
@@ -155,7 +155,7 @@ class FileSystem(object):
'''
raise NotImplementedError(self.__class__)
- def Walk(self, root, depth=-1):
+ def Walk(self, root, depth=-1, walk_delegate=None):
'''Recursively walk the directories in a file system, starting with root.
Behaviour is very similar to os.walk from the standard os module, yielding
@@ -164,6 +164,13 @@ class FileSystem(object):
|base| respectively. If |depth| is specified and greater than 0, Walk will
only recurse |depth| times.
+ |walk_delegate|, if specified, should be a callback of signature
not at google - send to devlin 2014/08/29 19:28:31 Neat! How about a more descriptive name than |wal
+
+ def my_walk_delegate(root):,
+
+ which returns a tuple (dirs, files), where |dirs| is a list of directory
+ names under |root|, and |files| is a list of file names under |root|.
+
Note that directories will always end with a '/', files never will.
If |root| cannot be found, raises a FileNotFoundError.
@@ -176,13 +183,16 @@ class FileSystem(object):
if depth == 0:
return
AssertIsDirectory(root)
- dirs, files = [], []
- for f in self.ReadSingle(root).Get():
- if IsDirectory(f):
- dirs.append(f)
- else:
- files.append(f)
+ if walk_delegate:
+ dirs, files = walk_delegate(root)
+ else:
+ dirs, files = [], []
+ for f in self.ReadSingle(root).Get():
+ if IsDirectory(f):
+ dirs.append(f)
+ else:
+ files.append(f)
yield root[len(basepath):].rstrip('/'), dirs, files

Powered by Google App Engine
This is Rietveld 408576698