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