| OLD | NEW |
| 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 import sys |
| 7 | 7 |
| 8 from docs_server_utils import StringIdentity | 8 from docs_server_utils import StringIdentity |
| 9 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode | 9 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode |
| 10 from future import Future | 10 from future import Future |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 class LocalFileSystem(FileSystem): | 63 class LocalFileSystem(FileSystem): |
| 64 '''FileSystem implementation which fetches resources from the local | 64 '''FileSystem implementation which fetches resources from the local |
| 65 filesystem. | 65 filesystem. |
| 66 ''' | 66 ''' |
| 67 def __init__(self, base_path): | 67 def __init__(self, base_path): |
| 68 self._base_path = _ConvertToFilepath(base_path) | 68 self._base_path = _ConvertToFilepath(base_path) |
| 69 | 69 |
| 70 @staticmethod | 70 @staticmethod |
| 71 def Create(): | 71 def Create(): |
| 72 return LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir)) | 72 return LocalFileSystem( |
| 73 os.path.join(sys.path[0], '..', '..', '..', '..', '..')) |
| 73 | 74 |
| 74 def Read(self, paths, binary=False): | 75 def Read(self, paths, binary=False): |
| 75 result = {} | 76 result = {} |
| 76 for path in paths: | 77 for path in paths: |
| 77 full_path = os.path.join(self._base_path, | 78 full_path = os.path.join(self._base_path, |
| 78 _ConvertToFilepath(path).lstrip(os.sep)) | 79 _ConvertToFilepath(path).lstrip(os.sep)) |
| 79 if path.endswith('/'): | 80 if path.endswith('/'): |
| 80 result[path] = _ListDir(full_path) | 81 result[path] = _ListDir(full_path) |
| 81 else: | 82 else: |
| 82 result[path] = _ReadFile(full_path, binary) | 83 result[path] = _ReadFile(full_path, binary) |
| 83 return Future(value=result) | 84 return Future(value=result) |
| 84 | 85 |
| 85 def Refresh(self): | 86 def Refresh(self): |
| 86 return Future(value=()) | 87 return Future(value=()) |
| 87 | 88 |
| 88 def Stat(self, path): | 89 def Stat(self, path): |
| 89 full_path = os.path.join(self._base_path, | 90 full_path = os.path.join(self._base_path, |
| 90 _ConvertToFilepath(path).lstrip(os.sep)) | 91 _ConvertToFilepath(path).lstrip(os.sep)) |
| 91 return _CreateStatInfo(full_path) | 92 return _CreateStatInfo(full_path) |
| 92 | 93 |
| 93 def GetIdentity(self): | 94 def GetIdentity(self): |
| 94 return '@'.join((self.__class__.__name__, StringIdentity(self._base_path))) | 95 return '@'.join((self.__class__.__name__, StringIdentity(self._base_path))) |
| OLD | NEW |