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

Side by Side Diff: globals/get_current_browser_versions.py

Issue 6702768332996608: Issue 2432 - Auto-generate browser versions on requirements page (Closed)
Patch Set: Created April 29, 2015, 1:16 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 | pages/requirements.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import re
2 import json
3 import urllib2
4 from xml.dom import minidom
5
6 import lxml.etree
7
8 CHROME_UPDATE_XML = '''\
9 <?xml version="1.0" encoding="UTF-8"?>
10 <request protocol="3.0" ismachine="0">
11 <os platform="win" version="99" arch="x64"/>
12 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
13 <updatecheck/>
14 </app>
15 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome" >
16 <updatecheck/>
17 </app>
18 <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
19 <updatecheck/>
20 </app>
21 </request>'''
22
23 def get_opera_version(channel):
Wladimir Palant 2015/04/29 17:16:55 Add this as inner function to get_opera_versions?
24 response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
25 try:
26 spec = json.load(response)
27 finally:
28 response.close()
29
30 return int(re.search(r'\d+', spec['installer_filename']).group(0))
31
32 class BrowserVersions:
33 def get_chrome_versions(self):
34 response = urllib2.urlopen(urllib2.Request('https://tools.google.com/service /update2', CHROME_UPDATE_XML))
Wladimir Palant 2015/04/29 17:16:55 From experience, this will fail regularly. Current
Sebastian Noack 2015/04/30 11:52:46 Done.
35 try:
36 doc = minidom.parse(response)
37 finally:
38 response.close()
39
40 versions = []
41 for manifest in doc.getElementsByTagName('manifest'):
42 versions.append(int(manifest.getAttribute('version').split('.')[0]))
43
44 return [min(versions) - 1] + versions
Wladimir Palant 2015/04/29 17:16:55 I think that hardcoding this here is very suboptim
Sebastian Noack 2015/04/30 11:52:46 Done.
45
46 def get_opera_versions(self):
47 stable_version = get_opera_version('Stable')
48
49 yield stable_version - 1 # previous
50 yield stable_version
51 yield get_opera_version('Beta')
52 yield get_opera_version('Developer')
53
54 def get_yandex_versions(self):
55 response = urllib2.urlopen('https://ru.wikipedia.org/wiki/%D0%AF%D0%BD%D0%B4 %D0%B5%D0%BA%D1%81.%D0%91%D1%80%D0%B0%D1%83%D0%B7%D0%B5%D1%80')
Wladimir Palant 2015/04/29 17:16:55 Please use https://api.browser.yandex.ru/update-in
Sebastian Noack 2015/04/30 11:52:46 Done.
56 try:
57 doc = lxml.etree.parse(response, lxml.etree.HTMLParser())
58 finally:
59 response.close()
60
61 def version_by_color(color):
62 return doc.findall('//td[@bgcolor="%s"]' % color)[-1].text
63
64 yield version_by_color('salmon') # previous
65 yield version_by_color('#A0E75A') # stable
66 yield version_by_color('lightblue') # beta
67
68 def get_versions(self, browser):
69 versions = getattr(self, 'get_%s_versions' % browser)()
70 versions = {str(version) for version in versions}
71 versions = sorted(versions, key=lambda x: map(int, x.split('.')))
72 return versions
73
74 get_current_browser_versions = BrowserVersions().get_versions
OLDNEW
« no previous file with comments | « no previous file | pages/requirements.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld