crosvm.updateScript: use more stable update source

It has been explained to me that cros-omahaproxy reports which
versions are available to users, while cros-updates-serving reports
the latest builds available for each channel. The latter is probably
better for our use case anyway, and apparently, while both aren't
officially supported, is less likely to randomly break.

So let's use that instead, even if it is much more annoying to parse.

+18 -12
+18 -12
pkgs/applications/virtualization/crosvm/update.py
··· 1 1 #! /usr/bin/env nix-shell 2 - #! nix-shell -p python3 -p nix-prefetch-git -i python 2 + #! nix-shell -p nix-prefetch-git "python3.withPackages (ps: with ps; [ lxml ])" 3 + #! nix-shell -i python 3 4 4 5 import base64 5 - import csv 6 6 import json 7 7 import re 8 8 import subprocess 9 - import xml.etree.ElementTree as ElementTree 10 9 from codecs import iterdecode 11 - from operator import itemgetter 12 10 from os.path import dirname, splitext 11 + from lxml import etree 12 + from lxml.etree import HTMLParser 13 13 from urllib.request import urlopen 14 14 15 15 # ChromiumOS components required to build crosvm. ··· 27 27 # branch branches are used for fixes for specific devices. So for 28 28 # Chromium OS they will always be 0. This is a best guess, and is not 29 29 # documented. 30 - with urlopen('https://cros-omahaproxy.appspot.com/all') as resp: 31 - versions = csv.DictReader(iterdecode(resp, 'utf-8')) 32 - stables = filter(lambda v: v['track'] == 'stable-channel', versions) 33 - stable = sorted(stables, key=itemgetter('chrome_version'), reverse=True)[0] 30 + with urlopen('https://cros-updates-serving.appspot.com/') as resp: 31 + document = etree.parse(resp, HTMLParser()) 32 + # bgcolor="lightgreen" is set on the most up-to-date version for 33 + # each channel, so find a lightgreen cell in the "Stable" column. 34 + (platform_version, chrome_version) = document.xpath(""" 35 + (//table[@id="cros-updates"]/tr/td[1 + count( 36 + //table[@id="cros-updates"]/thead/tr[1]/th[text() = "Stable"] 37 + /preceding-sibling::*) 38 + ][@bgcolor="lightgreen"])[1]/text() 39 + """) 34 40 35 - chrome_major_version = re.match(r'\d+', stable['chrome_version'])[0] 36 - chromeos_tip_build = re.match(r'\d+', stable['chromeos_version'])[0] 41 + chrome_major_version = re.match(r'\d+', chrome_version)[0] 42 + chromeos_tip_build = re.match(r'\d+', platform_version)[0] 37 43 38 44 # Find the most recent buildspec for the stable Chrome version and 39 45 # Chromium OS build number. Its branch build and branch branch build ··· 52 58 53 59 # Read the buildspec, and extract the git revisions for each component. 54 60 with urlopen(f'{buildspecs_url}{chrome_major_version}/{buildspec}.xml?format=TEXT') as resp: 55 - xml = base64.decodebytes(resp.read()).decode('utf-8') 56 - root = ElementTree.fromstring(xml) 61 + xml = base64.decodebytes(resp.read()) 62 + root = etree.fromstring(xml) 57 63 for project in root.findall('project'): 58 64 revisions[project.get('name')] = project.get('revision') 59 65