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

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: 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):
11 self._base_path = base_path
12 self._fetcher = fetcher
13 self._object_store = object_store
14
15 def _GetBranchNumberForVersion(self, version_number):
16 """Returns the most recent branch number for a given chrome version number
17 using data stored on omahaproxy (see url_constants)
18 """
19 branch = self._object_store.Get(
20 version_number,
21 object_store.CHROME_VERSION_DATA_SOURCE).Get()
22
23 if branch is not None:
24 return branch
25
26 try:
27 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
28 except Exception as e:
29 #if omahaproxy is having problems
30 logging.error("Could not fetch data at Omaha Proxy.\n%s" % (e))
cduvall 2013/03/21 18:43:53 better return None here
epeterson 2013/03/25 19:35:11 Done? Is there a better way to handle this case so
31
32 # entry['title'] looks like: 'title - version#.#.branch#.#'
33 for entry in version_json['events']:
34 version_title = entry['title'].split(' - ')[1].split('.')
35 if version_title[0] == version_number:
36 self._object_store.Set(version_number,
37 version_title[2],
38 object_store.CHROME_VERSION_DATA_SOURCE)
39 return version_title[2]
40
41 def GetDataSourceForVersion(self, version_number):
42 """Returns an api data source for the most recent branch number
43 corresponding to a given version number
44 """
45 branch_number = self._GetBranchNumberForVersion(version_number)
46 branch_api_data_source = self._CreateMemcacheForBranch(branch_number)
47 return branch_api_data_source
48
49 def SetCreateMemcacheForBranch(self, create_memcache_for_branch):
50 """Sets a function, initially created in handler, that returns a memcache
51 tied to a specific branch number
52 """
53 self._CreateMemcacheForBranch = create_memcache_for_branch
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698