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

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: rename to provider 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
24 assert isinstance(branch, basestring), branch
25 assert isinstance(version, int) or version == 'trunk', version
23 self.channel = channel 26 self.channel = channel
24 self.branch = branch 27 self.branch = branch
25 self.version = version 28 self.version = version
26 29
27 def __eq__(self, other): 30 def __eq__(self, other):
28 return self.__dict__ == other.__dict__ 31 return self.__dict__ == other.__dict__
29 32
30 def __ne__(self, other): 33 def __ne__(self, other):
31 return not (self == other) 34 return not (self == other)
32 35
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 def GetAllVersions(self): 118 def GetAllVersions(self):
116 return tuple(self.GetChannelInfo(channel).version 119 return tuple(self.GetChannelInfo(channel).version
117 for channel in BranchUtility.GetAllChannelNames()) 120 for channel in BranchUtility.GetAllChannelNames())
118 121
119 def GetAllChannelInfo(self): 122 def GetAllChannelInfo(self):
120 return tuple(self.GetChannelInfo(channel) 123 return tuple(self.GetChannelInfo(channel)
121 for channel in BranchUtility.GetAllChannelNames()) 124 for channel in BranchUtility.GetAllChannelNames())
122 125
123 126
124 def GetChannelInfo(self, channel): 127 def GetChannelInfo(self, channel):
128 version = self._ExtractFromVersionJson(channel, 'version')
129 if version != 'trunk':
130 version = int(version)
125 return ChannelInfo(channel, 131 return ChannelInfo(channel,
126 self._ExtractFromVersionJson(channel, 'branch'), 132 self._ExtractFromVersionJson(channel, 'branch'),
127 self._ExtractFromVersionJson(channel, 'version')) 133 version)
128 134
129 def GetStableChannelInfo(self, version): 135 def GetStableChannelInfo(self, version):
130 '''Given a |version| corresponding to a 'stable' version of Chrome, returns 136 '''Given a |version| corresponding to a 'stable' version of Chrome, returns
131 a ChannelInfo object representing that version. 137 a ChannelInfo object representing that version.
132 ''' 138 '''
133 return ChannelInfo('stable', self.GetBranchForVersion(version), version) 139 return ChannelInfo('stable', self.GetBranchForVersion(version), version)
134 140
135 def _ExtractFromVersionJson(self, channel_name, data_type): 141 def _ExtractFromVersionJson(self, channel_name, data_type):
136 '''Returns the branch or version number for a channel name. 142 '''Returns the branch or version number for a channel name.
137 ''' 143 '''
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 number = version['version'].split('.')[0] 175 number = version['version'].split('.')[0]
170 if number not in numbers: 176 if number not in numbers:
171 numbers[number] = 0 177 numbers[number] = 0
172 else: 178 else:
173 numbers[number] += 1 179 numbers[number] += 1
174 180
175 sorted_numbers = sorted(numbers.iteritems(), 181 sorted_numbers = sorted(numbers.iteritems(),
176 None, 182 None,
177 operator.itemgetter(1), 183 operator.itemgetter(1),
178 True) 184 True)
179 object_store.Set(channel_name, int(sorted_numbers[0][0])) 185 object_store.Set(channel_name, sorted_numbers[0][0])
180 return int(sorted_numbers[0][0]) 186 return sorted_numbers[0][0]
181 187
182 def GetBranchForVersion(self, version): 188 def GetBranchForVersion(self, version):
183 '''Returns the most recent branch for a given chrome version number using 189 '''Returns the most recent branch for a given chrome version number using
184 data stored on omahaproxy (see url_constants). 190 data stored on omahaproxy (see url_constants).
185 ''' 191 '''
186 if version == 'trunk': 192 if version == 'trunk':
187 return 'trunk' 193 return 'trunk'
188 194
189 branch = self._branch_object_store.Get(str(version)).Get() 195 branch = self._branch_object_store.Get(str(version)).Get()
190 if branch is not None: 196 if branch is not None:
191 return branch 197 return branch
192 198
193 version_json = json.loads(self._history_result.Get().content) 199 version_json = json.loads(self._history_result.Get().content)
194 for entry in version_json['events']: 200 for entry in version_json['events']:
195 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##' 201 # Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##'
196 version_title = entry['title'].split(' - ')[1].split('.') 202 version_title = entry['title'].split(' - ')[1].split('.')
197 if version_title[0] == str(version): 203 if version_title[0] == str(version):
198 self._branch_object_store.Set(str(version), int(version_title[2])) 204 self._branch_object_store.Set(str(version), version_title[2])
199 return int(version_title[2]) 205 return version_title[2]
200 206
201 raise ValueError('The branch for %s could not be found.' % version) 207 raise ValueError('The branch for %s could not be found.' % version)
202 208
203 def GetChannelForVersion(self, version): 209 def GetChannelForVersion(self, version):
204 '''Returns the name of the development channel corresponding to a given 210 '''Returns the name of the development channel corresponding to a given
205 version number. 211 version number.
206 ''' 212 '''
207 for channel_info in self.GetAllChannelInfo(): 213 for channel_info in self.GetAllChannelInfo():
208 if channel_info.channel == 'stable' and version <= channel_info.version: 214 if channel_info.channel == 'stable' and version <= channel_info.version:
209 return channel_info.channel 215 return channel_info.channel
(...skipping 11 matching lines...) Expand all
221 version_json = json.loads(self._history_result.Get().content) 227 version_json = json.loads(self._history_result.Get().content)
222 latest_version = 0 228 latest_version = 0
223 for entry in version_json['events']: 229 for entry in version_json['events']:
224 version_title = entry['title'].split(' - ')[1].split('.') 230 version_title = entry['title'].split(' - ')[1].split('.')
225 version = int(version_title[0]) 231 version = int(version_title[0])
226 if version > latest_version: 232 if version > latest_version:
227 latest_version = version 233 latest_version = version
228 234
229 self._version_object_store.Set('latest', latest_version) 235 self._version_object_store.Set('latest', latest_version)
230 return latest_version 236 return latest_version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698