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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6
7 from file_system import FileSystem
8 from lazy_value import LazyValue
9
10 class LocalFileSystem(FileSystem):
11 """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.
12 """
13 def __init__(self, base_path):
14 self._base_path = self._ConvertToFilepath(base_path)
15
16 def _ConvertToFilepath(self, path):
17 return path.replace('/', os.sep)
18
19 def _ReadFile(self, filename):
20 with open(os.path.join(self._base_path, filename), 'r') as f:
21 return f.read()
22
23 def _ListDir(self, dir_name):
24 all_files = []
25 full_path = os.path.join(self._base_path, dir_name)
26 for path in os.listdir(full_path):
27 if os.path.isdir(os.path.join(full_path, path)):
28 all_files.append(path + '/')
29 else:
30 all_files.append(path)
31 return all_files
32
33 def Read(self, paths):
34 result = {}
35 for path in paths:
36 if path.endswith('/'):
37 result[path] = LazyValue(
38 value=self._ListDir(self._ConvertToFilepath(path)))
39 else:
40 result[path] = LazyValue(
41 value=self._ReadFile(self._ConvertToFilepath(path)))
42 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698