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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import json
6 import logging
7 import object_store
8
9 class ChromeVersionDataSource:
10 def __init__(self, base_path, fetcher, object_store, CreateMemcacheForBranch):
11 self._base_path = base_path
12 self._fetcher = fetcher
13 self._object_store = object_store
14 self._CreateMemcacheForBranch = CreateMemcacheForBranch
cduvall 2013/03/25 22:59:43 Name unix_hacker_style
epeterson 2013/03/27 22:36:09 Done.
15
16 def _GetBranchNumberForVersion(self, version_number):
17 """Returns the most recent branch number for a given chrome version number
18 using data stored on omahaproxy (see url_constants)
19 """
20 branch = self._object_store.Get(
21 version_number,
22 object_store.CHROME_VERSION_DATA_SOURCE).Get()
23
24 if branch is not None:
25 return branch
26
27 try:
28 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
29 except Exception as e:
30 # if omahaproxy is having problems
31 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.
32 return None
33
34 # entry['title'] looks like: 'title - version#.#.branch#.#'
35 for entry in version_json['events']:
36 version_title = entry['title'].split(' - ')[1].split('.')
37 if version_title[0] == version_number:
38 self._object_store.Set(version_number,
39 version_title[2],
40 object_store.CHROME_VERSION_DATA_SOURCE)
41 return version_title[2]
42
43 def GetDataSourceForVersion(self, version_number):
44 """Returns an api data source for the most recent branch number
45 corresponding to a given version number
46 """
47 branch_number = self._GetBranchNumberForVersion(version_number)
48 branch_api_data_source = self._CreateMemcacheForBranch(branch_number)
49 return branch_api_data_source
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698