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

Unified 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: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/compiled_file_system.py
diff --git a/chrome/common/extensions/docs/server2/compiled_file_system.py b/chrome/common/extensions/docs/server2/compiled_file_system.py
index 6c547ba2a2b9a9efc9f9faffc0692872f80b023a..58d161ad757da1ee83cefb2b8080867acc6b1a08 100644
--- a/chrome/common/extensions/docs/server2/compiled_file_system.py
+++ b/chrome/common/extensions/docs/server2/compiled_file_system.py
@@ -5,6 +5,7 @@
import os
import object_store
+import logging
APPS = 'Apps'
APPS_FS = 'AppsFileSystem'
@@ -27,7 +28,7 @@ PERMS = 'Perms'
SIDENAV = 'Sidenav'
STATIC = 'Static'
ZIP = 'Zip'
-
+DEFAULT_BRANCH = '000'
cduvall 2013/03/21 18:43:53 Separate this from the namespace constants.
epeterson 2013/03/25 19:35:11 Done.
class _CacheEntry(object):
def __init__(self, cache_data, version):
self._cache_data = cache_data
@@ -39,19 +40,22 @@ class CompiledFileSystem(object):
class Factory(object):
"""A class to build a CompiledFileSystem.
"""
- def __init__(self, file_system, object_store):
+ def __init__(self, file_system, object_store, branch_number=DEFAULT_BRANCH):
self._file_system = file_system
self._object_store = object_store
+ self._branch_number = branch_number
def Create(self, populate_function, namespace, version=None):
"""Create a CompiledFileSystem that populates the cache by calling
|populate_function| with (path, data), where |data| is the data that was
fetched from |path|. The keys to the cache are put in the namespace
- specified by |namespace|, and optionally adding |version|. """
+ specified by |namespace|, and optionally adding |version|.
+ """
return CompiledFileSystem(self._file_system,
populate_function,
self._object_store,
namespace,
+ self._branch_number,
version=version)
def __init__(self,
@@ -59,13 +63,17 @@ class CompiledFileSystem(object):
populate_function,
object_store,
namespace,
+ branch_number,
version=None):
self._file_system = file_system
self._populate_function = populate_function
self._object_store = object_store
self._namespace = 'CompiledFileSystem.' + namespace
+ self._branch_number = branch_number
cduvall 2013/03/21 18:43:53 Doesn't the file system already have a branch numb
epeterson 2013/03/25 19:35:11 Done.
if version is not None:
- self._namespace = '%s.%s' % (self._namespace, version)
+ self._namespace = '%s.%s.%s' % (self._namespace,
+ version,
+ self._branch_number)
def _MakeKey(self, key):
return self._namespace + '.' + key
@@ -93,14 +101,18 @@ class CompiledFileSystem(object):
time=0).Get()
if (cache_entry is not None) and (version == cache_entry.version):
return cache_entry._cache_data
- cache_data = self._populate_function(
- path,
- self._file_system.ReadSingle(path, binary=binary))
- self._object_store.Set(self._MakeKey(path),
- _CacheEntry(cache_data, version),
- object_store.FILE_SYSTEM_CACHE,
- time=0)
- return cache_data
+ try:
+ cache_data = self._populate_function(
+ path,
+ self._file_system.ReadSingle(path, binary=binary))
+ self._object_store.Set(self._MakeKey(path),
+ _CacheEntry(cache_data, version),
+ object_store.FILE_SYSTEM_CACHE,
+ time=0)
+ return cache_data
+ except ValueError as e:
+ return {}
+ logging.error("%s" % e)
cduvall 2013/03/21 18:43:53 Give a better message than this. And single quotes
epeterson 2013/03/25 19:35:11 Done? Does this work for you?
def GetFromFileListing(self, path):
"""Calls |populate_function| on the listing of the files at |path|.

Powered by Google App Engine
This is Rietveld 408576698