From ceb3acfa8b67ca1c4b255da7db96af972ccbe64e Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Thu, 10 Sep 2020 12:01:01 +0200 Subject: chromium: update.py: Keep the channel order consistent This makes Git diffs way easier to read. Using sort_keys=True is usually better but with this implementation the output is a bit nicer to read IMO. --- .../networking/browsers/chromium/update.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'pkgs/applications/networking') diff --git a/pkgs/applications/networking/browsers/chromium/update.py b/pkgs/applications/networking/browsers/chromium/update.py index 0a0d512004b54..bfc7f0d2478c3 100755 --- a/pkgs/applications/networking/browsers/chromium/update.py +++ b/pkgs/applications/networking/browsers/chromium/update.py @@ -4,9 +4,11 @@ import csv import json import subprocess +import sys + from codecs import iterdecode +from collections import OrderedDict from os.path import abspath, dirname -from sys import stderr from urllib.request import urlopen HISTORY_URL = 'https://omahaproxy.appspot.com/history?os=linux' @@ -27,7 +29,7 @@ def nix_prefetch_url(url, algo='sha256'): channels = {} last_channels = load_json(JSON_PATH) -print(f'GET {HISTORY_URL}', file=stderr) +print(f'GET {HISTORY_URL}', file=sys.stderr) with urlopen(HISTORY_URL) as resp: builds = csv.DictReader(iterdecode(resp, 'utf-8')) for build in builds: @@ -59,5 +61,17 @@ with urlopen(HISTORY_URL) as resp: channels[channel_name] = channel with open(JSON_PATH, 'w') as out: - json.dump(channels, out, indent=2) + def get_channel_key(item): + channel_name = item[0] + if channel_name == 'stable': + return 0 + elif channel_name == 'beta': + return 1 + elif channel_name == 'dev': + return 2 + else: + print(f'Error: Unexpected channel: {channel_name}', file=sys.stderr) + sys.exit(1) + sorted_channels = OrderedDict(sorted(channels.items(), key=get_channel_key)) + json.dump(sorted_channels, out, indent=2) out.write('\n') -- cgit 1.4.1