From a5a64158e976a43417995fd805abd08457cefb5d Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 19 Nov 2018 08:36:49 +0100 Subject: [PATCH] allow specifying multiple postmarketOS mirrors (!1718) Multiple -mp arguments can be used to list multiple mirrors: $ pmbootstrap -mp=first -mp=second chroot -- cat /etc/apk/repositories This is needed for the new build infrastructure, so we can have a WIP repository to which we push packages until all of them are up to date, and then publish all of them at once. Software like KDE/Plasma Mobile, which expect a lot of packages to be updated from one version to another will not end up with a half-way through upgrade that way. --- pmb/config/__init__.py | 2 +- pmb/helpers/args.py | 21 +++++++++++++++++++++ pmb/helpers/pkgrel_bump.py | 4 ++-- pmb/helpers/repo.py | 11 ++++++----- pmb/parse/arguments.py | 9 +++++---- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 74a15316..1cac3ea4 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -76,7 +76,7 @@ defaults = { "keymap": "", "log": "$WORK/log.txt", "mirror_alpine": "http://dl-cdn.alpinelinux.org/alpine/", - "mirror_postmarketos": "http://postmarketos.brixit.nl", + "mirrors_postmarketos": ["http://postmarketos.brixit.nl"], "nonfree_firmware": True, "nonfree_userland": False, "port_distccd": "33632", diff --git a/pmb/helpers/args.py b/pmb/helpers/args.py index 79d7a429..624c45da 100644 --- a/pmb/helpers/args.py +++ b/pmb/helpers/args.py @@ -82,6 +82,26 @@ import pmb.config """ +def fix_mirrors_postmarketos(args): + """ Fix args.mirrors_postmarketos when it is supposed to be empty or the + default value. + + In pmb/parse/arguments.py, we set the -mp/--mirror-pmOS argument to + action="append" and start off with an empty list. That way, users can + specify multiple custom mirrors by specifying -mp multiple times on the + command line. Here we fix the default and no mirrors case. + + NOTE: we don't use nargs="+", because it does not play nicely with + subparsers: """ + # -mp not specified: use default mirrors + if not args.mirrors_postmarketos: + args.mirrors_postmarketos = pmb.config.defaults["mirrors_postmarketos"] + + # -mp="": use no postmarketOS mirrors (build everything locally) + if args.mirrors_postmarketos == [""]: + args.mirrors_postmarketos = [] + + def check_pmaports_path(args): """ Make sure that args.aports exists when it was overridden by --aports. Without this check, 'pmbootstrap init' would start cloning the @@ -134,6 +154,7 @@ def add_deviceinfo(args): def init(args): # Basic initialization + fix_mirrors_postmarketos(args) pmb.config.merge_with_args(args) replace_variables(args) add_shortcuts(args) diff --git a/pmb/helpers/pkgrel_bump.py b/pmb/helpers/pkgrel_bump.py index d1f8f3da..40889085 100644 --- a/pmb/helpers/pkgrel_bump.py +++ b/pmb/helpers/pkgrel_bump.py @@ -76,9 +76,9 @@ def auto_apkindex_files(args): if os.path.exists(local): ret[arch].append(local) - if args.mirror_postmarketos: + for mirror in args.mirrors_postmarketos: path = (args.work + "/cache_apk_" + arch + "/APKINDEX." + - pmb.helpers.repo.hash(args.mirror_postmarketos) + ".tar.gz") + pmb.helpers.repo.hash(mirror) + ".tar.gz") ret[arch].append(path) return ret diff --git a/pmb/helpers/repo.py b/pmb/helpers/repo.py index 2ca1c5ca..8495b801 100644 --- a/pmb/helpers/repo.py +++ b/pmb/helpers/repo.py @@ -67,8 +67,9 @@ def urls(args, user_repository=True, postmarketos_mirror=True): ret.append("/mnt/pmbootstrap-packages") # Upstream postmarketOS binary repository - if postmarketos_mirror and args.mirror_postmarketos: - ret.append(args.mirror_postmarketos) + if postmarketos_mirror: + for mirror in args.mirrors_postmarketos: + ret.append(mirror) # Upstream Alpine Linux repositories directories = ["main", "community"] @@ -93,9 +94,9 @@ def apkindex_files(args, arch=None): # Upstream postmarketOS binary repository urls_todo = [] - mirror = args.mirror_postmarketos - if mirror: - urls_todo.append(mirror) + for mirror in args.mirrors_postmarketos: + if mirror: + urls_todo.append(mirror) # Resolve the APKINDEX.$HASH.tar.gz files urls_todo += urls(args, False, False) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index e02cf719..7bb58b82 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -260,6 +260,7 @@ def arguments(): parser = argparse.ArgumentParser(prog="pmbootstrap") arch_native = pmb.parse.arch.alpine_native() arch_choices = set(pmb.config.build_device_architectures + [arch_native]) + mirrors_pmos_default = pmb.config.defaults["mirrors_postmarketos"] # Other parser.add_argument("-V", "--version", action="version", @@ -269,11 +270,11 @@ def arguments(): parser.add_argument("-c", "--config", dest="config", default=pmb.config.defaults["config"]) parser.add_argument("-d", "--port-distccd", dest="port_distccd") - parser.add_argument("-mp", "--mirror-pmOS", dest="mirror_postmarketos", + parser.add_argument("-mp", "--mirror-pmOS", dest="mirrors_postmarketos", help="postmarketOS mirror, disable with: -mp=''," - " default: " + - pmb.config.defaults["mirror_postmarketos"], - metavar="URL") + " specify multiple with: -mp='one' -mp='two'," + " default: " + ", ".join(mirrors_pmos_default), + metavar="URL", action="append", default=[]) parser.add_argument("-m", "--mirror-alpine", dest="mirror_alpine", help="Alpine Linux mirror, default: " + pmb.config.defaults["mirror_alpine"],