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

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..7a5ac4fdbd45bdcc605ef373b4a3ddef9d9cd928 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, file_lister=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,15 @@ class FileSystem(object):
|base| respectively. If |depth| is specified and greater than 0, Walk will
only recurse |depth| times.
+ |file_lister|, if specified, should be a callback of signature
+
+ def my_file_lister(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 the listing of files and directories should be for a *single* level
+ only, i.e. it should not recursively list anything.
+
Note that directories will always end with a '/', files never will.
If |root| cannot be found, raises a FileNotFoundError.
@@ -176,13 +185,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 file_lister:
+ dirs, files = file_lister(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