from docs_server_utils import StringIdentity
from file_system import FileSystem, FileNotFoundError, StatInfo
from future import Gettable, Future
+from path_util import AssertIsDirectory, AssertIsValid
+from test_util import ChromiumPath
+
def _ConvertToFilepath(path):
return path.replace('/', os.sep)
+
def _ConvertFromFilepath(path):
return path.replace(os.sep, '/')
+
def _ReadFile(filename):
try:
with open(filename, 'rb') as f:
except IOError as e:
raise FileNotFoundError('Read failed for %s: %s' % (filename, e))
+
def _ListDir(dir_name):
all_files = []
try:
all_files.append(posix_path)
return all_files
+
def _CreateStatInfo(path):
try:
path_mtime = os.stat(path).st_mtime
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.
'''
def __init__(self, base_path):
+ AssertIsDirectory(base_path)
self._base_path = _ConvertToFilepath(base_path)
@staticmethod
- def Create(root=''):
- return LocalFileSystem(
- os.path.join(sys.path[0], '..', '..', '..', '..', '..', root))
+ def Create(*path):
+ return LocalFileSystem(ChromiumPath(*path))
def Read(self, paths):
def resolve():
result = {}
for path in paths:
+ AssertIsValid(path)
full_path = os.path.join(self._base_path,
_ConvertToFilepath(path).lstrip(os.sep))
if path == '' or path.endswith('/'):
return Future(value=())
def Stat(self, path):
+ AssertIsValid(path)
full_path = os.path.join(self._base_path,
_ConvertToFilepath(path).lstrip(os.sep))
return _CreateStatInfo(full_path)