Chromium Code Reviews| 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 |