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: Include minor version number for Thunderbird releases Created April 30, 2015, 10:51 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 from xml.dom import minidom
8
9 from jinja2 import contextfunction
10
11 BROWSERS = {}
12
13 CHROME_UPDATE_XML = '''\
14 <?xml version="1.0" encoding="UTF-8"?>
15 <request protocol="3.0" ismachine="0">
16 <os platform="win" version="99" arch="x64"/>
17 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
18 <updatecheck/>
19 </app>
20 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
21 <updatecheck/>
22 </app>
23 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
24 <updatecheck/>
25 </app>
26 </request>'''
27
28 def get_mozilla_version(product, origin_version, channel, minor=False,
29 subdomain='aus4', origin_build='-', attribute='appVersio n'):
30 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))
31 try:
32 doc = minidom.parse(response)
33 finally:
34 response.close()
35
36 update = doc.getElementsByTagName('update')[0]
37 full_version = update.getAttribute(attribute)
38
39 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
40 if minor:
41 return match.group(0)
42 return match.group(1)
43
44 def get_mozilla_versions(product, origin_version, release_minor=False):
45 return {
46 'current': get_mozilla_version(product, origin_version, 'release', release_m inor),
47 'unreleased': [
48 get_mozilla_version(product, origin_version, 'beta'),
49 get_mozilla_version(product, origin_version, 'aurora'),
50 get_mozilla_version(product, origin_version, 'nightly'),
51 ]
52 }
53
54 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
55 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
56
57 def get_seamonkey_version(origin_version, origin_build, channel):
58 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
59 'aus2-community', origin_build, 'version')
60
61 def get_seamonkey_versions():
62 return {
63 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
64 'unreleased': [get_seamonkey_version('2.32', '20150101215737', 'beta')]
65 }
66
67 BROWSERS['seamonkey'] = get_seamonkey_versions
68
69 def get_chrome_version(manifest):
70 return manifest.getAttribute('version').split('.')[0]
71
72 def get_chrome_versions():
73 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
74 try:
75 doc = minidom.parse(response)
76 finally:
77 response.close()
78
79 manifests = doc.getElementsByTagName('manifest')
80 return {
81 'current': get_chrome_version(manifests[0]),
82 'unreleased': map(get_chrome_version, manifests[1:])
83 }
84
85 BROWSERS['chrome'] = get_chrome_versions
86
87 def get_opera_version(channel):
88 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
89 try:
90 spec = json.load(response)
91 finally:
92 response.close()
93
94 return re.search(r'\d+', spec['installer_filename']).group(0)
95
96 def get_opera_versions():
97 return {
98 'current': get_opera_version('Stable'),
99 'unreleased': [
100 get_opera_version('Beta'),
101 get_opera_version('Developer')
102 ]
103 }
104
105 BROWSERS['opera'] = get_opera_versions
106
107 def get_yandex_version(suffix):
108 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix)
109 try:
110 doc = minidom.parse(response)
111 finally:
112 response.close()
113
114 item = doc.getElementsByTagName('item')[0]
115 description = item.getElementsByTagName('description')[0]
116 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
117
118 def get_yandex_versions():
119 return {
120 'current': get_yandex_version(''),
121 'unreleased': [get_yandex_version('-beta')]
122 }
123
124 BROWSERS['yandex'] = get_yandex_versions
125
126 def open_cache_file(source):
127 cache_dir = source.get_cache_dir()
128 filename = os.path.join(cache_dir, 'browsers.json')
129 flags = os.O_RDWR | os.O_CREAT
130 try:
131 fd = os.open(filename, flags)
132 except OSError as e:
133 if e.errno != errno.ENOENT:
134 raise
135 os.makedirs(cache_dir)
136 fd = os.open(filename, flags)
137 return os.fdopen(fd, 'w+')
138
139 @contextfunction
140 def get_browser_versions(context, browser):
141 func = BROWSERS[browser]
142 exception = None
143 try:
144 versions = func()
145 except Exception as e:
146 exception = e
147
148 with open_cache_file(context['source']) 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 exception:
158 if not cached_versions:
159 raise exception
160
161 print >>sys.stderr, "Warning: Failed to get %s versions, falling back to c ached versions" % browser
162 return cached_versions
163
164 # Determine previous version: If we recorded the version before and it
165 # changed since then, the old current version becomes the new previous
166 # version. If the version didn't change, use the cached previous version.
167 current = versions['current']
168 if cached_versions:
169 cached_current = cached_versions['current']
170 if cached_current != current:
171 versions['previous'] = cached_current
172 else:
173 cached_previous = cached_versions.get('previous')
174 if cached_previous:
175 versions['previous'] = cached_previous
176
177 # Remove duplicated from unreleased versions. Occasionally,
178 # different channels are on the same version, but we want
179 # to list each version only once.
180 unreleased = versions['unreleased']
181 previous = versions.get('previous')
182 for i, version in list(enumerate(unreleased))[::-1]:
183 if version == current or previous and version == previous:
184 del unreleased[i]
185
186 cache[browser] = versions
187 file.seek(0)
188 json.dump(cache, file)
189 file.truncate()
190
191 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