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 from object_store_creator import ObjectStoreCreator |
| 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, |
| 18 base_path, |
| 19 fetcher): |
| 20 self._base_path = base_path |
| 21 self._fetcher = fetcher |
| 22 self._object_store = ObjectStoreCreator(ChromeVersionUtility).Create() |
| 23 |
| 24 def GetBranchNumberForVersion(self, version_number): |
| 25 '''Returns the most recent branch number for a given chrome version number |
| 26 using data stored on omahaproxy (see url_constants) |
| 27 ''' |
| 28 if version_number == 'trunk': |
| 29 return 'trunk' |
| 30 |
| 31 branch = self._object_store.Get(version_number).Get() |
| 32 |
| 33 if branch is not None: |
| 34 return branch |
| 35 |
| 36 try: |
| 37 version_json = json.loads(self._fetcher.Fetch(self._base_path).content) |
| 38 except Exception as e: |
| 39 # If omahaproxy is having problems, report it. |
| 40 logging.error('Could not fetch data at Omaha Proxy: %s' % (e)) |
| 41 return None |
| 42 |
| 43 # Here, entry['title'] looks like: 'title - version#.#.branch#.#' |
| 44 for entry in version_json['events']: |
| 45 version_title = entry['title'].split(' - ')[1].split('.') |
| 46 if version_title[0] == version_number: |
| 47 self._object_store.Set(version_number, version_title[2]) |
| 48 return version_title[2] |
| 49 return None |
| 50 |
| 51 def GetLatestVersionNumber(self): |
| 52 try: |
| 53 version_json = json.loads(self._fetcher.Fetch(self._base_path).content) |
| 54 except Exception as e: |
| 55 logging.error('Could not fetch data at Omaha Proxy: %s' % (e)) |
| 56 return None |
| 57 |
| 58 latest_version = 0 |
| 59 for entry in version_json['events']: |
| 60 version_title = entry['title'].split(' - ')[1].split('.') |
| 61 version = int(version_title[0]) |
| 62 if version > latest_version: |
| 63 latest_version = version |
| 64 return latest_version |
OLD | NEW |