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: Include minor version number for Thunderbird releases Created April 30, 2015, 10:51 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_version(product, origin_version, channel, minor=False, 29 def get_mozilla_version(product, origin_version, channel,
29 subdomain='aus4', origin_build='-', attribute='appVersio n'): 30 minor=False, subdomain='aus4', origin_build='-',
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 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 ))
31 try: 40 try:
32 doc = minidom.parse(response) 41 doc = minidom.parse(response)
33 finally: 42 finally:
34 response.close() 43 response.close()
35 44
36 update = doc.getElementsByTagName('update')[0] 45 update = doc.getElementsByTagName('update')[0]
37 full_version = update.getAttribute(attribute) 46 full_version = update.getAttribute(attribute)
38 47
39 match = re.search(r'^(\d+)(?:\.\d+)?', full_version) 48 match = re.search(r'^(\d+)(?:\.\d+)?', full_version)
40 if minor: 49 if minor:
41 return match.group(0) 50 return match.group(0)
42 return match.group(1) 51 return match.group(1)
43 52
44 def get_mozilla_versions(product, origin_version, release_minor=False): 53 def get_mozilla_versions(product, origin_version, release_minor=False):
45 return { 54 return {
46 'current': get_mozilla_version(product, origin_version, 'release', release_m inor), 55 'current': get_mozilla_version(product, origin_version, 'release', release_m inor),
47 'unreleased': [ 56 'unreleased': [
48 get_mozilla_version(product, origin_version, 'beta'), 57 get_mozilla_version(product, origin_version, 'beta'),
49 get_mozilla_version(product, origin_version, 'aurora'), 58 get_mozilla_version(product, origin_version, 'aurora'),
50 get_mozilla_version(product, origin_version, 'nightly'), 59 get_mozilla_version(product, origin_version, 'nightly'),
51 ] 60 ]
52 } 61 }
53 62
54 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0') 63 BROWSERS['firefox'] = lambda: get_mozilla_versions('Firefox', '37.0')
55 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue) 64 BROWSERS['thunderbird'] = lambda: get_mozilla_versions('Thunderbird', '31.0', Tr ue)
56 65
57 def get_seamonkey_version(origin_version, origin_build, channel): 66 def get_seamonkey_version(origin_version, origin_build, channel, **kw):
58 return get_mozilla_version('SeaMonkey', origin_version, channel, True, 67 return get_mozilla_version('SeaMonkey', origin_version, channel, True,
59 'aus2-community', origin_build, 'version') 68 'aus2-community', origin_build, 'version', **kw)
60 69
61 def get_seamonkey_versions(): 70 def get_seamonkey_versions():
62 return { 71 return {
63 'current': get_seamonkey_version('2.32', '20150112201917', 'release'), 72 'current': get_seamonkey_version('2.32', '20150112201917', 'release'),
64 'unreleased': [get_seamonkey_version('2.32', '20150101215737', 'beta')] 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 ]
65 } 81 }
66 82
67 BROWSERS['seamonkey'] = get_seamonkey_versions 83 BROWSERS['seamonkey'] = get_seamonkey_versions
68 84
69 def get_chrome_version(manifest): 85 def get_chrome_version(manifest):
70 return manifest.getAttribute('version').split('.')[0] 86 return manifest.getAttribute('version').split('.')[0]
71 87
72 def get_chrome_versions(): 88 def get_chrome_versions():
73 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))
74 try: 90 try:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) 132 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
117 133
118 def get_yandex_versions(): 134 def get_yandex_versions():
119 return { 135 return {
120 'current': get_yandex_version(''), 136 'current': get_yandex_version(''),
121 'unreleased': [get_yandex_version('-beta')] 137 'unreleased': [get_yandex_version('-beta')]
122 } 138 }
123 139
124 BROWSERS['yandex'] = get_yandex_versions 140 BROWSERS['yandex'] = get_yandex_versions
125 141
126 def open_cache_file(source): 142 def open_cache_file(filename):
127 cache_dir = source.get_cache_dir()
128 filename = os.path.join(cache_dir, 'browsers.json')
129 flags = os.O_RDWR | os.O_CREAT 143 flags = os.O_RDWR | os.O_CREAT
130 try: 144 try:
131 fd = os.open(filename, flags) 145 fd = os.open(filename, flags)
132 except OSError as e: 146 except OSError as e:
133 if e.errno != errno.ENOENT: 147 if e.errno != errno.ENOENT:
134 raise 148 raise
135 os.makedirs(cache_dir) 149 os.makedirs(os.path.dirname(filename))
136 fd = os.open(filename, flags) 150 fd = os.open(filename, flags)
137 return os.fdopen(fd, 'w+') 151 return os.fdopen(fd, 'w+')
138 152
139 @contextfunction 153 @contextfunction
140 def get_browser_versions(context, browser): 154 def get_browser_versions(context, browser):
141 func = BROWSERS[browser] 155 func = BROWSERS[browser]
142 exception = None 156 exc_info = None
143 try: 157 try:
144 versions = func() 158 versions = func()
145 except Exception as e: 159 except Exception:
146 exception = e 160 exc_info = sys.exc_info()
147 161
148 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:
149 try: 164 try:
150 cache = json.load(file) 165 cache = json.load(file)
151 except ValueError: 166 except ValueError:
152 if file.tell() > 0: 167 if file.tell() > 0:
153 raise 168 raise
154 cache = {} 169 cache = {}
155 170
156 cached_versions = cache.get(browser) 171 cached_versions = cache.get(browser)
157 if exception: 172 if exc_info:
158 if not cached_versions: 173 if not cached_versions:
159 raise exception 174 raise exc_info[0], exc_info[1], exc_info[2]
160 175
161 print >>sys.stderr, "Warning: Failed to get %s versions, falling back to c ached versions" % browser 176 versions = cached_versions
162 return cached_versions 177 logging.warning('Failed to get %s versions, falling back to '
163 178 'cached versions', browser, exc_info=exc_info)
164 # Determine previous version: If we recorded the version before and it 179 else:
165 # changed since then, the old current version becomes the new previous 180 # Determine previous version: If we recorded the version before and it
166 # version. If the version didn't change, use the cached previous version. 181 # changed since then, the old current version becomes the new previous
167 current = versions['current'] 182 # version. If the version didn't change, use the cached previous version.
168 if cached_versions: 183 current = versions['current']
169 cached_current = cached_versions['current'] 184 previous = None
170 if cached_current != current: 185 if cached_versions:
171 versions['previous'] = cached_current 186 cached_current = cached_versions['current']
172 else: 187 if cached_current != current:
173 cached_previous = cached_versions.get('previous') 188 previous = cached_current
174 if cached_previous: 189 else:
175 versions['previous'] = cached_previous 190 previous = cached_versions['previous']
176 191 versions['previous'] = previous
177 # Remove duplicated from unreleased versions. Occasionally, 192
178 # different channels are on the same version, but we want 193 # Remove duplicates from unreleased versions. Occasionally,
179 # to list each version only once. 194 # different channels are on the same version, but we want
180 unreleased = versions['unreleased'] 195 # to list each version only once.
181 previous = versions.get('previous') 196 versions['unreleased'] = sorted(
182 for i, version in list(enumerate(unreleased))[::-1]: 197 set(versions['unreleased']) - {current, previous},
183 if version == current or previous and version == previous: 198 key=lambda ver: map(int, ver.split('.'))
184 del unreleased[i] 199 )
185 200
186 cache[browser] = versions 201 cache[browser] = versions
187 file.seek(0) 202 file.seek(0)
188 json.dump(cache, file) 203 json.dump(cache, file)
189 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)
190 209
191 return versions 210 return versions
LEFTRIGHT

Powered by Google App Engine
This is Rietveld