forked from Mirror/pmbootstrap
* The APKINDEX parser used to return a dictionary with one package for a given package name. This works for the installed packages database, because there can only be one provider for a package. But when parsing packages from binary repositories, we need to support multiple providers for one package. It is now possible to get a dictionary with either multiple providers, or just a single provider for each package. * Dependency parsing logic has been adjusted, to support multiple providers. For multiple providers, the one with the same package name as the package we are looking up is prefered. If there is none (eg. "so:libEGL.so.1" is provided by "mesa-egl"), it prefers packages that will be installed anyway, and after that packages that are already installed. When all else fails, it just picks the first one and prints a note in the "pmbootstrap log". * Added testcases for all functions in pmb.parse.apkindex and pmb.parse.depends * pmbootstrap chroot has a new "--add" parameter to specify packages that pmbootstrap should build if neccessary, and install in the chroot. This can be used to quickly test the depencency resolution of pmbootstrap without doing a full "pmbootstrap install". Fixes #1122.
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""
|
|
Copyright 2018 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 <http://www.gnu.org/licenses/>.
|
|
"""
|
|
import os
|
|
import glob
|
|
import logging
|
|
|
|
import pmb.config
|
|
import pmb.chroot.apk
|
|
|
|
|
|
def list_chroot(args, suffix, remove_prefix=True):
|
|
ret = []
|
|
prefix = pmb.config.initfs_hook_prefix
|
|
for pkgname in pmb.chroot.apk.installed(args, suffix).keys():
|
|
if pkgname.startswith(prefix):
|
|
if remove_prefix:
|
|
ret.append(pkgname[len(prefix):])
|
|
else:
|
|
ret.append(pkgname)
|
|
return ret
|
|
|
|
|
|
def list_aports(args):
|
|
ret = []
|
|
prefix = pmb.config.initfs_hook_prefix
|
|
for path in glob.glob(args.aports + "/*/" + prefix + "*"):
|
|
ret.append(os.path.basename(path)[len(prefix):])
|
|
return ret
|
|
|
|
|
|
def ls(args, suffix):
|
|
hooks_chroot = list_chroot(args, suffix)
|
|
hooks_aports = list_aports(args)
|
|
|
|
for hook in hooks_aports:
|
|
line = "* " + hook
|
|
if hook in hooks_chroot:
|
|
line += " (installed)"
|
|
logging.info(line)
|
|
|
|
|
|
def add(args, hook, suffix):
|
|
if hook not in list_aports(args):
|
|
raise RuntimeError("Invalid hook name! Run 'pmbootstrap initfs hook_ls'"
|
|
" to get a list of all hooks.")
|
|
prefix = pmb.config.initfs_hook_prefix
|
|
pmb.chroot.apk.install(args, [prefix + hook], suffix)
|
|
|
|
|
|
def delete(args, hook, suffix):
|
|
if hook not in list_chroot(args, suffix):
|
|
raise RuntimeError("There is no such hook installed!")
|
|
prefix = pmb.config.initfs_hook_prefix
|
|
pmb.chroot.root(args, ["apk", "del", prefix + hook], suffix)
|
|
|
|
|
|
def update(args, suffix):
|
|
"""
|
|
Rebuild and update all hooks, that are out of date
|
|
"""
|
|
pmb.chroot.apk.install(args, list_chroot(args, suffix, False), suffix)
|