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: Fix regex, add error handling Created Aug. 16, 2016, 6:44 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_json_versions(product): 37 def get_json_versions(product_url):
34 urls = { 38 response = urllib.urlopen(product_url)
Vasily Kuznetsov 2016/08/22 17:51:55 This dict seems somewhat redundant here. Wouldn't
Jon Sonesen 2016/08/29 13:15:39 So rather than a constant dict just have the funct
35 'Firefox':
36 'https://product-details.mozilla.org/1.0/firefox_versions.json',
37 'Thunderbird':
38 'https://product-details.mozilla.org/1.0/thunderbird_versions.json',
39 'Seamonkey':
40 'http://www.seamonkey-project.org/seamonkey_versions.json'
41 }
42 response = urllib.urlopen(urls[product])
43 try: 39 try:
44 doc = json.load(response) 40 doc = json.load(response)
45 except json.ValueError: 41 except json.ValueError:
46 print 'URL: %s not returning json object'.format(urls[product]) 42 print 'URL: %s not returning json object'.format(product_url)
47 finally: 43 finally:
48 response.close() 44 response.close()
49 45
50 for key, value in doc.iteritems(): 46 for key, value in doc.iteritems():
51 if value: 47 if value:
52 doc[key] = re.search(r'^(\d+)(?:\.\d+)?', value).group(0) 48 match = re.search(r'^(\d+)(?:\.\d+)?', value)
Vasily Kuznetsov 2016/08/22 17:51:55 Isn't this a bit fragile? What if the regex doesn'
Jon Sonesen 2016/08/29 13:15:39 I agree that it is fragile...but also I thought we
49 if match:
50 doc[key] = match.group(0)
53 return doc 51 return doc
54 52
55 53
56 def get_firefox_versions(): 54 def get_firefox_versions():
57 versions = get_json_versions('Firefox') 55 versions = get_json_versions(FIREFOX_URL)
58 return { 56 return {
59 'current': versions['LATEST_FIREFOX_VERSION'], 57 'current': versions['LATEST_FIREFOX_VERSION'],
60 'unreleased': [ 58 'unreleased': [
61 versions['LATEST_FIREFOX_DEVEL_VERSION'], 59 versions['LATEST_FIREFOX_DEVEL_VERSION'],
Vasily Kuznetsov 2016/08/22 17:51:55 It would be nice to give more friendly error messa
Jon Sonesen 2016/08/29 13:15:39 I thought we decided not to so the build 'fails lo
62 versions['FIREFOX_AURORA'], 60 versions['FIREFOX_AURORA'],
63 versions['FIREFOX_NIGHTLY'], 61 versions['FIREFOX_NIGHTLY'],
64 ] 62 ]
65 } 63 }
66 64
67 65
68 def get_thunderbird_versions(): 66 def get_thunderbird_versions():
69 versions = get_json_versions('Thunderbird') 67 tbird_versions = get_json_versions(THUNDERBIRD_URL)
70 firefox_versions = get_json_versions('Firefox') 68 firefox_versions = get_json_versions(FIREFOX_URL)
71 return { 69 return {
72 'current': versions['LATEST_THUNDERBIRD_VERSION'], 70 'current': tbird_versions['LATEST_THUNDERBIRD_VERSION'],
73 'unreleased': [ 71 'unreleased': [
74 versions['LATEST_THUNDERBIRD_DEVEL_VERSION'], 72 tbird_versions['LATEST_THUNDERBIRD_DEVEL_VERSION'],
75 versions['LATEST_THUNDERBIRD_ALPHA'], 73 tbird_versions['LATEST_THUNDERBIRD_ALPHA_VERSION'],
Vasily Kuznetsov 2016/08/22 17:51:55 I think this should be LATEST_THUNDERBIRD_ALPHA_VE
Jon Sonesen 2016/08/29 13:15:39 you're right....dang haha
76 firefox_versions['FIREFOX_NIGHTLY'], 74 firefox_versions['FIREFOX_NIGHTLY'],
77 ] 75 ]
78 } 76 }
79 77
80 BROWSERS['firefox'] = lambda: get_firefox_versions() 78 BROWSERS['firefox'] = lambda: get_firefox_versions()
81 BROWSERS['thunderbird'] = lambda: get_thunderbird_versions() 79 BROWSERS['thunderbird'] = lambda: get_thunderbird_versions()
82 80
83 81
84 def get_seamonkey_versions(): 82 def get_seamonkey_versions():
85 seamonkey_versions = get_json_versions('Seamonkey') 83 seamonkey_versions = get_json_versions(SEAMONKEY_URL)
86 versions = { 84 versions = {
87 'current': seamonkey_versions['LATEST_SEAMONKEY_VERSION'], 85 'current': seamonkey_versions['LATEST_SEAMONKEY_VERSION'],
88 'unreleased': [ 86 'unreleased': [
89 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'], 87 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'],
90 seamonkey_versions['LATEST_SEAMONKEY_TESTING_VERSION'], 88 seamonkey_versions['LATEST_SEAMONKEY_TESTING_VERSION'],
91 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'], 89 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'],
92 ] 90 ]
93 } 91 }
94 92
95 return versions 93 return versions
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 file.seek(0) 243 file.seek(0)
246 json.dump(persistent_cache, file) 244 json.dump(persistent_cache, file)
247 file.truncate() 245 file.truncate()
248 246
249 if not versions['previous']: 247 if not versions['previous']:
250 logging.warning("Couldn't determine previous browser version, " 248 logging.warning("Couldn't determine previous browser version, "
251 'please set %s.previous in %s', browser, filename) 249 'please set %s.previous in %s', browser, filename)
252 250
253 cache[browser] = versions 251 cache[browser] = versions
254 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