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

Side by Side Diff: chrome/common/extensions/docs/server2/chrome_version_utility.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: Fixing up Offline/Online Access - Attempting to rework availability algorithm Created 7 years, 7 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) 2013 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 os
8
9 class ChromeVersionUtility(object):
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, base_path, fetcher, object_store_creator):
18 self._base_path = base_path
19 self._fetcher = fetcher
20 self._object_store = object_store_creator.Create(ChromeVersionUtility,
21 channel=None)
22
23 def GetBranchNumberForVersion(self, version):
24 '''Returns the most recent branch number for a given chrome version number
25 using data stored on omahaproxy (see url_constants)
26 '''
27 if version == 'trunk':
28 return 'trunk'
29
30 branch = self._object_store.Get(str(version)).Get()
31 if branch is not None:
32 return branch
33 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
34 for entry in version_json['events']:
35 # Here, entry['title'] looks like: 'title - version#.#.branch#.#'
36 version_title = entry['title'].split(' - ')[1].split('.')
37 if version_title[0] == str(version):
38 self._object_store.Set(str(version), version_title[2])
39 return int(version_title[2])
40 raise ValueError(
41 'A branch number for the given version could not be determined')
42
43 def GetLatestVersionNumber(self):
44 version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
45 latest_version = 0
46 for entry in version_json['events']:
47 version_title = entry['title'].split(' - ')[1].split('.')
48 version = int(version_title[0])
49 if version > latest_version:
50 latest_version = version
51 return latest_version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698