| 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 sys | 5 import sys |
| 6 | 6 |
| 7 import schema_util | 7 import schema_util |
| 8 from docs_server_utils import ToUnicode | 8 from docs_server_utils import ToUnicode |
| 9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
| 10 from future import Gettable, Future | 10 from future import Gettable, Future |
| 11 from path_util import ToDirectory |
| 11 from third_party.handlebar import Handlebar | 12 from third_party.handlebar import Handlebar |
| 12 from third_party.json_schema_compiler import json_parse | 13 from third_party.json_schema_compiler import json_parse |
| 13 from third_party.json_schema_compiler.memoize import memoize | 14 from third_party.json_schema_compiler.memoize import memoize |
| 14 | 15 |
| 15 | 16 |
| 16 _SINGLE_FILE_FUNCTIONS = set() | 17 _SINGLE_FILE_FUNCTIONS = set() |
| 17 | 18 |
| 18 | 19 |
| 19 def SingleFile(fn): | 20 def SingleFile(fn): |
| 20 '''A decorator which can be optionally applied to the compilation function | 21 '''A decorator which can be optionally applied to the compilation function |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 def resolve(): | 219 def resolve(): |
| 219 cache_data = self._compilation_function(path, future_files.Get()) | 220 cache_data = self._compilation_function(path, future_files.Get()) |
| 220 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) | 221 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) |
| 221 return cache_data | 222 return cache_data |
| 222 return Future(delegate=Gettable(resolve)) | 223 return Future(delegate=Gettable(resolve)) |
| 223 | 224 |
| 224 def GetFromFileListing(self, path): | 225 def GetFromFileListing(self, path): |
| 225 '''Calls |compilation_function| on the listing of the files at |path|. | 226 '''Calls |compilation_function| on the listing of the files at |path|. |
| 226 Assumes that the path given is to a directory. | 227 Assumes that the path given is to a directory. |
| 227 ''' | 228 ''' |
| 228 if not path.endswith('/'): | 229 # TODO(kalman): assert IsDirectory(path) |
| 229 path += '/' | 230 path = ToDirectory(path) |
| 230 | 231 |
| 231 try: | 232 try: |
| 232 version = self._file_system.Stat(path).version | 233 version = self._file_system.Stat(path).version |
| 233 except FileNotFoundError: | 234 except FileNotFoundError: |
| 234 return Future(exc_info=sys.exc_info()) | 235 return Future(exc_info=sys.exc_info()) |
| 235 | 236 |
| 236 cache_entry = self._list_object_store.Get(path).Get() | 237 cache_entry = self._list_object_store.Get(path).Get() |
| 237 if (cache_entry is not None) and (version == cache_entry.version): | 238 if (cache_entry is not None) and (version == cache_entry.version): |
| 238 return Future(value=cache_entry._cache_data) | 239 return Future(value=cache_entry._cache_data) |
| 239 | 240 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 250 return cache_entry.version | 251 return cache_entry.version |
| 251 return self._file_system.Stat(path).version | 252 return self._file_system.Stat(path).version |
| 252 | 253 |
| 253 def GetFileListingVersion(self, path): | 254 def GetFileListingVersion(self, path): |
| 254 if not path.endswith('/'): | 255 if not path.endswith('/'): |
| 255 path += '/' | 256 path += '/' |
| 256 cache_entry = self._list_object_store.Get(path).Get() | 257 cache_entry = self._list_object_store.Get(path).Get() |
| 257 if cache_entry is not None: | 258 if cache_entry is not None: |
| 258 return cache_entry.version | 259 return cache_entry.version |
| 259 return self._file_system.Stat(path).version | 260 return self._file_system.Stat(path).version |
| OLD | NEW |