Left: | ||
Right: |
OLD | NEW |
---|---|
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' | 14 BASE_URL = 'https://product-details.mozilla.org/1.0' |
15 FIREFOX_URL = BASE_URL + '/firefox_versions.json' | 15 FIREFOX_URL = BASE_URL + '/firefox_versions.json' |
16 THUNDERBIRD_URL = BASE_URL + '/thunderbird_versions.json' | 16 THUNDERBIRD_URL = BASE_URL + '/thunderbird_versions.json' |
17 SEAMONKEY_URL = 'http://www.seamonkey-project.org/seamonkey_versions.json' | 17 SEAMONKEY_URL = 'http://www.seamonkey-project.org/seamonkey_versions.json' |
18 | 18 CHROME_URL = 'https://omahaproxy.appspot.com/all.json?os=win' |
19 CHROME_UPDATE_XML = '''\ | |
20 <?xml version="1.0" encoding="UTF-8"?> | |
21 <request protocol="3.0" ismachine="0"> | |
22 <os platform="win" version="99" arch="x64"/> | |
23 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}"> | |
24 <updatecheck/> | |
25 </app> | |
26 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" > | |
27 <updatecheck/> | |
28 </app> | |
29 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome"> | |
30 <updatecheck/> | |
31 </app> | |
32 </request>''' | |
33 | 19 |
34 cache = {} | 20 cache = {} |
35 | 21 |
36 | 22 |
37 def get_json_versions(product_url): | 23 def get_json_versions(product_url): |
38 response = urllib.urlopen(product_url) | 24 response = urllib.urlopen(product_url) |
39 try: | 25 try: |
40 doc = json.load(response) | 26 doc = json.load(response) |
41 except json.ValueError: | 27 except json.ValueError: |
42 print 'URL: %s not returning json object'.format(product_url) | 28 print 'URL: %s not returning json object'.format(product_url) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'], | 72 seamonkey_versions['LATEST_SEAMONKEY_MILESTONE_VERSION'], |
87 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'], | 73 seamonkey_versions['LATEST_SEAMONKEY_DEVEL_VERSION'], |
88 ] | 74 ] |
89 } | 75 } |
90 | 76 |
91 return versions | 77 return versions |
92 | 78 |
93 BROWSERS['seamonkey'] = get_seamonkey_versions | 79 BROWSERS['seamonkey'] = get_seamonkey_versions |
94 | 80 |
95 | 81 |
96 def get_chrome_version(manifest): | 82 def get_chrome_version(version_info): |
97 return manifest.getAttribute('version').split('.')[0] | 83 return version_info['version'].split('.')[0] |
98 | 84 |
99 | 85 |
100 def get_chrome_versions(): | 86 def get_chrome_versions(): |
101 response = urllib.urlopen('https://tools.google.com/service/update2', CHROME _UPDATE_XML) | 87 response = urllib.urlopen(CHROME_URL) |
102 try: | 88 try: |
103 doc = minidom.parse(response) | 89 data = json.load(response) |
104 finally: | 90 finally: |
105 response.close() | 91 response.close() |
106 | 92 |
107 manifests = doc.getElementsByTagName('manifest') | 93 channels = {x['channel']: x for x in data[0]['versions']} |
Sebastian Noack
2017/08/14 11:54:31
It seems the logic can be simplified. All data we
tlucas
2017/08/14 12:08:28
Done.
| |
94 | |
108 return { | 95 return { |
109 'current': get_chrome_version(manifests[0]), | 96 'current': get_chrome_version(channels['stable']), |
110 'unreleased': map(get_chrome_version, manifests[1:]) | 97 'unreleased': map( |
98 get_chrome_version, | |
99 (channels['beta'], channels['dev']) | |
100 ), | |
111 } | 101 } |
112 | 102 |
113 BROWSERS['chrome'] = get_chrome_versions | 103 BROWSERS['chrome'] = get_chrome_versions |
114 | 104 |
115 | 105 |
116 def get_opera_version(channel): | 106 def get_opera_version(channel): |
117 response = urllib.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel) | 107 response = urllib.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel) |
118 try: | 108 try: |
119 spec = json.load(response) | 109 spec = json.load(response) |
120 finally: | 110 finally: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 file.seek(0) | 231 file.seek(0) |
242 json.dump(persistent_cache, file) | 232 json.dump(persistent_cache, file) |
243 file.truncate() | 233 file.truncate() |
244 | 234 |
245 if not versions['previous']: | 235 if not versions['previous']: |
246 logging.warning("Couldn't determine previous browser version, " | 236 logging.warning("Couldn't determine previous browser version, " |
247 'please set %s.previous in %s', browser, filename) | 237 'please set %s.previous in %s', browser, filename) |
248 | 238 |
249 cache[browser] = versions | 239 cache[browser] = versions |
250 return versions | 240 return versions |
OLD | NEW |