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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests Created 8 years, 5 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/local_file_system.py
diff --git a/chrome/common/extensions/docs/server2/local_file_system.py b/chrome/common/extensions/docs/server2/local_file_system.py
new file mode 100644
index 0000000000000000000000000000000000000000..cc5ddad6398b20b6695d6e19af0b3aeeda01e081
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/local_file_system.py
@@ -0,0 +1,42 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+
+from file_system import FileSystem
+from lazy_value import LazyValue
+
+class LocalFileSystem(FileSystem):
+ """Class to fetch resources from local filesystem.
not at google - send to devlin 2012/07/18 10:39:15 FileSystem implementation which fetches resources
cduvall 2012/07/18 21:26:10 Done.
+ """
+ def __init__(self, base_path):
+ self._base_path = self._ConvertToFilepath(base_path)
+
+ def _ConvertToFilepath(self, path):
+ return path.replace('/', os.sep)
+
+ def _ReadFile(self, filename):
+ with open(os.path.join(self._base_path, filename), 'r') as f:
+ return f.read()
+
+ def _ListDir(self, dir_name):
+ all_files = []
+ full_path = os.path.join(self._base_path, dir_name)
+ for path in os.listdir(full_path):
+ if os.path.isdir(os.path.join(full_path, path)):
+ all_files.append(path + '/')
+ else:
+ all_files.append(path)
+ return all_files
+
+ def Read(self, paths):
+ result = {}
+ for path in paths:
+ if path.endswith('/'):
+ result[path] = LazyValue(
+ value=self._ListDir(self._ConvertToFilepath(path)))
+ else:
+ result[path] = LazyValue(
+ value=self._ReadFile(self._ConvertToFilepath(path)))
+ return result

Powered by Google App Engine
This is Rietveld 408576698