forked from Mirror/pmbootstrap
Introduce a new module: pmb.core to contain explicitly typed pmbootstrap API. The first component being Suffix and SuffixType. This explicitly defines what suffixes are possible, future changes should aim to further constrain this API (e.g. by validating against available device codenames or architectures for buildroot suffixes). Additionally, migrate the entire codebase over to using pathlib.Path. This is a relatively new part of the Python standard library that uses a more object oriented model for path handling. It also uses strong type hinting and has other features that make it much cleaner and easier to work with than pure f-strings. The Chroot class overloads the "/" operator the same way the Path object does, allowing one to write paths relative to a given chroot as: builddir = chroot / "home/pmos/build" The Chroot class also has a string representation ("native", or "rootfs_valve-jupiter"), and a .path property for directly accessing the absolute path (as a Path object). The general idea here is to encapsulate common patterns into type hinted code, and gradually reduce the amount of assumptions made around the codebase so that future changes are easier to implement. As the chroot suffixes are now part of the Chroot class, we also implement validation for them, this encodes the rules on suffix naming and will cause a runtime exception if a suffix doesn't follow the rules.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# Copyright 2023 Dylan Van Assche
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
import logging
|
|
|
|
from pmb.core.types import PmbArgs
|
|
import pmb.helpers.pmaports
|
|
|
|
|
|
def get_groups(args: PmbArgs):
|
|
""" Get all groups to which the user additionally must be added.
|
|
The list of groups are listed in _pmb_groups of the UI and
|
|
UI-extras package.
|
|
|
|
:returns: list of groups, e.g. ["feedbackd", "udev"] """
|
|
ret = []
|
|
if args.ui == "none":
|
|
return ret
|
|
|
|
# UI package
|
|
meta = f"postmarketos-ui-{args.ui}"
|
|
apkbuild = pmb.helpers.pmaports.get(args, meta)
|
|
groups = apkbuild["_pmb_groups"]
|
|
if groups:
|
|
logging.debug(f"{meta}: install _pmb_groups:"
|
|
f" {', '.join(groups)}")
|
|
ret += groups
|
|
|
|
# UI-extras subpackage
|
|
meta_extras = f"{meta}-extras"
|
|
if args.ui_extras and meta_extras in apkbuild["subpackages"]:
|
|
groups = apkbuild["subpackages"][meta_extras]["_pmb_groups"]
|
|
if groups:
|
|
logging.debug(f"{meta_extras}: install _pmb_groups:"
|
|
f" {', '.join(groups)}")
|
|
ret += groups
|
|
|
|
return ret
|