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 some more comments Created May 5, 2015, 1:33 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, minor=False,
30 subdomain='aus4', origin_build='-', attribute='appVersio n'):
31 response = urllib2.urlopen('https://%s.mozilla.org/update/3/%s/%s/%s/WINNT_x86 -msvc/en-US/%s/-/default/default/update.xml?force=1' % (subdomain, product, orig in_version, origin_build, channel))
32 try:
33 doc = minidom.parse(response)
34 finally:
35 response.close()
36
37 update = doc.getElementsByTagName('update')[0]
38 full_version = update.getAttribute(attribute)
39
40 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
41 if minor:
42 return match.group(0)
43 return match.group(1)
44
45 def get_mozilla_versions(product, origin_version, release_minor=False):
46 return {
47 'current': get_mozilla_version(product, origin_version, 'release', release_m inor),
48 'unreleased': [
49 get_mozilla_version(product, origin_version, 'beta'),
50 get_mozilla_version(product, origin_version, 'aurora'),
51 get_mozilla_version(product, origin_version, 'nightly'),
52 ]
53 }
54
55 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
Wladimir Palant 2015/05/13 13:17:23 Style nit: Please don't align columns. This might
Sebastian Noack 2015/05/13 18:35:11 Done.
56 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
57
58 def get_seamonkey_version(origin_version, origin_build, channel):
59 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
60 'aus2-community', origin_build, 'version')
61
62 def get_seamonkey_versions():
63 return {
64 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
65 'unreleased': [get_seamonkey_version('2.32', '20150101215737', 'beta')]
66 }
67
68 BROWSERS['seamonkey'] = get_seamonkey_versions
69
70 def get_chrome_version(manifest):
71 return manifest.getAttribute('version').split('.')[0]
72
73 def get_chrome_versions():
74 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
75 try:
76 doc = minidom.parse(response)
77 finally:
78 response.close()
79
80 manifests = doc.getElementsByTagName('manifest')
81 return {
82 'current': get_chrome_version(manifests[0]),
83 'unreleased': map(get_chrome_version, manifests[1:])
84 }
85
86 BROWSERS['chrome'] = get_chrome_versions
87
88 def get_opera_version(channel):
89 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
90 try:
91 spec = json.load(response)
92 finally:
93 response.close()
94
95 return re.search(r'\d+', spec['installer_filename']).group(0)
96
97 def get_opera_versions():
98 return {
99 'current': get_opera_version('Stable'),
100 'unreleased': [
101 get_opera_version('Beta'),
102 get_opera_version('Developer')
103 ]
104 }
105
106 BROWSERS['opera'] = get_opera_versions
107
108 def get_yandex_version(suffix):
109 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix)
110 try:
111 doc = minidom.parse(response)
112 finally:
113 response.close()
114
115 item = doc.getElementsByTagName('item')[0]
116 description = item.getElementsByTagName('description')[0]
117 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
118
119 def get_yandex_versions():
120 return {
121 'current': get_yandex_version(''),
122 'unreleased': [get_yandex_version('-beta')]
123 }
124
125 BROWSERS['yandex'] = get_yandex_versions
126
127 def open_cache_file(filename):
128 flags = os.O_RDWR | os.O_CREAT
129 try:
130 fd = os.open(filename, flags)
131 except OSError as e:
132 if e.errno != errno.ENOENT:
133 raise
134 os.makedirs(os.path.dirname(filename))
135 fd = os.open(filename, flags)
136 return os.fdopen(fd, 'w+')
137
138 @contextfunction
139 def get_browser_versions(context, browser):
Wladimir Palant 2015/05/13 13:17:23 Just realized: Thunderbird isn't a browser :). But
Sebastian Noack 2015/05/13 18:35:11 Yeah, I already realized myself, and thought about
140 func = BROWSERS[browser]
141 exc_info = None
142 try:
143 versions = func()
144 except Exception:
145 exc_info = sys.exc_info()
146
147 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
148 with open_cache_file(filename) as file:
149 try:
150 cache = json.load(file)
151 except ValueError:
152 if file.tell() > 0:
153 raise
154 cache = {}
155
156 cached_versions = cache.get(browser)
157 if exc_info:
158 if not cached_versions:
159 raise exc_info[0], exc_info[1], exc_info[2]
160
161 versions = cached_versions
162 logging.warning('Failed to get %s versions, falling back to '
163 'cached versions', browser, exc_info=exc_info)
164 else:
165 # Determine previous version: If we recorded the version before and it
166 # changed since then, the old current version becomes the new previous
167 # version. If the version didn't change, use the cached previous version.
168 current = versions['current']
169 previous = None
170 if cached_versions:
171 cached_current = cached_versions['current']
172 if cached_current != current:
173 previous = cached_current
174 else:
175 previous = cached_versions['previous']
176 versions['previous'] = previous
177
178 # Remove duplicated from unreleased versions. Occasionally,
Wladimir Palant 2015/05/13 13:17:23 Typo: duplicates
Sebastian Noack 2015/05/13 18:35:11 Done.
179 # different channels are on the same version, but we want
180 # to list each version only once.
181 versions['unreleased'] = sorted(
182 set(versions['unreleased']) - {current, previous},
183 key=lambda ver: map(int, ver.split('.'))
184 )
185
186 cache[browser] = versions
187 file.seek(0)
188 json.dump(cache, file)
189 file.truncate()
190
191 if not versions['previous']:
192 logging.warning("Couldn't determine previous browser version, "
193 'please set %s.previous in %s', browser, filename)
194
195 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