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

Side by Side Diff: chrome/common/extensions/docs/server2/local_file_system.py

Issue 14856006: Docserver: achieve online vs offline (cron vs instance) behaviour at the object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import sys
6 7
7 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode 8 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode
8 from future import Future 9 from future import Future
9 10
10 class LocalFileSystem(FileSystem): 11 class LocalFileSystem(FileSystem):
11 """FileSystem implementation which fetches resources from the local 12 '''FileSystem implementation which fetches resources from the local
12 filesystem. 13 filesystem.
13 """ 14 '''
14 def __init__(self, base_path): 15 def __init__(self, base_path=None):
16 if base_path is None:
17 # Default to the base of the extensions directory.
18 base_path = os.path.join(sys.path[0], os.pardir, os.pardir)
15 self._base_path = self._ConvertToFilepath(base_path) 19 self._base_path = self._ConvertToFilepath(base_path)
16 20
17 def _ConvertToFilepath(self, path): 21 def _ConvertToFilepath(self, path):
18 return path.replace('/', os.sep) 22 return path.replace('/', os.sep)
19 23
20 def _ReadFile(self, filename, binary): 24 def _ReadFile(self, filename, binary):
21 try: 25 try:
22 mode = 'rb' if binary else 'r' 26 mode = 'rb' if binary else 'r'
23 with open(os.path.join(self._base_path, filename), mode) as f: 27 with open(os.path.join(self._base_path, filename), mode) as f:
24 contents = f.read() 28 contents = f.read()
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 for filename in os.listdir(path)) 63 for filename in os.listdir(path))
60 else: 64 else:
61 versions = None 65 versions = None
62 try: 66 try:
63 return StatInfo(os.stat(path).st_mtime, versions) 67 return StatInfo(os.stat(path).st_mtime, versions)
64 except OSError as e: 68 except OSError as e:
65 raise FileNotFoundError('os.stat failed for %s: %s' % (path, e)) 69 raise FileNotFoundError('os.stat failed for %s: %s' % (path, e))
66 70
67 def Stat(self, path): 71 def Stat(self, path):
68 return self._CreateStatInfo(os.path.join(self._base_path, path)) 72 return self._CreateStatInfo(os.path.join(self._base_path, path))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698