| 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 environment_wrappers import CreateUrlFetcher | 9 from environment_wrappers import CreateUrlFetcher |
| 10 import url_constants | 10 import url_constants |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if channel_info.version < stable_info.version: | 85 if channel_info.version < stable_info.version: |
| 86 return self.GetStableChannelInfo(channel_info.version + 1) | 86 return self.GetStableChannelInfo(channel_info.version + 1) |
| 87 names = self.GetAllChannelNames() | 87 names = self.GetAllChannelNames() |
| 88 return self.GetAllChannelInfo()[names.index(channel_info.channel) + 1] | 88 return self.GetAllChannelInfo()[names.index(channel_info.channel) + 1] |
| 89 | 89 |
| 90 def Older(self, channel_info): | 90 def Older(self, channel_info): |
| 91 '''Given a ChannelInfo object, returns a new ChannelInfo object | 91 '''Given a ChannelInfo object, returns a new ChannelInfo object |
| 92 representing the previous Chrome version/branch combination. | 92 representing the previous Chrome version/branch combination. |
| 93 ''' | 93 ''' |
| 94 if channel_info.channel == 'stable': | 94 if channel_info.channel == 'stable': |
| 95 if channel_info.version <= 5: | |
| 96 # BranchUtility can't access branch data from before Chrome version 5. | |
| 97 return None | |
| 98 return self.GetStableChannelInfo(channel_info.version - 1) | 95 return self.GetStableChannelInfo(channel_info.version - 1) |
| 99 names = self.GetAllChannelNames() | 96 names = self.GetAllChannelNames() |
| 100 return self.GetAllChannelInfo()[names.index(channel_info.channel) - 1] | 97 return self.GetAllChannelInfo()[names.index(channel_info.channel) - 1] |
| 101 | 98 |
| 102 @staticmethod | 99 @staticmethod |
| 103 def SplitChannelNameFromPath(path): | 100 def SplitChannelNameFromPath(path): |
| 104 '''Splits the channel name out of |path|, returning the tuple | 101 '''Splits the channel name out of |path|, returning the tuple |
| 105 (channel_name, real_path). If the channel cannot be determined then returns | 102 (channel_name, real_path). If the channel cannot be determined then returns |
| 106 (None, path). | 103 (None, path). |
| 107 ''' | 104 ''' |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 if version != 'master': | 128 if version != 'master': |
| 132 version = int(version) | 129 version = int(version) |
| 133 return ChannelInfo(channel, | 130 return ChannelInfo(channel, |
| 134 self._ExtractFromVersionJson(channel, 'branch'), | 131 self._ExtractFromVersionJson(channel, 'branch'), |
| 135 version) | 132 version) |
| 136 | 133 |
| 137 def GetStableChannelInfo(self, version): | 134 def GetStableChannelInfo(self, version): |
| 138 '''Given a |version| corresponding to a 'stable' version of Chrome, returns | 135 '''Given a |version| corresponding to a 'stable' version of Chrome, returns |
| 139 a ChannelInfo object representing that version. | 136 a ChannelInfo object representing that version. |
| 140 ''' | 137 ''' |
| 141 return ChannelInfo('stable', self.GetBranchForVersion(version), version) | 138 branch = self.GetBranchForVersion(version) |
| 139 if branch is None: |
| 140 return None |
| 141 return ChannelInfo('stable', branch, version) |
| 142 | 142 |
| 143 def _ExtractFromVersionJson(self, channel_name, data_type): | 143 def _ExtractFromVersionJson(self, channel_name, data_type): |
| 144 '''Returns the branch or version number for a channel name. | 144 '''Returns the branch or version number for a channel name. |
| 145 ''' | 145 ''' |
| 146 if channel_name == 'master': | 146 if channel_name == 'master': |
| 147 return 'master' | 147 return 'master' |
| 148 | 148 |
| 149 if data_type == 'branch': | 149 if data_type == 'branch': |
| 150 object_store = self._branch_object_store | 150 object_store = self._branch_object_store |
| 151 elif data_type == 'version': | 151 elif data_type == 'version': |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if version == 'master': | 193 if version == 'master': |
| 194 return 'master' | 194 return 'master' |
| 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: | 201 for entry in version_json: |
| 202 version_title = entry['version'].split('.') | 202 version_title = entry['version'].split('.') |
| 203 # TODO(devlin): Is there a reason we don't cache all these values now? |
| 203 if version_title[0] == str(version): | 204 if version_title[0] == str(version): |
| 204 self._branch_object_store.Set(str(version), version_title[2]) | 205 self._branch_object_store.Set(str(version), version_title[2]) |
| 205 return version_title[2] | 206 return version_title[2] |
| 206 | 207 |
| 207 raise ValueError('The branch for %s could not be found.' % version) | 208 # This can legitimately happen because |
| 209 # https://omahaproxy.appspot.com/history.json?channel=dev&os=win&json=1 |
| 210 # (where we get the branch data) has a maximum number of results. The |
| 211 # assertion is a nasty hack to make sure that we're at least retrieving |
| 212 # a reasonable number of version. Unfortunately, this is also doomed to |
| 213 # need updating every five years or so. |
| 214 # TODO(devlin): Really, this is awful. |
| 215 assert(version < 40) |
| 216 return None |
| 208 | 217 |
| 209 def GetChannelForVersion(self, version): | 218 def GetChannelForVersion(self, version): |
| 210 '''Returns the name of the development channel corresponding to a given | 219 '''Returns the name of the development channel corresponding to a given |
| 211 version number. | 220 version number. |
| 212 ''' | 221 ''' |
| 213 for channel_info in self.GetAllChannelInfo(): | 222 for channel_info in self.GetAllChannelInfo(): |
| 214 if channel_info.channel == 'stable' and version <= channel_info.version: | 223 if channel_info.channel == 'stable' and version <= channel_info.version: |
| 215 return channel_info.channel | 224 return channel_info.channel |
| 216 if version == channel_info.version: | 225 if version == channel_info.version: |
| 217 return channel_info.channel | 226 return channel_info.channel |
| 218 | 227 |
| 219 def GetLatestVersionNumber(self): | 228 def GetLatestVersionNumber(self): |
| 220 '''Returns the most recent version number found using data stored on | 229 '''Returns the most recent version number found using data stored on |
| 221 omahaproxy. | 230 omahaproxy. |
| 222 ''' | 231 ''' |
| 223 latest_version = self._version_object_store.Get('latest').Get() | 232 latest_version = self._version_object_store.Get('latest').Get() |
| 224 if latest_version is not None: | 233 if latest_version is not None: |
| 225 return latest_version | 234 return latest_version |
| 226 | 235 |
| 227 version_json = json.loads(self._history_result.Get().content) | 236 version_json = json.loads(self._history_result.Get().content) |
| 228 latest_version = 0 | 237 latest_version = 0 |
| 229 for entry in version_json: | 238 for entry in version_json: |
| 230 version_title = entry['version'].split('.') | 239 version_title = entry['version'].split('.') |
| 231 version = int(version_title[0]) | 240 version = int(version_title[0]) |
| 232 if version > latest_version: | 241 if version > latest_version: |
| 233 latest_version = version | 242 latest_version = version |
| 234 | 243 |
| 235 self._version_object_store.Set('latest', latest_version) | 244 self._version_object_store.Set('latest', latest_version) |
| 236 return latest_version | 245 return latest_version |
| OLD | NEW |