From 32ad868cdc67286482a7aee7b3167b0d23b04e99 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 9 Jun 2017 18:01:39 +0200 Subject: [PATCH] apk.installed(): Retuns all packages and versions now pmb.chroot.apk.installed() used to return only the explicitly installed packages. This is not good enough for the initfs check functions (and especially for the "lazy reproducible builds", from which branch this commit was cherry picked). This commit introduces more noise for the logfile - if this becomes a problem, raise your voice in the issues tracker and we'll do something about it. (This commit also changes minor code styling in other files, I did not run autopep8 last time, because flake8 didn't complain...) --- pmb/chroot/apk.py | 23 +++++++++++++++-------- pmb/install/install.py | 3 ++- pmb/parse/arguments.py | 10 ++++++++-- pmb/parse/other.py | 35 +++++++++++++++++++++++++++++++++++ pmbootstrap.py | 4 ++-- 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 pmb/parse/other.py diff --git a/pmb/chroot/apk.py b/pmb/chroot/apk.py index 61fd25f6..30f9a92d 100644 --- a/pmb/chroot/apk.py +++ b/pmb/chroot/apk.py @@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ import logging -import os import pmb.chroot import pmb.parse.apkindex +import pmb.parse.other def install(args, packages, suffix="native", build=True): @@ -67,16 +67,23 @@ def upgrade(args, suffix="native", update_index=True): if update_index: pmb.chroot.root(args, ["apk", "update"], suffix) - # -a: also update previously downgraded (and therefore pinned) packages + # -a: also update previously downgraded (and therefore pinned) packages pmb.chroot.root(args, ["apk", "upgrade", "-a"], suffix) def installed(args, suffix="native"): """ - Get all explicitly installed packages + Get all installed packages and their versions. + :returns: { "hello-world": {"package": "hello-world-1-r2", "pkgrel": "2", + "pkgver": "1", "pkgname": "hello-world"}, ...} """ - world = args.work + "/chroot_" + suffix + "/etc/apk/world" - if not os.path.exists(world): - return [] - with open(world, encoding="utf-8") as handle: - return handle.read().splitlines() + ret = {} + list = pmb.chroot.user(args, ["apk", "info", "-vv"], suffix, + return_stdout=True) + for line in list.split("\n"): + if not line.rstrip(): + continue + package = line.split(" - ")[0] + split = pmb.parse.other.package_split(package) + ret[split["pkgname"]] = split + return ret diff --git a/pmb/install/install.py b/pmb/install/install.py index 56076afb..d51fb86a 100644 --- a/pmb/install/install.py +++ b/pmb/install/install.py @@ -85,7 +85,8 @@ def install(args, show_flash_msg=True): # List all packages to be installed (including the ones specified by --add) # and upgrade the installed packages/apkindexes logging.info("*** (2/5) CREATE DEVICE ROOTFS (" + args.device + ") ***") - install_packages = (pmb.config.install_device_packages + ["device-" + args.device]) + install_packages = (pmb.config.install_device_packages + + ["device-" + args.device]) suffix = "rootfs_" + args.device pmb.chroot.apk.upgrade(args, suffix) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 46a396d9..c6a38527 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -80,9 +80,15 @@ def arguments(): # Action: log log = sub.add_parser("log", help="follow the pmbootstrap logfile") - log_distccd = sub.add_parser("log_distccd", help="follow the distccd logfile") + log_distccd = sub.add_parser( + "log_distccd", + help="follow the distccd logfile") for action in [log, log_distccd]: - action.add_argument("-n", "--lines", default="30", help="count of initial output lines") + action.add_argument( + "-n", + "--lines", + default="30", + help="count of initial output lines") # Action: zap zap = sub.add_parser("zap", help="safely delete chroot" diff --git a/pmb/parse/other.py b/pmb/parse/other.py new file mode 100644 index 00000000..b7bcb8e2 --- /dev/null +++ b/pmb/parse/other.py @@ -0,0 +1,35 @@ +""" +Copyright 2017 Oliver Smith + +This file is part of pmbootstrap. + +pmbootstrap is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +pmbootstrap is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with pmbootstrap. If not, see . +""" + + +def package_split(package): + """ + Split a full package name (as returned by `apk info -vv` and as found as + apk file name) into its components. + :param package: Example: "heimdall-1.4.2-r1" + """ + split = package.split("-") + pkgrel = split[-1][1:] + pkgver = split[-2] + version = "-" + pkgver + "-r" + pkgrel + pkgname = package[:-1 * len(version)] + return {"pkgname": pkgname, + "pkgrel": pkgrel, + "pkgver": pkgver, + "package": package} diff --git a/pmbootstrap.py b/pmbootstrap.py index 6c8dead5..2d7a5b27 100755 --- a/pmbootstrap.py +++ b/pmbootstrap.py @@ -79,10 +79,10 @@ def main(): pmb.build.ccache_stats(args, args.arch) elif args.action == "log": pmb.helpers.run.user(args, ["tail", "-f", args.log, - "-n", args.lines], log=False) + "-n", args.lines], log=False) elif args.action == "log_distccd": pmb.chroot.user(args, ["tail", "-f", "/home/user/distccd.log", - "-n", args.lines], log=False) + "-n", args.lines], log=False) elif args.action == "zap": pmb.chroot.zap(args) else: