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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pages/requirements.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: globals/get_current_browser_versions.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/globals/get_current_browser_versions.py
@@ -0,0 +1,74 @@
+import re
+import json
+import urllib2
+from xml.dom import minidom
+
+import lxml.etree
+
+CHROME_UPDATE_XML = '''\
+<?xml version="1.0" encoding="UTF-8"?>
+<request protocol="3.0" ismachine="0">
+ <os platform="win" version="99" arch="x64"/>
+ <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}">
+ <updatecheck/>
+ </app>
+ <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-beta-multi-chrome">
+ <updatecheck/>
+ </app>
+ <app appid="{4DC8B4CA-1BDA-483E-B5FA-D3C12E15B62D}" ap="x64-dev-multi-chrome">
+ <updatecheck/>
+ </app>
+</request>'''
+
+def get_opera_version(channel):
Wladimir Palant 2015/04/29 17:16:55 Add this as inner function to get_opera_versions?
+ response = urllib2.urlopen('https://autoupdate.geo.opera.com/netinstaller/' + channel)
+ try:
+ spec = json.load(response)
+ finally:
+ response.close()
+
+ return int(re.search(r'\d+', spec['installer_filename']).group(0))
+
+class BrowserVersions:
+ def get_chrome_versions(self):
+ 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.
+ try:
+ doc = minidom.parse(response)
+ finally:
+ response.close()
+
+ versions = []
+ for manifest in doc.getElementsByTagName('manifest'):
+ versions.append(int(manifest.getAttribute('version').split('.')[0]))
+
+ 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.
+
+ def get_opera_versions(self):
+ stable_version = get_opera_version('Stable')
+
+ yield stable_version - 1 # previous
+ yield stable_version
+ yield get_opera_version('Beta')
+ yield get_opera_version('Developer')
+
+ def get_yandex_versions(self):
+ 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.
+ try:
+ doc = lxml.etree.parse(response, lxml.etree.HTMLParser())
+ finally:
+ response.close()
+
+ def version_by_color(color):
+ return doc.findall('//td[@bgcolor="%s"]' % color)[-1].text
+
+ yield version_by_color('salmon') # previous
+ yield version_by_color('#A0E75A') # stable
+ yield version_by_color('lightblue') # beta
+
+ def get_versions(self, browser):
+ versions = getattr(self, 'get_%s_versions' % browser)()
+ versions = {str(version) for version in versions}
+ versions = sorted(versions, key=lambda x: map(int, x.split('.')))
+ return versions
+
+get_current_browser_versions = BrowserVersions().get_versions
« 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