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

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: Updating .idl and .json APIs, HTML intro tables, python files 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
(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
cduvall 2013/03/27 23:01:10 nit: newline between logging and object_store
epeterson 2013/03/28 00:53:51 Done.
7 import object_store
8
9 class ChromeVersionDataSource:
10 """Generates and stores API data sources corresponding to the latest branch
11 number for a given version of Chrome.
12
13 Accesses data found on omahaproxy in order to link branch numbers to version
14 numbers.
15 """
16
17 def __init__(self,
18 base_path,
19 fetcher,
20 object_store,
21 create_objects_for_branch):
22 self._base_path = base_path
23 self._fetcher = fetcher
24 self._object_store = object_store
25 self._create_objects_for_branch = create_objects_for_branch
26
27 def _GetBranchNumberForVersion(self, version_number):
28 """Returns the most recent branch number for a given chrome version number
29 using data stored on omahaproxy (see url_constants)
30 """
31 if version_number == 'trunk':
32 return 'trunk'
33
34 branch = self._object_store.Get(
35 version_number,
36 object_store.CHROME_VERSION_DATA_SOURCE).Get()
37
38 if branch is not None:
39 return branch
40
41 try:
42 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
43 except Exception as e:
44 # If omahaproxy is having problems, report it.
45 logging.error('Could not fetch data at Omaha Proxy: %s' % (e))
46 return None
47
48 # Here, entry['title'] looks like: 'title - version#.#.branch#.#'
49 for entry in version_json['events']:
50 version_title = entry['title'].split(' - ')[1].split('.')
51 if version_title[0] == version_number:
52 self._object_store.Set(version_number,
53 version_title[2],
54 object_store.CHROME_VERSION_DATA_SOURCE)
55 return version_title[2]
56 return None
57
58 def GetLatestVersionNumber(self):
59 try:
60 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
61 except Exception as e:
62 logging.error('Could not fetch data at Omaha Proxy: %s' % (e))
63 return None
64
65 latest_version = 0
66 for entry in version_json['events']:
cduvall 2013/03/27 23:01:10 why 'events' here?
epeterson 2013/03/28 00:53:51 events is the JSON key for a list of all the separ
67 version_title = entry['title'].split(' - ')[1].split('.')
68 version = int(version_title[0])
69 if version > latest_version:
70 latest_version = version
71 return latest_version
72
73 def GetDataSourceForVersion(self, version_number):
74 """Returns an api data source for the most recent branch number
75 corresponding to a given version number
76 """
77 branch_number = self._GetBranchNumberForVersion(version_number)
78 branch_api_data_source = self._create_objects_for_branch(branch_number)
79 return branch_api_data_source
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698