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 |
11 | 11 |
12 | 12 |
13 class ChannelInfo(object): | 13 class ChannelInfo(object): |
14 '''Represents a Chrome channel with three pieces of information. |channel| is | 14 '''Represents a Chrome channel with three pieces of information. |channel| is |
15 one of 'stable', 'beta', 'dev', or 'trunk'. |branch| and |version| correspond | 15 one of 'stable', 'beta', 'dev', or 'trunk'. |branch| and |version| correspond |
16 with each other, and represent different releases of Chrome. Note that | 16 with each other, and represent different releases of Chrome. Note that |
17 |branch| and |version| can occasionally be the same for separate channels | 17 |branch| and |version| can occasionally be the same for separate channels |
18 (i.e. 'beta' and 'dev'), so all three fields are required to uniquely | 18 (i.e. 'beta' and 'dev'), so all three fields are required to uniquely |
19 identify a channel. | 19 identify a channel. |
20 ''' | 20 ''' |
21 | 21 |
22 def __init__(self, channel, branch, version): | 22 def __init__(self, channel, branch, version): |
| 23 assert isinstance(channel, basestring), channel |
| 24 assert isinstance(branch, basestring), branch |
| 25 # TODO(kalman): Assert that this is a string. One day Chromium will probably |
| 26 # be served out of a git repository and the versions will no longer be ints. |
| 27 assert isinstance(version, int) or version == 'trunk', version |
23 self.channel = channel | 28 self.channel = channel |
24 self.branch = branch | 29 self.branch = branch |
25 self.version = version | 30 self.version = version |
26 | 31 |
27 def __eq__(self, other): | 32 def __eq__(self, other): |
28 return self.__dict__ == other.__dict__ | 33 return self.__dict__ == other.__dict__ |
29 | 34 |
30 def __ne__(self, other): | 35 def __ne__(self, other): |
31 return not (self == other) | 36 return not (self == other) |
32 | 37 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 def GetAllVersions(self): | 120 def GetAllVersions(self): |
116 return tuple(self.GetChannelInfo(channel).version | 121 return tuple(self.GetChannelInfo(channel).version |
117 for channel in BranchUtility.GetAllChannelNames()) | 122 for channel in BranchUtility.GetAllChannelNames()) |
118 | 123 |
119 def GetAllChannelInfo(self): | 124 def GetAllChannelInfo(self): |
120 return tuple(self.GetChannelInfo(channel) | 125 return tuple(self.GetChannelInfo(channel) |
121 for channel in BranchUtility.GetAllChannelNames()) | 126 for channel in BranchUtility.GetAllChannelNames()) |
122 | 127 |
123 | 128 |
124 def GetChannelInfo(self, channel): | 129 def GetChannelInfo(self, channel): |
| 130 version = self._ExtractFromVersionJson(channel, 'version') |
| 131 if version != 'trunk': |
| 132 version = int(version) |
125 return ChannelInfo(channel, | 133 return ChannelInfo(channel, |
126 self._ExtractFromVersionJson(channel, 'branch'), | 134 self._ExtractFromVersionJson(channel, 'branch'), |
127 self._ExtractFromVersionJson(channel, 'version')) | 135 version) |
128 | 136 |
129 def GetStableChannelInfo(self, version): | 137 def GetStableChannelInfo(self, version): |
130 '''Given a |version| corresponding to a 'stable' version of Chrome, returns | 138 '''Given a |version| corresponding to a 'stable' version of Chrome, returns |
131 a ChannelInfo object representing that version. | 139 a ChannelInfo object representing that version. |
132 ''' | 140 ''' |
133 return ChannelInfo('stable', self.GetBranchForVersion(version), version) | 141 return ChannelInfo('stable', self.GetBranchForVersion(version), version) |
134 | 142 |
135 def _ExtractFromVersionJson(self, channel_name, data_type): | 143 def _ExtractFromVersionJson(self, channel_name, data_type): |
136 '''Returns the branch or version number for a channel name. | 144 '''Returns the branch or version number for a channel name. |
137 ''' | 145 ''' |
(...skipping 28 matching lines...) Expand all Loading... |
166 if data_type == 'branch': | 174 if data_type == 'branch': |
167 number = version['version'].split('.')[2] | 175 number = version['version'].split('.')[2] |
168 elif data_type == 'version': | 176 elif data_type == 'version': |
169 number = version['version'].split('.')[0] | 177 number = version['version'].split('.')[0] |
170 if number not in numbers: | 178 if number not in numbers: |
171 numbers[number] = 0 | 179 numbers[number] = 0 |
172 else: | 180 else: |
173 numbers[number] += 1 | 181 numbers[number] += 1 |
174 | 182 |
175 sorted_numbers = sorted(numbers.iteritems(), | 183 sorted_numbers = sorted(numbers.iteritems(), |
176 None, | 184 key=operator.itemgetter(1), |
177 operator.itemgetter(1), | 185 reverse=True) |
178 True) | 186 object_store.Set(channel_name, sorted_numbers[0][0]) |
179 object_store.Set(channel_name, int(sorted_numbers[0][0])) | 187 return sorted_numbers[0][0] |
180 return int(sorted_numbers[0][0]) | |
181 | 188 |
182 def GetBranchForVersion(self, version): | 189 def GetBranchForVersion(self, version): |
183 '''Returns the most recent branch for a given chrome version number using | 190 '''Returns the most recent branch for a given chrome version number using |
184 data stored on omahaproxy (see url_constants). | 191 data stored on omahaproxy (see url_constants). |
185 ''' | 192 ''' |
186 if version == 'trunk': | 193 if version == 'trunk': |
187 return 'trunk' | 194 return 'trunk' |
188 | 195 |
189 branch = self._branch_object_store.Get(str(version)).Get() | 196 branch = self._branch_object_store.Get(str(version)).Get() |
190 if branch is not None: | 197 if branch is not None: |
191 return branch | 198 return branch |
192 | 199 |
193 version_json = json.loads(self._history_result.Get().content) | 200 version_json = json.loads(self._history_result.Get().content) |
194 for entry in version_json['events']: | 201 for entry in version_json['events']: |
195 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##' | 202 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##' |
196 version_title = entry['title'].split(' - ')[1].split('.') | 203 version_title = entry['title'].split(' - ')[1].split('.') |
197 if version_title[0] == str(version): | 204 if version_title[0] == str(version): |
198 self._branch_object_store.Set(str(version), int(version_title[2])) | 205 self._branch_object_store.Set(str(version), version_title[2]) |
199 return int(version_title[2]) | 206 return version_title[2] |
200 | 207 |
201 raise ValueError('The branch for %s could not be found.' % version) | 208 raise ValueError('The branch for %s could not be found.' % version) |
202 | 209 |
203 def GetChannelForVersion(self, version): | 210 def GetChannelForVersion(self, version): |
204 '''Returns the name of the development channel corresponding to a given | 211 '''Returns the name of the development channel corresponding to a given |
205 version number. | 212 version number. |
206 ''' | 213 ''' |
207 for channel_info in self.GetAllChannelInfo(): | 214 for channel_info in self.GetAllChannelInfo(): |
208 if channel_info.channel == 'stable' and version <= channel_info.version: | 215 if channel_info.channel == 'stable' and version <= channel_info.version: |
209 return channel_info.channel | 216 return channel_info.channel |
(...skipping 11 matching lines...) Expand all Loading... |
221 version_json = json.loads(self._history_result.Get().content) | 228 version_json = json.loads(self._history_result.Get().content) |
222 latest_version = 0 | 229 latest_version = 0 |
223 for entry in version_json['events']: | 230 for entry in version_json['events']: |
224 version_title = entry['title'].split(' - ')[1].split('.') | 231 version_title = entry['title'].split(' - ')[1].split('.') |
225 version = int(version_title[0]) | 232 version = int(version_title[0]) |
226 if version > latest_version: | 233 if version > latest_version: |
227 latest_version = version | 234 latest_version = version |
228 | 235 |
229 self._version_object_store.Set('latest', latest_version) | 236 self._version_object_store.Set('latest', latest_version) |
230 return latest_version | 237 return latest_version |
OLD | NEW |