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

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

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving logic into availability_data_source Created 7 years, 8 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
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 logging
6
5 class _CacheEntry(object): 7 class _CacheEntry(object):
6 def __init__(self, cache_data, version): 8 def __init__(self, cache_data, version):
7 self._cache_data = cache_data 9 self._cache_data = cache_data
8 self.version = version 10 self.version = version
9 11
10 class CompiledFileSystem(object): 12 class CompiledFileSystem(object):
11 """This class caches FileSystem data that has been processed. 13 """This class caches FileSystem data that has been processed.
12 """ 14 """
13 class Factory(object): 15 class Factory(object):
14 """A class to build a CompiledFileSystem backed by |file_system|. 16 """A class to build a CompiledFileSystem backed by |file_system|.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 def GetFromFile(self, path, binary=False): 87 def GetFromFile(self, path, binary=False):
86 """Calls |populate_function| on the contents of the file at |path|. If 88 """Calls |populate_function| on the contents of the file at |path|. If
87 |binary| is True then the file will be read as binary - but this will only 89 |binary| is True then the file will be read as binary - but this will only
88 apply for the first time the file is fetched; if already cached, |binary| 90 apply for the first time the file is fetched; if already cached, |binary|
89 will be ignored. 91 will be ignored.
90 """ 92 """
91 version = self._file_system.Stat(path).version 93 version = self._file_system.Stat(path).version
92 cache_entry = self._file_object_store.Get(path, time=0).Get() 94 cache_entry = self._file_object_store.Get(path, time=0).Get()
93 if (cache_entry is not None) and (version == cache_entry.version): 95 if (cache_entry is not None) and (version == cache_entry.version):
94 return cache_entry._cache_data 96 return cache_entry._cache_data
95 cache_data = self._populate_function( 97 try:
96 path, 98 cache_data = self._populate_function(
97 self._file_system.ReadSingle(path, binary=binary)) 99 path,
98 self._file_object_store.Set(path, _CacheEntry(cache_data, version), time=0) 100 self._file_system.ReadSingle(path, binary=binary))
99 return cache_data 101 self._file_object_store.Set(path,
102 _CacheEntry(cache_data, version),
103 time=0)
104 return cache_data
105 except ValueError as e:
106 logging.error('Could not get data for the file at %s: %s' % (path, e))
107 return None
100 108
101 def GetFromFileListing(self, path): 109 def GetFromFileListing(self, path):
102 """Calls |populate_function| on the listing of the files at |path|. 110 """Calls |populate_function| on the listing of the files at |path|.
103 Assumes that the path given is to a directory. 111 Assumes that the path given is to a directory.
104 """ 112 """
105 if not path.endswith('/'): 113 if not path.endswith('/'):
106 path += '/' 114 path += '/'
107 version = self._file_system.Stat(path).version 115 version = self._file_system.Stat(path).version
108 cache_entry = self._list_object_store.Get(path, time=0).Get() 116 cache_entry = self._list_object_store.Get(path, time=0).Get()
109 if (cache_entry is not None) and (version == cache_entry.version): 117 if (cache_entry is not None) and (version == cache_entry.version):
110 return cache_entry._cache_data 118 return cache_entry._cache_data
111 cache_data = self._populate_function(path, self._RecursiveList(path)) 119 cache_data = self._populate_function(path, self._RecursiveList(path))
112 self._list_object_store.Set(path, _CacheEntry(cache_data, version), time=0) 120 self._list_object_store.Set(path, _CacheEntry(cache_data, version), time=0)
113 return cache_data 121 return cache_data
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698