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

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

Issue 14247024: Devserver: allow SubversionFileSystem to be pinned to a specific rev on construction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 7 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
index 8a6aae41125265ccc439b95959fd9f0e5823d621..2e9667ecc3c36217cc706de11ebf50a2d6637153 100644
--- a/chrome/common/extensions/docs/server2/local_file_system.py
+++ b/chrome/common/extensions/docs/server2/local_file_system.py
@@ -12,6 +12,54 @@ from future import Future
def _ConvertToFilepath(path):
return path.replace('/', os.sep)
+def _ConvertFromFilepath(path):
+ return path.replace(os.sep, '/')
+
+def _ReadFile(filename, binary):
+ try:
+ mode = 'rb' if binary else 'r'
+ with open(filename, mode) as f:
+ contents = f.read()
+ if binary:
+ return contents
+ return ToUnicode(contents)
+ except IOError as e:
+ raise FileNotFoundError('Read failed for %s: %s' % (filename, e))
+
+def _ListDir(dir_name):
+ all_files = []
+ try:
+ files = os.listdir(dir_name)
+ except OSError as e:
+ raise FileNotFoundError('os.listdir failed for %s: %s' % (dir_name, e))
+ for os_path in files:
+ posix_path = _ConvertFromFilepath(os_path)
+ if os_path.startswith('.'):
+ continue
+ if os.path.isdir(os.path.join(dir_name, os_path)):
+ all_files.append(posix_path + '/')
+ else:
+ all_files.append(posix_path)
+ return all_files
+
+def _CreateStatInfo(path):
+ try:
+ path_mtime = os.stat(path).st_mtime
+ if path.endswith('/'):
+ child_versions = dict((_ConvertFromFilepath(filename),
+ os.stat(os.path.join(path, filename)).st_mtime)
+ for filename in os.listdir(path))
+ # This file system stat mimics subversion, where the stat of directories
+ # is max(file stats). That means we need to recursively check the whole
+ # file system tree :\ so approximate that by just checking this dir.
+ version = max([path_mtime] + child_versions.values())
+ else:
+ child_versions = None
+ version = path_mtime
+ return StatInfo(version, child_versions)
+ except OSError as e:
+ raise FileNotFoundError('os.stat failed for %s: %s' % (path, e))
+
class LocalFileSystem(FileSystem):
'''FileSystem implementation which fetches resources from the local
filesystem.
@@ -23,62 +71,21 @@ class LocalFileSystem(FileSystem):
def Create():
return LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir))
- def _ReadFile(self, filename, binary):
- try:
- mode = 'rb' if binary else 'r'
- with open(os.path.join(self._base_path, filename), mode) as f:
- contents = f.read()
- if binary:
- return contents
- return ToUnicode(contents)
- except IOError as e:
- raise FileNotFoundError('Read failed for %s: %s' % (filename, e))
-
- def _ListDir(self, dir_name):
- all_files = []
- full_path = os.path.join(self._base_path, dir_name)
- try:
- files = os.listdir(full_path)
- except OSError as e:
- raise FileNotFoundError('os.listdir failed for %s: %s' % (dir_name, e))
- for path in files:
- if path.startswith('.'):
- continue
- 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, binary=False):
result = {}
for path in paths:
+ full_path = os.path.join(self._base_path,
+ _ConvertToFilepath(path).lstrip(os.sep))
if path.endswith('/'):
- result[path] = self._ListDir(_ConvertToFilepath(path))
+ result[path] = _ListDir(full_path)
else:
- result[path] = self._ReadFile(_ConvertToFilepath(path), binary)
+ result[path] = _ReadFile(full_path, binary)
return Future(value=result)
- def _CreateStatInfo(self, path):
- try:
- path_mtime = os.stat(path).st_mtime
- if path.endswith('/'):
- child_versions = dict(
- (filename, os.stat(os.path.join(path, filename)).st_mtime)
- for filename in os.listdir(path))
- # This file system stat mimics subversion, where the stat of directories
- # is max(file stats). That means we need to recursively check the whole
- # file system tree :\ so approximate that by just checking this dir.
- version = max([path_mtime] + child_versions.values())
- else:
- child_versions = None
- version = path_mtime
- return StatInfo(version, child_versions)
- except OSError as e:
- raise FileNotFoundError('os.stat failed for %s: %s' % (path, e))
-
def Stat(self, path):
- return self._CreateStatInfo(os.path.join(self._base_path, path))
+ full_path = os.path.join(self._base_path,
+ _ConvertToFilepath(path).lstrip(os.sep))
+ return _CreateStatInfo(full_path)
def GetIdentity(self):
return '@'.join((self.__class__.__name__, StringIdentity(self._base_path)))
« no previous file with comments | « chrome/common/extensions/docs/server2/instance_servlet.py ('k') | chrome/common/extensions/docs/server2/mock_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698