Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: chrome/common/extensions/docs/server2/branch_utility.py

Issue 26418002: Docserver: Pull knowledge of host file systems into a single (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
Jeffrey Yasskin 2013/10/08 17:46:05 Do you want basestring or str here? How are you ha
not at google - send to devlin 2013/10/08 18:27:37 Does unicode need to be handled any differently? I
Jeffrey Yasskin 2013/10/08 20:49:39 Unicode probably needs to be encoded before you ma
not at google - send to devlin 2013/10/08 21:29:36 I'm not sure what encoding we specify on fetches.
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
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
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 None,
Jeffrey Yasskin 2013/10/08 17:46:05 Wow, this is terrible style. sorted() wants keywor
not at google - send to devlin 2013/10/08 18:27:37 Heh.
177 operator.itemgetter(1), 185 operator.itemgetter(1),
178 True) 186 True)
179 object_store.Set(channel_name, int(sorted_numbers[0][0])) 187 object_store.Set(channel_name, sorted_numbers[0][0])
180 return int(sorted_numbers[0][0]) 188 return sorted_numbers[0][0]
181 189
182 def GetBranchForVersion(self, version): 190 def GetBranchForVersion(self, version):
183 '''Returns the most recent branch for a given chrome version number using 191 '''Returns the most recent branch for a given chrome version number using
184 data stored on omahaproxy (see url_constants). 192 data stored on omahaproxy (see url_constants).
185 ''' 193 '''
186 if version == 'trunk': 194 if version == 'trunk':
187 return 'trunk' 195 return 'trunk'
188 196
189 branch = self._branch_object_store.Get(str(version)).Get() 197 branch = self._branch_object_store.Get(str(version)).Get()
190 if branch is not None: 198 if branch is not None:
191 return branch 199 return branch
192 200
193 version_json = json.loads(self._history_result.Get().content) 201 version_json = json.loads(self._history_result.Get().content)
194 for entry in version_json['events']: 202 for entry in version_json['events']:
195 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##' 203 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##'
196 version_title = entry['title'].split(' - ')[1].split('.') 204 version_title = entry['title'].split(' - ')[1].split('.')
197 if version_title[0] == str(version): 205 if version_title[0] == str(version):
198 self._branch_object_store.Set(str(version), int(version_title[2])) 206 self._branch_object_store.Set(str(version), version_title[2])
199 return int(version_title[2]) 207 return version_title[2]
200 208
201 raise ValueError('The branch for %s could not be found.' % version) 209 raise ValueError('The branch for %s could not be found.' % version)
202 210
203 def GetChannelForVersion(self, version): 211 def GetChannelForVersion(self, version):
204 '''Returns the name of the development channel corresponding to a given 212 '''Returns the name of the development channel corresponding to a given
205 version number. 213 version number.
206 ''' 214 '''
207 for channel_info in self.GetAllChannelInfo(): 215 for channel_info in self.GetAllChannelInfo():
208 if channel_info.channel == 'stable' and version <= channel_info.version: 216 if channel_info.channel == 'stable' and version <= channel_info.version:
209 return channel_info.channel 217 return channel_info.channel
(...skipping 11 matching lines...) Expand all
221 version_json = json.loads(self._history_result.Get().content) 229 version_json = json.loads(self._history_result.Get().content)
222 latest_version = 0 230 latest_version = 0
223 for entry in version_json['events']: 231 for entry in version_json['events']:
224 version_title = entry['title'].split(' - ')[1].split('.') 232 version_title = entry['title'].split(' - ')[1].split('.')
225 version = int(version_title[0]) 233 version = int(version_title[0])
226 if version > latest_version: 234 if version > latest_version:
227 latest_version = version 235 latest_version = version
228 236
229 self._version_object_store.Set('latest', latest_version) 237 self._version_object_store.Set('latest', latest_version)
230 return latest_version 238 return latest_version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698