summary refs log tree commit diff
path: root/pkgs/os-specific/linux/chromium-os
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-12-17 17:07:40 +0000
committerAlyssa Ross <hi@alyssa.is>2019-12-17 17:07:40 +0000
commita769353d5fd4ccd70be3b196c945c9c25e3493be (patch)
treec1cfc655d0cb88d8bf11e5ee20be0b22c766765a /pkgs/os-specific/linux/chromium-os
parent752c156cab8604d0491f266cfb30020713ec4cbc (diff)
downloadnixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar.gz
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar.bz2
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar.lz
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar.xz
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.tar.zst
nixpkgs-a769353d5fd4ccd70be3b196c945c9c25e3493be.zip
chromiumOSPackages: 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.
Diffstat (limited to 'pkgs/os-specific/linux/chromium-os')
-rwxr-xr-xpkgs/os-specific/linux/chromium-os/update.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/pkgs/os-specific/linux/chromium-os/update.py b/pkgs/os-specific/linux/chromium-os/update.py
index 136321e078e..0ae7e8badaa 100755
--- a/pkgs/os-specific/linux/chromium-os/update.py
+++ b/pkgs/os-specific/linux/chromium-os/update.py
@@ -1,15 +1,14 @@
 #! /usr/bin/env nix-shell
-#! nix-shell -p python3 -i python
+#! nix-shell -i python -p "python3.withPackages (ps: with ps; [ lxml ])"
 
 import base64
-import csv
 import json
 import subprocess
-import xml.etree.ElementTree as ElementTree
 from codecs import iterdecode
-from operator import itemgetter
 from os import scandir
 from os.path import dirname, splitext
+from lxml import etree
+from lxml.etree import HTMLParser
 from re import MULTILINE, fullmatch, match, search
 from urllib.request import urlopen
 
@@ -37,13 +36,20 @@ buildspecs_url = f'{manifest_versions}/+/refs/heads/master/paladin/buildspecs/'
 # branch branches are used for fixes for specific devices.  So for
 # Chromium OS they will always be 0.  This is a best guess, and is not
 # documented.
-with urlopen('https://cros-omahaproxy.appspot.com/all') as resp:
-    versions = csv.DictReader(iterdecode(resp, 'utf-8'))
-    stables = filter(lambda v: v['track'] == 'stable-channel', versions)
-    stable = sorted(stables, key=itemgetter('chrome_version'), reverse=True)[0]
+with urlopen('https://cros-updates-serving.appspot.com/') as resp:
+    document = etree.parse(resp, HTMLParser())
 
-chrome_major_version = match(r'\d+', stable['chrome_version'])[0]
-chromeos_tip_build = match(r'\d+', stable['chromeos_version'])[0]
+    # bgcolor="lightgreen" is set on the most up-to-date version for
+    # each channel, so find a lightgreen cell in the "Stable" column.
+    (platform_version, chrome_version) = document.xpath("""
+        (//table[@id="cros-updates"]/tr/td[1 + count(
+            //table[@id="cros-updates"]/thead/tr[1]/th[text() = "Stable"]
+            /preceding-sibling::*)
+        ][@bgcolor="lightgreen"])[1]/text()
+    """)
+
+chrome_major_version = match(r'\d+', chrome_version)[0]
+chromeos_tip_build = match(r'\d+', platform_version)[0]
 
 # Find the most recent buildspec for the stable Chrome version and
 # Chromium OS build number.  Its branch build and branch branch build
@@ -62,8 +68,8 @@ revisions = {}
 
 # Read the buildspec, and extract the git revisions for each component.
 with urlopen(f'{buildspecs_url}{chrome_major_version}/{buildspec}.xml?format=TEXT') as resp:
-    xml = base64.decodebytes(resp.read()).decode('utf-8')
-    root = ElementTree.fromstring(xml)
+    xml = base64.decodebytes(resp.read())
+    root = etree.fromstring(xml)
     for project in root.findall('project'):
         revisions[project.get('name')] = project.get('revision')