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: Removed debug print Created May 13, 2015, 6:38 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 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 versions = {
72 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
73 'unreleased': [get_seamonkey_version('2.32', '20150101215737', 'beta')]
74 }
75
76 # Aurora builds for Windows, and Nighlies for all platforms
77 # are currently broken, and don't seem to come back soon.
78 # https://bugzilla.mozilla.org/show_bug.cgi?id=1086553
79 for channel in ('aurora', 'nightly'):
80 try:
81 version = get_seamonkey_version('2.13.1', '20120909051705', channel, platf orm='Linux_x86-gcc3')
Wladimir Palant 2015/05/14 19:53:19 Nit: use '2.32', '-' here? Aurora and Nightly chan
Sebastian Noack 2015/05/15 10:24:54 Done. Note that while nightlies weren't working, s
82 except Exception:
83 continue
84 versions['unreleased'].append(version)
85
86 return versions
87
88 BROWSERS['seamonkey'] = get_seamonkey_versions
89
90 def get_chrome_version(manifest):
91 return manifest.getAttribute('version').split('.')[0]
92
93 def get_chrome_versions():
94 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
95 try:
96 doc = minidom.parse(response)
97 finally:
98 response.close()
99
100 manifests = doc.getElementsByTagName('manifest')
101 return {
102 'current': get_chrome_version(manifests[0]),
103 'unreleased': map(get_chrome_version, manifests[1:])
104 }
105
106 BROWSERS['chrome'] = get_chrome_versions
107
108 def get_opera_version(channel):
109 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
110 try:
111 spec = json.load(response)
112 finally:
113 response.close()
114
115 return re.search(r'\d+', spec['installer_filename']).group(0)
116
117 def get_opera_versions():
118 return {
119 'current': get_opera_version('Stable'),
120 'unreleased': [
121 get_opera_version('Beta'),
122 get_opera_version('Developer')
123 ]
124 }
125
126 BROWSERS['opera'] = get_opera_versions
127
128 def get_yandex_version(suffix):
129 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix)
130 try:
131 doc = minidom.parse(response)
132 finally:
133 response.close()
134
135 item = doc.getElementsByTagName('item')[0]
136 description = item.getElementsByTagName('description')[0]
137 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
138
139 def get_yandex_versions():
140 return {
141 'current': get_yandex_version(''),
142 'unreleased': [get_yandex_version('-beta')]
143 }
144
145 BROWSERS['yandex'] = get_yandex_versions
146
147 def open_cache_file(filename):
148 flags = os.O_RDWR | os.O_CREAT
149 try:
150 fd = os.open(filename, flags)
151 except OSError as e:
152 if e.errno != errno.ENOENT:
153 raise
154 os.makedirs(os.path.dirname(filename))
155 fd = os.open(filename, flags)
156 return os.fdopen(fd, 'w+')
157
158 @contextfunction
159 def get_browser_versions(context, browser):
160 func = BROWSERS[browser]
161 exc_info = None
162 try:
163 versions = func()
164 except Exception:
165 exc_info = sys.exc_info()
166
167 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
168 with open_cache_file(filename) as file:
169 try:
170 cache = json.load(file)
171 except ValueError:
172 if file.tell() > 0:
173 raise
174 cache = {}
175
176 cached_versions = cache.get(browser)
177 if exc_info:
178 if not cached_versions:
179 raise exc_info[0], exc_info[1], exc_info[2]
180
181 versions = cached_versions
182 logging.warning('Failed to get %s versions, falling back to '
183 'cached versions', browser, exc_info=exc_info)
184 else:
185 # Determine previous version: If we recorded the version before and it
186 # changed since then, the old current version becomes the new previous
187 # version. If the version didn't change, use the cached previous version.
188 current = versions['current']
189 previous = None
190 if cached_versions:
191 cached_current = cached_versions['current']
192 if cached_current != current:
193 previous = cached_current
194 else:
195 previous = cached_versions['previous']
196 versions['previous'] = previous
197
198 # Remove duplicates from unreleased versions. Occasionally,
199 # different channels are on the same version, but we want
200 # to list each version only once.
201 versions['unreleased'] = sorted(
202 set(versions['unreleased']) - {current, previous},
203 key=lambda ver: map(int, ver.split('.'))
204 )
205
206 cache[browser] = versions
207 file.seek(0)
208 json.dump(cache, file)
209 file.truncate()
210
211 if not versions['previous']:
212 logging.warning("Couldn't determine previous browser version, "
213 'please set %s.previous in %s', browser, filename)
214
215 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