Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: globals/get_browser_versions.py

Issue 29348818: issue 4087 - Use Mozilla's product-details data to determine current product versions (Closed)
Left Patch Set: Replace update server calls with json request Created July 28, 2016, 7:45 p.m.
Right Patch Set: fixed problems with commas and long line...sorry for the mistake Created Aug. 30, 2016, 9:14 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 | « no previous file | no next file » | 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 urllib 5 import urllib
6 import errno 6 import errno
7 import logging 7 import logging
8 import time 8 import time
9 from xml.dom import minidom 9 from xml.dom import minidom
10 10
11 from jinja2 import contextfunction 11 from jinja2 import contextfunction
12 12
13 BROWSERS = {} 13 BROWSERS = {}
14 BASE_URL = 'https://product-details.mozilla.org/1.0'
15 FIREFOX_URL = BASE_URL + '/firefox_versions.json'
16 THUNDERBIRD_URL = BASE_URL + '/thunderbird_versions.json'
17 SEAMONKEY_URL = 'http://www.seamonkey-project.org/seamonkey_versions.json'
14 18
15 CHROME_UPDATE_XML = '''\ 19 CHROME_UPDATE_XML = '''\
16 <?xml version="1.0" encoding="UTF-8"?> 20 <?xml version="1.0" encoding="UTF-8"?>
17 <request protocol="3.0" ismachine="0"> 21 <request protocol="3.0" ismachine="0">
18 <os platform="win" version="99" arch="x64"/> 22 <os platform="win" version="99" arch="x64"/>
19 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}"> 23 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
20 <updatecheck/> 24 <updatecheck/>
21 </app> 25 </app>
22 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" > 26 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
23 <updatecheck/> 27 <updatecheck/>
24 </app> 28 </app>
25 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome"> 29 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
26 <updatecheck/> 30 <updatecheck/>
27 </app> 31 </app>
28 </request>''' 32 </request>'''
29 33
30 cache = {} 34 cache = {}
31 35
32 36
33 def get_firefox_version(): 37 def get_json_versions(product_url):
34 url = 'https://product-details.mozilla.org/firefox_versions.json' 38 response = urllib.urlopen(product_url)
35 response = urllib.urlopen(url) 39 try:
36 try: 40 doc = json.load(response)
37 doc = json.loads(response.read()) 41 except json.ValueError:
Sebastian Noack 2016/08/01 16:21:07 Any reason you cannot parse the response lazily?
38 finally: 42 print 'URL: %s not returning json object'.format(product_url)
39 response.close() 43 finally:
44 response.close()
45
46 for key, value in doc.iteritems():
47 if value:
48 match = re.search(r'^(\d+)(?:\.\d+)?', value)
49 if match:
50 doc[key] = match.group(0)
40 return doc 51 return doc
41 52
42 53
43 def get_firefox_versions(): 54 def get_firefox_versions():
44 versions = get_firefox_version() 55 versions = get_json_versions(FIREFOX_URL)
45 return { 56 return {
46 'current': versions['LATEST_FIREFOX_VERSION'], 57 'current': versions['LATEST_FIREFOX_VERSION'],
47 'unreleased': [ 58 'unreleased': [
48 versions['LATEST_FIREFOX_DEVEL_VERSION'], 59 versions['LATEST_FIREFOX_DEVEL_VERSION'],
49 versions['FIREFOX_AURORA'], 60 versions['FIREFOX_AURORA'],
50 versions['FIREFOX_NIGHTLY'], 61 versions['FIREFOX_NIGHTLY'],
51 ] 62 ]
52 } 63 }
53 64
54 65
55 def get_thunderbird_version():
56 url = 'https://product-details.mozilla.org/thunderbird_versions.json'
57 response = urllib.urlopen(url)
58 try:
59 doc = json.loads(response.read())
60 finally:
61 response.close()
62 return doc
63
64
65 def get_thunderbird_versions(): 66 def get_thunderbird_versions():
66 versions = get_thunderbird_version() 67 tbird_versions = get_json_versions(THUNDERBIRD_URL)
67 firefox_versions = get_firefox_version() 68 firefox_versions = get_json_versions(FIREFOX_URL)
68 return { 69 return {
69 'current': versions['LATEST_THUNDERBIRD_VERSION'], 70 'current': tbird_versions['LATEST_THUNDERBIRD_VERSION'],
70 'unreleased': [ 71 'unreleased': [
71 versions['LATEST_THUNDERBIRD_DEVEL_VERSION'], 72 tbird_versions['LATEST_THUNDERBIRD_DEVEL_VERSION'],
72 firefox_versions['FIREFOX_AURORA'], 73 tbird_versions['LATEST_THUNDERBIRD_ALPHA_VERSION'],
73 firefox_versions['FIREFOX_NIGHTLY'], 74 firefox_versions['FIREFOX_NIGHTLY'],
74 ] 75 ]
75 } 76 }
76 77
77 BROWSERS['firefox'] = lambda: get_firefox_versions() 78 BROWSERS['firefox'] = lambda: get_firefox_versions()
78 BROWSERS['thunderbird'] = lambda: get_thunderbird_versions() 79 BROWSERS['thunderbird'] = lambda: get_thunderbird_versions()
79 80
80 81
81 def get_seamonkey_version():
Sebastian Noack 2016/08/01 16:21:07 This code duplication isn't great. How about, inst
82 url = 'http://www.seamonkey-project.org/seamonkey_versions.json'
83 response = urllib.urlopen(url)
84 try:
85 doc = json.loads(response.read())
86 finally:
87 response.close()
88 return doc
89
90
91 def get_seamonkey_versions(): 82 def get_seamonkey_versions():
92 # Aurora and Nightly builds for Windows are permantently broken. 83 seamonkey_versions = get_json_versions(SEAMONKEY_URL)
93 # Occasionally, builds for other platforms are broken as well.
94 # https://bugzilla.mozilla.org/show_bug.cgi?id=1086553
95 seamonkey_versions = get_seamonkey_version()
96 versions = { 84 versions = {
97 'current': seamonkey_versions['LATEST_SEAMONKEY_VERSION'], 85 'current': seamonkey_versions['LATEST_SEAMONKEY_VERSION'],
98 'unreleased': [ 86 'unreleased': [
99 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'],
100 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'], 87 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'],
101 seamonkey_versions['LATEST_SEAMONKEY_TESTING_VERSION'], 88 seamonkey_versions['LATEST_SEAMONKEY_TESTING_VERSION'],
89 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'],
102 ] 90 ]
103 } 91 }
104 92
105 return versions 93 return versions
106 94
107 BROWSERS['seamonkey'] = get_seamonkey_versions 95 BROWSERS['seamonkey'] = get_seamonkey_versions
108 96
109 97
110 def get_chrome_version(manifest): 98 def get_chrome_version(manifest):
111 return manifest.getAttribute('version').split('.')[0] 99 return manifest.getAttribute('version').split('.')[0]
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 file.seek(0) 243 file.seek(0)
256 json.dump(persistent_cache, file) 244 json.dump(persistent_cache, file)
257 file.truncate() 245 file.truncate()
258 246
259 if not versions['previous']: 247 if not versions['previous']:
260 logging.warning("Couldn't determine previous browser version, " 248 logging.warning("Couldn't determine previous browser version, "
261 'please set %s.previous in %s', browser, filename) 249 'please set %s.previous in %s', browser, filename)
262 250
263 cache[browser] = versions 251 cache[browser] = versions
264 return versions 252 return versions
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld