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

Delta Between Two Patch Sets: globals/get_browser_versions.py

Issue 6702768332996608: Issue 2432 - Auto-generate browser versions on requirements page (Closed)
Left Patch Set: Created April 29, 2015, 1:16 p.m.
Right Patch Set: Removed build ID an try-block for SeaMonkey Aurora and Nightly Created May 15, 2015, 10:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « .hgignore ('k') | pages/requirements.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import re
2 import os
3 import sys
4 import json
5 import urllib2
6 import errno
7 import logging
8 from xml.dom import minidom
9
10 from jinja2 import contextfunction
11
12 BROWSERS = {}
13
14 CHROME_UPDATE_XML = '''\
15 <?xml version="1.0" encoding="UTF-8"?>
16 <request protocol="3.0" ismachine="0">
17 <os platform="win" version="99" arch="x64"/>
18 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
19 <updatecheck/>
20 </app>
21 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
22 <updatecheck/>
23 </app>
24 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
25 <updatecheck/>
26 </app>
27 </request>'''
28
29 def get_mozilla_version(product, origin_version, channel,
30 minor=False, subdomain='aus4', origin_build='-',
31 attribute='appVersion', platform='WINNT_x86-msvc'):
32 response = urllib2.urlopen('https://%s.mozilla.org/update/3/%s/%s/%s/%s/en-US/ %s/-/default/default/update.xml?force=1' % (
33 subdomain,
34 product,
35 origin_version,
36 origin_build,
37 platform,
38 channel
39 ))
40 try:
41 doc = minidom.parse(response)
42 finally:
43 response.close()
44
45 update = doc.getElementsByTagName('update')[0]
46 full_version = update.getAttribute(attribute)
47
48 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
49 if minor:
50 return match.group(0)
51 return match.group(1)
52
53 def get_mozilla_versions(product, origin_version, release_minor=False):
54 return {
55 'current': get_mozilla_version(product, origin_version, 'release', release_m inor),
56 'unreleased': [
57 get_mozilla_version(product, origin_version, 'beta'),
58 get_mozilla_version(product, origin_version, 'aurora'),
59 get_mozilla_version(product, origin_version, 'nightly'),
60 ]
61 }
62
63 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
64 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
65
66 def get_seamonkey_version(origin_version, origin_build, channel, **kw):
67 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
68 'aus2-community', origin_build, 'version', **kw)
69
70 def get_seamonkey_versions():
71 return {
72 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
73 'unreleased': [
74 get_seamonkey_version('2.32', '20150101215737', 'beta'),
75
76 # Aurora and Nightly builds for Windows are currently broken.
77 # https://bugzilla.mozilla.org/show_bug.cgi?id=1086553
78 get_seamonkey_version('2.32', '-', 'aurora', platform='Linux_x86-gcc3'),
79 get_seamonkey_version('2.32', '-', 'nightly', platform='Linux_x86-gcc3')
80 ]
81 }
82
83 BROWSERS['seamonkey'] = get_seamonkey_versions
84
85 def get_chrome_version(manifest):
86 return manifest.getAttribute('version').split('.')[0]
87
88 def get_chrome_versions():
89 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
90 try:
91 doc = minidom.parse(response)
92 finally:
93 response.close()
94
95 manifests = doc.getElementsByTagName('manifest')
96 return {
97 'current': get_chrome_version(manifests[0]),
98 'unreleased': map(get_chrome_version, manifests[1:])
99 }
100
101 BROWSERS['chrome'] = get_chrome_versions
102
103 def get_opera_version(channel):
104 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
105 try:
106 spec = json.load(response)
107 finally:
108 response.close()
109
110 return re.search(r'\d+', spec['installer_filename']).group(0)
111
112 def get_opera_versions():
113 return {
114 'current': get_opera_version('Stable'),
115 'unreleased': [
116 get_opera_version('Beta'),
117 get_opera_version('Developer')
118 ]
119 }
120
121 BROWSERS['opera'] = get_opera_versions
122
123 def get_yandex_version(suffix):
124 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix)
125 try:
126 doc = minidom.parse(response)
127 finally:
128 response.close()
129
130 item = doc.getElementsByTagName('item')[0]
131 description = item.getElementsByTagName('description')[0]
132 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
133
134 def get_yandex_versions():
135 return {
136 'current': get_yandex_version(''),
137 'unreleased': [get_yandex_version('-beta')]
138 }
139
140 BROWSERS['yandex'] = get_yandex_versions
141
142 def open_cache_file(filename):
143 flags = os.O_RDWR | os.O_CREAT
144 try:
145 fd = os.open(filename, flags)
146 except OSError as e:
147 if e.errno != errno.ENOENT:
148 raise
149 os.makedirs(os.path.dirname(filename))
150 fd = os.open(filename, flags)
151 return os.fdopen(fd, 'w+')
152
153 @contextfunction
154 def get_browser_versions(context, browser):
155 func = BROWSERS[browser]
156 exc_info = None
157 try:
158 versions = func()
159 except Exception:
160 exc_info = sys.exc_info()
161
162 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
163 with open_cache_file(filename) as file:
164 try:
165 cache = json.load(file)
166 except ValueError:
167 if file.tell() > 0:
168 raise
169 cache = {}
170
171 cached_versions = cache.get(browser)
172 if exc_info:
173 if not cached_versions:
174 raise exc_info[0], exc_info[1], exc_info[2]
175
176 versions = cached_versions
177 logging.warning('Failed to get %s versions, falling back to '
178 'cached versions', browser, exc_info=exc_info)
179 else:
180 # Determine previous version: If we recorded the version before and it
181 # changed since then, the old current version becomes the new previous
182 # version. If the version didn't change, use the cached previous version.
183 current = versions['current']
184 previous = None
185 if cached_versions:
186 cached_current = cached_versions['current']
187 if cached_current != current:
188 previous = cached_current
189 else:
190 previous = cached_versions['previous']
191 versions['previous'] = previous
192
193 # Remove duplicates from unreleased versions. Occasionally,
194 # different channels are on the same version, but we want
195 # to list each version only once.
196 versions['unreleased'] = sorted(
197 set(versions['unreleased']) - {current, previous},
198 key=lambda ver: map(int, ver.split('.'))
199 )
200
201 cache[browser] = versions
202 file.seek(0)
203 json.dump(cache, file)
204 file.truncate()
205
206 if not versions['previous']:
207 logging.warning("Couldn't determine previous browser version, "
208 'please set %s.previous in %s', browser, filename)
209
210 return versions
LEFTRIGHT

Powered by Google App Engine
This is Rietveld