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

Side by Side Diff: globals/get_browser_versions.py

Issue 4843664727605248: Issue 2576 - Use urllib instead urllib2 which isn't bundled with runserver.exe (Closed)
Patch Set: Created May 22, 2015, 2:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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 14
15 CHROME_UPDATE_XML = '''\ 15 CHROME_UPDATE_XML = '''\
16 <?xml version="1.0" encoding="UTF-8"?> 16 <?xml version="1.0" encoding="UTF-8"?>
17 <request protocol="3.0" ismachine="0"> 17 <request protocol="3.0" ismachine="0">
18 <os platform="win" version="99" arch="x64"/> 18 <os platform="win" version="99" arch="x64"/>
19 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}"> 19 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
20 <updatecheck/> 20 <updatecheck/>
21 </app> 21 </app>
22 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" > 22 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
23 <updatecheck/> 23 <updatecheck/>
24 </app> 24 </app>
25 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome"> 25 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
26 <updatecheck/> 26 <updatecheck/>
27 </app> 27 </app>
28 </request>''' 28 </request>'''
29 29
30 cache = {} 30 cache = {}
31 31
32 def get_mozilla_version(product, origin_version, channel, 32 def get_mozilla_version(product, origin_version, channel,
33 minor=False, subdomain='aus4', origin_build='-', 33 minor=False, subdomain='aus4', origin_build='-',
34 attribute='appVersion', platform='WINNT_x86-msvc'): 34 attribute='appVersion', platform='WINNT_x86-msvc'):
35 response = urllib2.urlopen('https://%s.mozilla.org/update/3/%s/%s/%s/%s/en-US/ %s/-/default/default/update.xml?force=1' % ( 35 response = urllib.urlopen('https://%s.mozilla.org/update/3/%s/%s/%s/%s/en-US/% s/-/default/default/update.xml?force=1' % (
36 subdomain, 36 subdomain,
37 product, 37 product,
38 origin_version, 38 origin_version,
39 origin_build, 39 origin_build,
40 platform, 40 platform,
41 channel 41 channel
42 )) 42 ))
43 try: 43 try:
44 doc = minidom.parse(response) 44 doc = minidom.parse(response)
45 finally: 45 finally:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 versions['unreleased'].append(version) 87 versions['unreleased'].append(version)
88 88
89 return versions 89 return versions
90 90
91 BROWSERS['seamonkey'] = get_seamonkey_versions 91 BROWSERS['seamonkey'] = get_seamonkey_versions
92 92
93 def get_chrome_version(manifest): 93 def get_chrome_version(manifest):
94 return manifest.getAttribute('version').split('.')[0] 94 return manifest.getAttribute('version').split('.')[0]
95 95
96 def get_chrome_versions(): 96 def get_chrome_versions():
97 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service/u pdate2', CHROME_UPDATE_XML)) 97 response = urllib.urlopen('https://tools.google.com/service/update2', CHROME_U PDATE_XML)
98 try: 98 try:
99 doc = minidom.parse(response) 99 doc = minidom.parse(response)
100 finally: 100 finally:
101 response.close() 101 response.close()
102 102
103 manifests = doc.getElementsByTagName('manifest') 103 manifests = doc.getElementsByTagName('manifest')
104 return { 104 return {
105 'current': get_chrome_version(manifests[0]), 105 'current': get_chrome_version(manifests[0]),
106 'unreleased': map(get_chrome_version, manifests[1:]) 106 'unreleased': map(get_chrome_version, manifests[1:])
107 } 107 }
108 108
109 BROWSERS['chrome'] = get_chrome_versions 109 BROWSERS['chrome'] = get_chrome_versions
110 110
111 def get_opera_version(channel): 111 def get_opera_version(channel):
112 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel) 112 response = urllib.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + c hannel)
113 try: 113 try:
114 spec = json.load(response) 114 spec = json.load(response)
115 finally: 115 finally:
116 response.close() 116 response.close()
117 117
118 return re.search(r'\d+', spec['installer_filename']).group(0) 118 return re.search(r'\d+', spec['installer_filename']).group(0)
119 119
120 def get_opera_versions(): 120 def get_opera_versions():
121 return { 121 return {
122 'current': get_opera_version('Stable'), 122 'current': get_opera_version('Stable'),
123 'unreleased': [ 123 'unreleased': [
124 get_opera_version('Beta'), 124 get_opera_version('Beta'),
125 get_opera_version('Developer') 125 get_opera_version('Developer')
126 ] 126 ]
127 } 127 }
128 128
129 BROWSERS['opera'] = get_opera_versions 129 BROWSERS['opera'] = get_opera_versions
130 130
131 def get_yandex_version(suffix): 131 def get_yandex_version(suffix):
132 response = urllib2.urlopen('https://api.browser.yandex.ru/update-info/browser/ yandex%s/win-yandex.xml' % suffix) 132 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y andex%s/win-yandex.xml' % suffix)
133 try: 133 try:
134 doc = minidom.parse(response) 134 doc = minidom.parse(response)
135 finally: 135 finally:
136 response.close() 136 response.close()
137 137
138 item = doc.getElementsByTagName('item')[0] 138 item = doc.getElementsByTagName('item')[0]
139 description = item.getElementsByTagName('description')[0] 139 description = item.getElementsByTagName('description')[0]
140 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) 140 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0)
141 141
142 def get_yandex_versions(): 142 def get_yandex_versions():
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 file.seek(0) 217 file.seek(0)
218 json.dump(persistent_cache, file) 218 json.dump(persistent_cache, file)
219 file.truncate() 219 file.truncate()
220 220
221 if not versions['previous']: 221 if not versions['previous']:
222 logging.warning("Couldn't determine previous browser version, " 222 logging.warning("Couldn't determine previous browser version, "
223 'please set %s.previous in %s', browser, filename) 223 'please set %s.previous in %s', browser, filename)
224 224
225 cache[browser] = versions 225 cache[browser] = versions
226 return versions 226 return versions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld