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

Side by Side Diff: globals/get_browser_versions.py

Issue 6702768332996608: Issue 2432 - Auto-generate browser versions on requirements page (Closed)
Patch Set: Addressed comments Created May 13, 2015, 6:18 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 | « .hgignore ('k') | pages/requirements.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 url = '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 print url
41 response = urllib2.urlopen(url)
42 try:
43 doc = minidom.parse(response)
44 finally:
45 response.close()
46
47 update = doc.getElementsByTagName('update')[0]
48 full_version = update.getAttribute(attribute)
49
50 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
51 if minor:
52 return match.group(0)
53 return match.group(1)
54
55 def get_mozilla_versions(product, origin_version, release_minor=False):
56 return {
57 'current': get_mozilla_version(product, origin_version, 'release', release_m inor),
58 'unreleased': [
59 get_mozilla_version(product, origin_version, 'beta'),
60 get_mozilla_version(product, origin_version, 'aurora'),
61 get_mozilla_version(product, origin_version, 'nightly'),
62 ]
63 }
64
65 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
66 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
67
68 def get_seamonkey_version(origin_version, origin_build, channel, **kw):
69 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
70 'aus2-community', origin_build, 'version', **kw)
71
72 def get_seamonkey_versions():
73 versions = {
74 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
75 'unreleased': [get_seamonkey_version('2.32', '20150101215737', 'beta')]
76 }
77
78 # Aurora builds for Windows, and Nighlies for all platforms
79 # are currently broken, and don't seem to come back soon.
80 # https://bugzilla.mozilla.org/show_bug.cgi?id=1086553
81 for channel in ('aurora', 'nightly'):
82 try:
83 version = get_seamonkey_version('2.13.1', '20120909051705', channel, platf orm='Linux_x86-gcc3')
84 except Exception:
85 continue
86 versions['unreleased'].append(version)
87
88 return versions
89
90 BROWSERS['seamonkey'] = get_seamonkey_versions
91
92 def get_chrome_version(manifest):
93 return manifest.getAttribute('version').split('.')[0]
94
95 def get_chrome_versions():
96 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
97 try:
98 doc = minidom.parse(response)
99 finally:
100 response.close()
101
102 manifests = doc.getElementsByTagName('manifest')
103 return {
104 'current': get_chrome_version(manifests[0]),
105 'unreleased': map(get_chrome_version, manifests[1:])
106 }
107
108 BROWSERS['chrome'] = get_chrome_versions
109
110 def get_opera_version(channel):
111 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
112 try:
113 spec = json.load(response)
114 finally:
115 response.close()
116
117 return re.search(r'\d+', spec['installer_filename']).group(0)
118
119 def get_opera_versions():
120 return {
121 'current': get_opera_version('Stable'),
122 'unreleased': [
123 get_opera_version('Beta'),
124 get_opera_version('Developer')
125 ]
126 }
127
128 BROWSERS['opera'] = get_opera_versions
129
130 def get_yandex_version(suffix):
131 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix)
132 try:
133 doc = minidom.parse(response)
134 finally:
135 response.close()
136
137 item = doc.getElementsByTagName('item')[0]
138 description = item.getElementsByTagName('description')[0]
139 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
140
141 def get_yandex_versions():
142 return {
143 'current': get_yandex_version(''),
144 'unreleased': [get_yandex_version('-beta')]
145 }
146
147 BROWSERS['yandex'] = get_yandex_versions
148
149 def open_cache_file(filename):
150 flags = os.O_RDWR | os.O_CREAT
151 try:
152 fd = os.open(filename, flags)
153 except OSError as e:
154 if e.errno != errno.ENOENT:
155 raise
156 os.makedirs(os.path.dirname(filename))
157 fd = os.open(filename, flags)
158 return os.fdopen(fd, 'w+')
159
160 @contextfunction
161 def get_browser_versions(context, browser):
162 func = BROWSERS[browser]
163 exc_info = None
164 try:
165 versions = func()
166 except Exception:
167 exc_info = sys.exc_info()
168
169 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
170 with open_cache_file(filename) as file:
171 try:
172 cache = json.load(file)
173 except ValueError:
174 if file.tell() > 0:
175 raise
176 cache = {}
177
178 cached_versions = cache.get(browser)
179 if exc_info:
180 if not cached_versions:
181 raise exc_info[0], exc_info[1], exc_info[2]
182
183 versions = cached_versions
184 logging.warning('Failed to get %s versions, falling back to '
185 'cached versions', browser, exc_info=exc_info)
186 else:
187 # Determine previous version: If we recorded the version before and it
188 # changed since then, the old current version becomes the new previous
189 # version. If the version didn't change, use the cached previous version.
190 current = versions['current']
191 previous = None
192 if cached_versions:
193 cached_current = cached_versions['current']
194 if cached_current != current:
195 previous = cached_current
196 else:
197 previous = cached_versions['previous']
198 versions['previous'] = previous
199
200 # Remove duplicates from unreleased versions. Occasionally,
201 # different channels are on the same version, but we want
202 # to list each version only once.
203 versions['unreleased'] = sorted(
204 set(versions['unreleased']) - {current, previous},
205 key=lambda ver: map(int, ver.split('.'))
206 )
207
208 cache[browser] = versions
209 file.seek(0)
210 json.dump(cache, file)
211 file.truncate()
212
213 if not versions['previous']:
214 logging.warning("Couldn't determine previous browser version, "
215 'please set %s.previous in %s', browser, filename)
216
217 return versions
OLDNEW
« no previous file with comments | « .hgignore ('k') | pages/requirements.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld