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

Delta Between Two Patch Sets: globals/get_browser_versions.py

Issue 5341722020151296: Issue 2628 - Fix stable version of Yandex.Browser listed on the requirements page (Closed)
Left Patch Set: Created June 3, 2015, 4:24 p.m.
Right Patch Set: Fixed syntax error, removed unneeded list declaration Created June 3, 2015, 5:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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(beta=False): 131 def key_by_version(version):
132 url = 'https://api.browser.yandex.ru/update-info/browser/yandex%s/win-yandex.x ml%s' 132 return map(int, version.split('.'))
133 if beta: 133
134 url %= ('-beta', '') 134 def get_yandex_version_raw(suffix, params):
135 else: 135 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y andex%s/win-yandex.xml%s' % (suffix, params))
136 url %= ('', '?manual=yes')
137
138 response = urllib.urlopen(url)
139 try: 136 try:
140 doc = minidom.parse(response) 137 doc = minidom.parse(response)
141 finally: 138 finally:
142 response.close() 139 response.close()
143 140
144 item = doc.getElementsByTagName('item')[0] 141 item = doc.getElementsByTagName('item')[0]
145 description = item.getElementsByTagName('description')[0] 142 description = item.getElementsByTagName('description')[0]
146 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) 143 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
147 144
145 def get_yandex_version(suffix=''):
146 return max(
147 get_yandex_version_raw(suffix, ''),
148 get_yandex_version_raw(suffix, '?manual=yes'),
149 key=key_by_version
150 )
151
148 def get_yandex_versions(): 152 def get_yandex_versions():
149 return { 153 return {
150 'current': get_yandex_version(), 154 'current': get_yandex_version(),
151 'unreleased': [get_yandex_version(beta=True)] 155 'unreleased': [get_yandex_version('-beta')]
152 } 156 }
153 157
154 BROWSERS['yandex'] = get_yandex_versions 158 BROWSERS['yandex'] = get_yandex_versions
155 159
156 def open_cache_file(filename): 160 def open_cache_file(filename):
157 flags = os.O_RDWR | os.O_CREAT 161 flags = os.O_RDWR | os.O_CREAT
158 try: 162 try:
159 fd = os.open(filename, flags) 163 fd = os.open(filename, flags)
160 except OSError as e: 164 except OSError as e:
161 if e.errno != errno.ENOENT: 165 if e.errno != errno.ENOENT:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 previous = cached_current 212 previous = cached_current
209 else: 213 else:
210 previous = cached_versions['previous'] 214 previous = cached_versions['previous']
211 versions['previous'] = previous 215 versions['previous'] = previous
212 216
213 # Remove duplicates from unreleased versions. Occasionally, 217 # Remove duplicates from unreleased versions. Occasionally,
214 # different channels are on the same version, but we want 218 # different channels are on the same version, but we want
215 # to list each version only once. 219 # to list each version only once.
216 versions['unreleased'] = sorted( 220 versions['unreleased'] = sorted(
217 set(versions['unreleased']) - {current, previous}, 221 set(versions['unreleased']) - {current, previous},
218 key=lambda ver: map(int, ver.split('.')) 222 key=key_by_version
219 ) 223 )
220 224
221 versions['timestamp'] = now 225 versions['timestamp'] = now
222 persistent_cache[browser] = versions 226 persistent_cache[browser] = versions
223 file.seek(0) 227 file.seek(0)
224 json.dump(persistent_cache, file) 228 json.dump(persistent_cache, file)
225 file.truncate() 229 file.truncate()
226 230
227 if not versions['previous']: 231 if not versions['previous']:
228 logging.warning("Couldn't determine previous browser version, " 232 logging.warning("Couldn't determine previous browser version, "
229 'please set %s.previous in %s', browser, filename) 233 'please set %s.previous in %s', browser, filename)
230 234
231 cache[browser] = versions 235 cache[browser] = versions
232 return versions 236 return versions
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld