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: Addressed comments Created April 30, 2015, 8:26 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:
Left: Side by side diff | Download
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
1 import re 1 import re
2 import os 2 import os
3 import sys 3 import sys
4 import json 4 import json
5 import urllib2 5 import urllib2
6 import errno 6 import errno
7 import logging
7 from xml.dom import minidom 8 from xml.dom import minidom
8 9
9 from jinja2 import contextfunction 10 from jinja2 import contextfunction
10 11
11 BROWSERS = {} 12 BROWSERS = {}
12 13
13 CHROME_UPDATE_XML = '''\ 14 CHROME_UPDATE_XML = '''\
14 <?xml version="1.0" encoding="UTF-8"?> 15 <?xml version="1.0" encoding="UTF-8"?>
15 <request protocol="3.0" ismachine="0"> 16 <request protocol="3.0" ismachine="0">
16 <os platform="win" version="99" arch="x64"/> 17 <os platform="win" version="99" arch="x64"/>
17 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}"> 18 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
18 <updatecheck/> 19 <updatecheck/>
19 </app> 20 </app>
20 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" > 21 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
21 <updatecheck/> 22 <updatecheck/>
22 </app> 23 </app>
23 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome"> 24 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
24 <updatecheck/> 25 <updatecheck/>
25 </app> 26 </app>
26 </request>''' 27 </request>'''
27 28
28 def get_mozilla_update(subdomain, product, version, build, channel): 29 def get_mozilla_version(product, origin_version, channel,
29 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, vers ion, build, 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 ))
30 try: 40 try:
31 doc = minidom.parse(response) 41 doc = minidom.parse(response)
32 finally: 42 finally:
33 response.close() 43 response.close()
34 44
35 return doc.getElementsByTagName('update')[0] 45 update = doc.getElementsByTagName('update')[0]
36 46 full_version = update.getAttribute(attribute)
37 def get_mozilla_version(product, version, channel): 47
38 update = get_mozilla_update('aus4', product, version, '-', channel) 48 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
39 return update.getAttribute('appVersion').split('.')[0] 49 if minor:
40 50 return match.group(0)
41 def get_mozilla_versions(product, version): 51 return match.group(1)
42 return { 52
43 'current': get_mozilla_version(product, version, 'release'), 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),
44 'unreleased': [ 56 'unreleased': [
45 get_mozilla_version(product, version, 'beta'), 57 get_mozilla_version(product, origin_version, 'beta'),
46 get_mozilla_version(product, version, 'aurora'), 58 get_mozilla_version(product, origin_version, 'aurora'),
47 get_mozilla_version(product, version, 'nightly'), 59 get_mozilla_version(product, origin_version, 'nightly'),
48 ] 60 ]
49 } 61 }
50 62
51 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0') 63 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
52 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0') 64 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
53 65
54 def get_seamonkey_version(channel, version, build): 66 def get_seamonkey_version(origin_version, origin_build, channel, **kw):
55 update = get_mozilla_update('aus2-community', 'SeaMonkey', version, build, cha nnel) 67 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
56 return re.search(r'^^\d+\.\d+', update.getAttribute('version')).group(0) 68 'aus2-community', origin_build, 'version', **kw)
57 69
58 def get_seamonkey_versions(): 70 def get_seamonkey_versions():
59 return { 71 return {
60 'current': get_seamonkey_version('release', '2.32', '20150112201917'), 72 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
61 'unreleased': [get_seamonkey_version('beta', '2.32', '20150101215737')] 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 ]
62 } 81 }
63 82
64 BROWSERS['seamonkey'] = get_seamonkey_versions 83 BROWSERS['seamonkey'] = get_seamonkey_versions
65 84
66 def get_chrome_version(manifest): 85 def get_chrome_version(manifest):
67 return manifest.getAttribute('version').split('.')[0] 86 return manifest.getAttribute('version').split('.')[0]
68 87
69 def get_chrome_versions(): 88 def get_chrome_versions():
70 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML)) 89 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML))
71 try: 90 try:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) 132 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
114 133
115 def get_yandex_versions(): 134 def get_yandex_versions():
116 return { 135 return {
117 'current': get_yandex_version(''), 136 'current': get_yandex_version(''),
118 'unreleased': [get_yandex_version('-beta')] 137 'unreleased': [get_yandex_version('-beta')]
119 } 138 }
120 139
121 BROWSERS['yandex'] = get_yandex_versions 140 BROWSERS['yandex'] = get_yandex_versions
122 141
123 def open_cache_file(source): 142 def open_cache_file(filename):
124 filename = os.path.join(source.get_cache_dir(), 'browsers.json')
125 flags = os.O_RDWR | os.O_CREAT 143 flags = os.O_RDWR | os.O_CREAT
126 try: 144 try:
127 fd = os.open(filename, flags) 145 fd = os.open(filename, flags)
128 except OSError as e: 146 except OSError as e:
129 if e.errno != errno.ENOENT: 147 if e.errno != errno.ENOENT:
130 raise 148 raise
131 os.makedirs(os.path.dirname(filename)) 149 os.makedirs(os.path.dirname(filename))
132 fd = os.open(filename, flags) 150 fd = os.open(filename, flags)
133 return os.fdopen(fd, 'w+') 151 return os.fdopen(fd, 'w+')
134 152
135 @contextfunction 153 @contextfunction
136 def get_browser_versions(context, browser): 154 def get_browser_versions(context, browser):
137 func = BROWSERS[browser] 155 func = BROWSERS[browser]
138 exception = None 156 exc_info = None
139 try: 157 try:
140 versions = func() 158 versions = func()
141 except Exception as e: 159 except Exception:
142 exception = e 160 exc_info = sys.exc_info()
143 161
144 with open_cache_file(context['source']) as file: 162 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
163 with open_cache_file(filename) as file:
145 try: 164 try:
146 cache = json.load(file) 165 cache = json.load(file)
147 except ValueError: 166 except ValueError:
148 if file.tell() > 0: 167 if file.tell() > 0:
149 raise 168 raise
150 cache = {} 169 cache = {}
151 170
152 cached_versions = cache.get(browser) 171 cached_versions = cache.get(browser)
153 if exception: 172 if exc_info:
154 if not cached_versions: 173 if not cached_versions:
155 raise exception 174 raise exc_info[0], exc_info[1], exc_info[2]
156 175
157 print >>sys.stderr, "Warning: Failed to get %s versions, falling back to c ached versions" % browser 176 versions = cached_versions
158 return cached_versions 177 logging.warning('Failed to get %s versions, falling back to '
159 178 'cached versions', browser, exc_info=exc_info)
160 # Determine previous version: If we recorded the version before and it 179 else:
161 # changed since then, the old current version becomes the new previous 180 # Determine previous version: If we recorded the version before and it
162 # version. If the version didn't change, use the cached previous version. 181 # changed since then, the old current version becomes the new previous
163 current = versions['current'] 182 # version. If the version didn't change, use the cached previous version.
164 if cached_versions: 183 current = versions['current']
165 cached_current = cached_versions['current'] 184 previous = None
166 if cached_current != current: 185 if cached_versions:
167 versions['previous'] = cached_current 186 cached_current = cached_versions['current']
168 else: 187 if cached_current != current:
169 cached_previous = cached_versions.get('previous') 188 previous = cached_current
170 if cached_previous: 189 else:
171 versions['previous'] = cached_previous 190 previous = cached_versions['previous']
172 191 versions['previous'] = previous
173 # Remove duplicated from unreleased versions. Occasionally, 192
174 # different channels are on the same version, but we want 193 # Remove duplicates from unreleased versions. Occasionally,
175 # to list each version only once. 194 # different channels are on the same version, but we want
176 unreleased = versions['unreleased'] 195 # to list each version only once.
177 previous = versions.get('previous') 196 versions['unreleased'] = sorted(
178 for i, version in list(enumerate(unreleased))[::-1]: 197 set(versions['unreleased']) - {current, previous},
179 if version == current or previous and version == previous: 198 key=lambda ver: map(int, ver.split('.'))
180 del unreleased[i] 199 )
181 200
182 cache[browser] = versions 201 cache[browser] = versions
183 file.seek(0) 202 file.seek(0)
184 json.dump(cache, file) 203 json.dump(cache, file)
185 file.truncate() 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)
186 209
187 return versions 210 return versions
LEFTRIGHT

Powered by Google App Engine
This is Rietveld