OLD | NEW |
---|---|
(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): | |
not at google - send to devlin
2013/05/13 21:26:41
This is so similar to BranchUtility, and BranchUti
| |
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_number): | |
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_number == 'trunk': | |
28 return 'trunk' | |
29 | |
30 branch = self._object_store.Get(version_number).Get() | |
31 if branch is not None: | |
32 return branch | |
33 try: | |
34 version_json = json.loads(self._fetcher.Fetch(self._base_path).content) | |
35 except Exception as e: | |
36 # If omahaproxy is having problems, report it. | |
37 #version_json = self._GetFakeData() | |
38 logging.error('Could not fetch data at Omaha Proxy: %s' % (e)) | |
39 return None | |
not at google - send to devlin
2013/05/13 21:26:41
let's just let this exception fall all the way thr
epeterson
2013/05/15 07:38:34
Done.
| |
40 | |
41 # Here, entry['title'] looks like: 'title - version#.#.branch#.#' | |
42 for entry in version_json['events']: | |
43 version_title = entry['title'].split(' - ')[1].split('.') | |
44 if version_title[0] == version_number: | |
45 self._object_store.Set(version_number, version_title[2]) | |
46 return version_title[2] | |
47 return None | |
not at google - send to devlin
2013/05/13 21:26:41
throw a ValueError or something
epeterson
2013/05/15 07:38:34
Done.
| |
48 | |
49 def GetLatestVersionNumber(self): | |
not at google - send to devlin
2013/05/13 21:26:41
need to object-storify this or it won't work offli
| |
50 try: | |
51 version_json = json.loads(self._fetcher.Fetch(self._base_path).content) | |
not at google - send to devlin
2013/05/13 21:26:41
might want to lazily populate the version json bea
| |
52 except Exception as e: | |
53 #version_json = self._GetFakeData() | |
54 logging.error('Could not fetch latest version at Omaha Proxy: %s' % (e)) | |
55 return None | |
not at google - send to devlin
2013/05/13 21:26:41
ditto fall through
epeterson
2013/05/15 07:38:34
Done.
| |
56 | |
57 latest_version = 0 | |
58 for entry in version_json['events']: | |
59 version_title = entry['title'].split(' - ')[1].split('.') | |
60 version = int(version_title[0]) | |
61 if version > latest_version: | |
62 latest_version = version | |
63 return latest_version | |
64 | |
65 def _GetFakeData(self): | |
66 with open(os.path.join('test_data', | |
67 'chrome_version_utility', | |
68 'omaha_dev_win_history.json')) as f: | |
69 return json.load(f) | |
not at google - send to devlin
2013/05/13 21:26:41
delete _GetFakeData and the places where it's comm
epeterson
2013/05/15 07:38:34
Done.
| |
OLD | NEW |