gnome3: add updateScript

This commit is contained in:
Jan Tojnar 2017-12-25 10:46:52 +01:00
parent b0a57be4fe
commit cc1d6fcbcb
No known key found for this signature in database
GPG key ID: 7FAB2A15F7A607A4
3 changed files with 76 additions and 1 deletions

View file

@ -1,4 +1,4 @@
{ pkgs }:
{ pkgs, lib }:
let
@ -13,6 +13,12 @@ let
callPackage = pkgs.newScope self;
# Convert a version to branch (3.26.18 → 3.26)
# Used for finding packages on GNOME mirrors
versionBranch = version: builtins.concatStringsSep "." (lib.take 2 (lib.splitString "." version));
updateScript = callPackage ./update.nix { };
version = "3.26";
maintainers = with pkgs.lib.maintainers; [ lethalman jtojnar ];

View file

@ -0,0 +1,58 @@
import argparse
import json
import requests
import sys
def version_to_list(version):
return list(map(int, version.split('.')))
def odd_unstable(version_str, selected):
version = version_to_list(version_str)
if len(version) < 2:
return True
even = version[1] % 2 == 0
if selected == 'stable':
return even
else:
return not even
def no_policy(version, selected):
return True
version_policies = {
'odd-unstable': odd_unstable,
'none': no_policy,
}
def make_version_policy(version_predicate, selected):
return lambda version: version_predicate(version, selected)
parser = argparse.ArgumentParser(description='Find latest version for a GNOME package by crawling their release server.')
parser.add_argument('package-name', help='Name of the directory in https://ftp.gnome.org/pub/GNOME/sources/ containing the package.')
parser.add_argument('version-policy', help='Policy determining which versions are considered stable. For most GNOME packages, odd minor versions are unstable but there are exceptions.', choices=version_policies.keys(), nargs='?', default='odd-unstable')
parser.add_argument('requested-release', help='Most of the time, we will want to update to stable version but sometimes it is useful to test.', choices=['stable', 'unstable'], nargs='?', default='stable')
if __name__ == '__main__':
args = parser.parse_args()
package_name = getattr(args, 'package-name')
requested_release = getattr(args, 'requested-release')
version_predicate = version_policies[getattr(args, 'version-policy')]
version_policy = make_version_policy(version_predicate, requested_release)
# The structure of cache.json: https://gitlab.gnome.org/Infrastructure/sysadmin-bin/blob/master/ftpadmin#L762
cache = json.loads(requests.get('https://ftp.gnome.org/pub/GNOME/sources/{}/cache.json'.format(package_name)).text)
if type(cache) != list or cache[0] != 4:
print('Unknown format of cache.json file.', file=sys.stderr)
sys.exit(1)
versions = cache[2][package_name]
versions = sorted(filter(version_policy, versions), key=version_to_list)
if len(versions) == 0:
print('No versions matched.', file=sys.stderr)
sys.exit(1)
print(versions[-1])

View file

@ -0,0 +1,11 @@
{ lib, writeScript, python3, common-updater-scripts, coreutils, gnugrep, gnused }:
{ packageName, attrPath ? packageName, versionPolicy ? "odd-unstable" }:
let
python = python3.withPackages (p: [ p.requests ]);
in writeScript "update-${packageName}" ''
set -o errexit
PATH=${lib.makeBinPath [ common-updater-scripts coreutils gnugrep gnused python ]}
latest_tag=$(python "${./find-latest-version.py}" "${packageName}" "${versionPolicy}" "stable")
update-source-version "${attrPath}" "$latest_tag"
''