| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import operator | 7 import operator |
| 8 | 8 |
| 9 from appengine_url_fetcher import AppEngineUrlFetcher | 9 from appengine_url_fetcher import AppEngineUrlFetcher |
| 10 import url_constants | 10 import url_constants |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 version_json = json.loads(self._fetch_result.Get().content) | 159 version_json = json.loads(self._fetch_result.Get().content) |
| 160 except Exception as e: | 160 except Exception as e: |
| 161 # This can happen if omahaproxy is misbehaving, which we've seen before. | 161 # This can happen if omahaproxy is misbehaving, which we've seen before. |
| 162 # Quick hack fix: just serve from trunk until it's fixed. | 162 # Quick hack fix: just serve from trunk until it's fixed. |
| 163 logging.error('Failed to fetch or parse branch from omahaproxy: %s! ' | 163 logging.error('Failed to fetch or parse branch from omahaproxy: %s! ' |
| 164 'Falling back to "trunk".' % e) | 164 'Falling back to "trunk".' % e) |
| 165 return 'trunk' | 165 return 'trunk' |
| 166 | 166 |
| 167 numbers = {} | 167 numbers = {} |
| 168 for entry in version_json: | 168 for entry in version_json: |
| 169 if entry['os'] not in ['win', 'linux', 'mac', 'cros']: | 169 if entry['os'] not in ('win', 'linux', 'mac', 'cros'): |
| 170 continue | 170 continue |
| 171 for version in entry['versions']: | 171 for version in entry['versions']: |
| 172 if version['channel'] != channel_name: | 172 if version['channel'] != channel_name: |
| 173 continue | 173 continue |
| 174 if data_type == 'branch': | 174 if data_type == 'branch': |
| 175 number = version['version'].split('.')[2] | 175 number = version['version'].split('.')[2] |
| 176 elif data_type == 'version': | 176 elif data_type == 'version': |
| 177 number = version['version'].split('.')[0] | 177 number = version['version'].split('.')[0] |
| 178 if number not in numbers: | 178 if number not in numbers: |
| 179 numbers[number] = 0 | 179 numbers[number] = 0 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 191 data stored on omahaproxy (see url_constants). | 191 data stored on omahaproxy (see url_constants). |
| 192 ''' | 192 ''' |
| 193 if version == 'trunk': | 193 if version == 'trunk': |
| 194 return 'trunk' | 194 return 'trunk' |
| 195 | 195 |
| 196 branch = self._branch_object_store.Get(str(version)).Get() | 196 branch = self._branch_object_store.Get(str(version)).Get() |
| 197 if branch is not None: | 197 if branch is not None: |
| 198 return branch | 198 return branch |
| 199 | 199 |
| 200 version_json = json.loads(self._history_result.Get().content) | 200 version_json = json.loads(self._history_result.Get().content) |
| 201 for entry in version_json['events']: | 201 for entry in version_json: |
| 202 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##' | 202 version_title = entry['version'].split('.') |
| 203 version_title = entry['title'].split(' - ')[1].split('.') | |
| 204 if version_title[0] == str(version): | 203 if version_title[0] == str(version): |
| 205 self._branch_object_store.Set(str(version), version_title[2]) | 204 self._branch_object_store.Set(str(version), version_title[2]) |
| 206 return version_title[2] | 205 return version_title[2] |
| 207 | 206 |
| 208 raise ValueError('The branch for %s could not be found.' % version) | 207 raise ValueError('The branch for %s could not be found.' % version) |
| 209 | 208 |
| 210 def GetChannelForVersion(self, version): | 209 def GetChannelForVersion(self, version): |
| 211 '''Returns the name of the development channel corresponding to a given | 210 '''Returns the name of the development channel corresponding to a given |
| 212 version number. | 211 version number. |
| 213 ''' | 212 ''' |
| 214 for channel_info in self.GetAllChannelInfo(): | 213 for channel_info in self.GetAllChannelInfo(): |
| 215 if channel_info.channel == 'stable' and version <= channel_info.version: | 214 if channel_info.channel == 'stable' and version <= channel_info.version: |
| 216 return channel_info.channel | 215 return channel_info.channel |
| 217 if version == channel_info.version: | 216 if version == channel_info.version: |
| 218 return channel_info.channel | 217 return channel_info.channel |
| 219 | 218 |
| 220 def GetLatestVersionNumber(self): | 219 def GetLatestVersionNumber(self): |
| 221 '''Returns the most recent version number found using data stored on | 220 '''Returns the most recent version number found using data stored on |
| 222 omahaproxy. | 221 omahaproxy. |
| 223 ''' | 222 ''' |
| 224 latest_version = self._version_object_store.Get('latest').Get() | 223 latest_version = self._version_object_store.Get('latest').Get() |
| 225 if latest_version is not None: | 224 if latest_version is not None: |
| 226 return latest_version | 225 return latest_version |
| 227 | 226 |
| 228 version_json = json.loads(self._history_result.Get().content) | 227 version_json = json.loads(self._history_result.Get().content) |
| 229 latest_version = 0 | 228 latest_version = 0 |
| 230 for entry in version_json['events']: | 229 for entry in version_json: |
| 231 version_title = entry['title'].split(' - ')[1].split('.') | 230 version_title = entry['version'].split('.') |
| 232 version = int(version_title[0]) | 231 version = int(version_title[0]) |
| 233 if version > latest_version: | 232 if version > latest_version: |
| 234 latest_version = version | 233 latest_version = version |
| 235 | 234 |
| 236 self._version_object_store.Set('latest', latest_version) | 235 self._version_object_store.Set('latest', latest_version) |
| 237 return latest_version | 236 return latest_version |
| OLD | NEW |