Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: globals/get_browser_versions.py

Issue 5341722020151296: Issue 2628 - Fix stable version of Yandex.Browser listed on the requirements page (Closed)
Patch Set: Get both variants and pick newer Created June 3, 2015, 4:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import re 1 import re
2 import os 2 import os
3 import sys 3 import sys
4 import json 4 import json
5 import urllib 5 import urllib
6 import errno 6 import errno
7 import logging 7 import logging
8 import time 8 import time
9 from xml.dom import minidom 9 from xml.dom import minidom
10 10
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return { 121 return {
122 'current': get_opera_version('Stable'), 122 'current': get_opera_version('Stable'),
123 'unreleased': [ 123 'unreleased': [
124 get_opera_version('Beta'), 124 get_opera_version('Beta'),
125 get_opera_version('Developer') 125 get_opera_version('Developer')
126 ] 126 ]
127 } 127 }
128 128
129 BROWSERS['opera'] = get_opera_versions 129 BROWSERS['opera'] = get_opera_versions
130 130
131 def get_yandex_version(suffix): 131 def key_by_version(version):
132 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y andex%s/win-yandex.xml' % suffix) 132 return map(int, version.split('.'))
133
134 def get_yandex_version_raw(suffix, params):
135 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y andex%s/win-yandex.xml' % (suffix, params))
Wladimir Palant 2015/06/03 17:11:36 If I'm not mistaken this should produce "not all a
Sebastian Noack 2015/06/03 17:42:31 Argh, you are right. I did test the change, but in
133 try: 136 try:
134 doc = minidom.parse(response) 137 doc = minidom.parse(response)
135 finally: 138 finally:
136 response.close() 139 response.close()
137 140
138 item = doc.getElementsByTagName('item')[0] 141 item = doc.getElementsByTagName('item')[0]
139 description = item.getElementsByTagName('description')[0] 142 description = item.getElementsByTagName('description')[0]
140 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) 143 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
141 144
145 def get_yandex_version(suffix=''):
146 return max(
147 [
148 get_yandex_version_raw(suffix, ''),
149 get_yandex_version_raw(suffix, '?manual=yes'),
150 ],
151 key=key_by_version
152 )
153
142 def get_yandex_versions(): 154 def get_yandex_versions():
143 return { 155 return {
144 'current': get_yandex_version(''), 156 'current': get_yandex_version(),
145 'unreleased': [get_yandex_version('-beta')] 157 'unreleased': [get_yandex_version('-beta')]
146 } 158 }
147 159
148 BROWSERS['yandex'] = get_yandex_versions 160 BROWSERS['yandex'] = get_yandex_versions
149 161
150 def open_cache_file(filename): 162 def open_cache_file(filename):
151 flags = os.O_RDWR | os.O_CREAT 163 flags = os.O_RDWR | os.O_CREAT
152 try: 164 try:
153 fd = os.open(filename, flags) 165 fd = os.open(filename, flags)
154 except OSError as e: 166 except OSError as e:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 previous = cached_current 214 previous = cached_current
203 else: 215 else:
204 previous = cached_versions['previous'] 216 previous = cached_versions['previous']
205 versions['previous'] = previous 217 versions['previous'] = previous
206 218
207 # Remove duplicates from unreleased versions. Occasionally, 219 # Remove duplicates from unreleased versions. Occasionally,
208 # different channels are on the same version, but we want 220 # different channels are on the same version, but we want
209 # to list each version only once. 221 # to list each version only once.
210 versions['unreleased'] = sorted( 222 versions['unreleased'] = sorted(
211 set(versions['unreleased']) - {current, previous}, 223 set(versions['unreleased']) - {current, previous},
212 key=lambda ver: map(int, ver.split('.')) 224 key=key_by_version
213 ) 225 )
214 226
215 versions['timestamp'] = now 227 versions['timestamp'] = now
216 persistent_cache[browser] = versions 228 persistent_cache[browser] = versions
217 file.seek(0) 229 file.seek(0)
218 json.dump(persistent_cache, file) 230 json.dump(persistent_cache, file)
219 file.truncate() 231 file.truncate()
220 232
221 if not versions['previous']: 233 if not versions['previous']:
222 logging.warning("Couldn't determine previous browser version, " 234 logging.warning("Couldn't determine previous browser version, "
223 'please set %s.previous in %s', browser, filename) 235 'please set %s.previous in %s', browser, filename)
224 236
225 cache[browser] = versions 237 cache[browser] = versions
226 return versions 238 return versions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld