Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/chrome_version_utility.py |
| diff --git a/chrome/common/extensions/docs/server2/chrome_version_utility.py b/chrome/common/extensions/docs/server2/chrome_version_utility.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9db12b0966089e48e22df761b2a06505cf86ee69 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/chrome_version_utility.py |
| @@ -0,0 +1,69 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import logging |
| +import os |
| + |
| +class ChromeVersionUtility(object): |
|
not at google - send to devlin
2013/05/13 21:26:41
This is so similar to BranchUtility, and BranchUti
|
| + '''Generates and stores API data sources corresponding to the latest branch |
| + number for a given version of Chrome. |
| + |
| + Accesses data found on omahaproxy in order to link branch numbers to version |
| + numbers. |
| + ''' |
| + |
| + def __init__(self, base_path, fetcher, object_store_creator): |
| + self._base_path = base_path |
| + self._fetcher = fetcher |
| + self._object_store = object_store_creator.Create(ChromeVersionUtility, |
| + channel=None) |
| + |
| + def GetBranchNumberForVersion(self, version_number): |
| + '''Returns the most recent branch number for a given chrome version number |
| + using data stored on omahaproxy (see url_constants) |
| + ''' |
| + if version_number == 'trunk': |
| + return 'trunk' |
| + |
| + branch = self._object_store.Get(version_number).Get() |
| + if branch is not None: |
| + return branch |
| + try: |
| + version_json = json.loads(self._fetcher.Fetch(self._base_path).content) |
| + except Exception as e: |
| + # If omahaproxy is having problems, report it. |
| + #version_json = self._GetFakeData() |
| + logging.error('Could not fetch data at Omaha Proxy: %s' % (e)) |
| + 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.
|
| + |
| + # Here, entry['title'] looks like: 'title - version#.#.branch#.#' |
| + for entry in version_json['events']: |
| + version_title = entry['title'].split(' - ')[1].split('.') |
| + if version_title[0] == version_number: |
| + self._object_store.Set(version_number, version_title[2]) |
| + return version_title[2] |
| + 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.
|
| + |
| + 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
|
| + try: |
| + 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
|
| + except Exception as e: |
| + #version_json = self._GetFakeData() |
| + logging.error('Could not fetch latest version at Omaha Proxy: %s' % (e)) |
| + 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.
|
| + |
| + latest_version = 0 |
| + for entry in version_json['events']: |
| + version_title = entry['title'].split(' - ')[1].split('.') |
| + version = int(version_title[0]) |
| + if version > latest_version: |
| + latest_version = version |
| + return latest_version |
| + |
| + def _GetFakeData(self): |
| + with open(os.path.join('test_data', |
| + 'chrome_version_utility', |
| + 'omaha_dev_win_history.json')) as f: |
| + 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.
|