From e458b1fdbc1517cfdbd1334c011020ff3f9ff901 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 30 Sep 2018 03:53:55 +0200 Subject: [PATCH] Add --offline flag Allow working offline with pmbootstrap, as long as all packages that are being used have already been downloaded. --- pmb/chroot/apk.py | 2 ++ pmb/chroot/apk_static.py | 2 ++ pmb/helpers/args.py | 3 ++- pmb/helpers/repo.py | 7 +++++++ pmb/parse/arguments.py | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pmb/chroot/apk.py b/pmb/chroot/apk.py index 223403fd..9b04a101 100644 --- a/pmb/chroot/apk.py +++ b/pmb/chroot/apk.py @@ -229,6 +229,8 @@ def install(args, packages, suffix="native", build=True): ["add"] + packages, ["del", ".pmbootstrap"]] for command in commands: + if args.offline: + command = ["--no-network"] + command pmb.chroot.root(args, ["apk", "--no-progress"] + command, suffix) diff --git a/pmb/chroot/apk_static.py b/pmb/chroot/apk_static.py index fe4811cc..c73271a5 100644 --- a/pmb/chroot/apk_static.py +++ b/pmb/chroot/apk_static.py @@ -181,4 +181,6 @@ def init(args): def run(args, parameters): + if args.offline: + parameters = ["--no-network"] + parameters pmb.helpers.run.root(args, [args.work + "/apk.static"] + parameters) diff --git a/pmb/helpers/args.py b/pmb/helpers/args.py index 14991498..e435d254 100644 --- a/pmb/helpers/args.py +++ b/pmb/helpers/args.py @@ -115,7 +115,8 @@ def add_cache(args): "apk_min_version_checked": [], "apk_repository_list_updated": [], "built": {}, - "find_aport": {}}) + "find_aport": {}, + "offline_msg_shown": False}) def add_deviceinfo(args): diff --git a/pmb/helpers/repo.py b/pmb/helpers/repo.py index 18785799..9965907e 100644 --- a/pmb/helpers/repo.py +++ b/pmb/helpers/repo.py @@ -118,6 +118,13 @@ def update(args, arch=None, force=False, existing_only=False): :returns: True when files have been downloaded, False otherwise """ + # Skip in offline mode, only show once + if args.offline: + if not args.cache["offline_msg_shown"]: + logging.info("NOTE: skipping package index update (offline mode)") + args.cache["offline_msg_shown"] = True + return False + # Architectures and retention time architectures = [arch] if arch else pmb.config.build_device_architectures retention_hours = pmb.config.apkindex_retention_time diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index c84cc560..fd610003 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -281,6 +281,8 @@ def arguments(): " recommended, may screw up your work folders" " directory permissions!)", dest="as_root", action="store_true") + parser.add_argument("-o", "--offline", help="Do not attempt to update" + " the package index files", action="store_true") # Compiler parser.add_argument("--ccache-disable", action="store_false",