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

Unified Diff: chrome/common/extensions/docs/server2/chrome_version_data_source.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: First round of changes 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/chrome_version_data_source.py
diff --git a/chrome/common/extensions/docs/server2/chrome_version_data_source.py b/chrome/common/extensions/docs/server2/chrome_version_data_source.py
new file mode 100644
index 0000000000000000000000000000000000000000..7dce9d14530fd81b23bb831062d428961823e517
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/chrome_version_data_source.py
@@ -0,0 +1,49 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import logging
+import object_store
+
+class ChromeVersionDataSource:
+ def __init__(self, base_path, fetcher, object_store, CreateMemcacheForBranch):
+ self._base_path = base_path
+ self._fetcher = fetcher
+ self._object_store = object_store
+ self._CreateMemcacheForBranch = CreateMemcacheForBranch
cduvall 2013/03/25 22:59:43 Name unix_hacker_style
epeterson 2013/03/27 22:36:09 Done.
+
+ def _GetBranchNumberForVersion(self, version_number):
+ """Returns the most recent branch number for a given chrome version number
+ using data stored on omahaproxy (see url_constants)
+ """
+ branch = self._object_store.Get(
+ version_number,
+ object_store.CHROME_VERSION_DATA_SOURCE).Get()
+
+ if branch is not None:
+ return branch
+
+ try:
+ version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
+ except Exception as e:
+ # if omahaproxy is having problems
+ logging.error("Could not fetch data at Omaha Proxy.\n%s" % (e))
cduvall 2013/03/25 22:59:43 do '...Proxy: %s' also, single quotes
epeterson 2013/03/27 22:36:09 Done.
+ return None
+
+ # entry['title'] looks like: 'title - version#.#.branch#.#'
+ for entry in version_json['events']:
+ version_title = entry['title'].split(' - ')[1].split('.')
+ if version_title[0] == version_number:
+ self._object_store.Set(version_number,
+ version_title[2],
+ object_store.CHROME_VERSION_DATA_SOURCE)
+ return version_title[2]
+
+ def GetDataSourceForVersion(self, version_number):
+ """Returns an api data source for the most recent branch number
+ corresponding to a given version number
+ """
+ branch_number = self._GetBranchNumberForVersion(version_number)
+ branch_api_data_source = self._CreateMemcacheForBranch(branch_number)
+ return branch_api_data_source

Powered by Google App Engine
This is Rietveld 408576698