Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • postmarketOS/pmbootstrap
  • fossdd/pmbootstrap
  • Adrian/pmbootstrap
  • JustSoup321/pmbootstrap
  • longnoserob/pmbootstrap
  • sixthkrum/pmbootstrap
  • ollieparanoid/pmbootstrap
  • magdesign/pmbootstrap
  • anjandev/pmbootstrap
  • HenriDellal/pmbootstrap
  • Minecrell/pmbootstrap
  • chipiguay/pmbootstrap
  • ijiki16/pmbootstrap
  • whynothugo/pmbootstrap
  • amessier/pmbootstrap
  • Eisenbahnfan/pmbootstrap
  • user0-07161/pmbootstrap
  • SzczurekYT/pmbootstrap
  • neuschaefer/pmbootstrap
  • knuxify/pmbootstrap
  • Frieder.Hannenheim/pmbootstrap
21 results
Show changes
Commits on Source (10)
Showing
with 252 additions and 167 deletions
......@@ -12,14 +12,6 @@ pmb.chroot.apk module
:undoc-members:
:show-inheritance:
pmb.chroot.apk\_static module
-----------------------------
.. automodule:: pmb.chroot.apk_static
:members:
:undoc-members:
:show-inheritance:
pmb.chroot.binfmt module
------------------------
......
......@@ -4,6 +4,14 @@ pmb.helpers package
Submodules
----------
pmb.helpers.apk\_static module
-----------------------------
.. automodule:: pmb.helpers.apk_static
:members:
:undoc-members:
:show-inheritance:
pmb.helpers.apk module
----------------------
......
......@@ -14,7 +14,6 @@ if TYPE_CHECKING:
from . import config
from . import parse
from . import types
from .config import init as config_init
from .helpers import frontend
from .helpers import logging
......
......@@ -4,7 +4,6 @@ from pathlib import Path
import pmb.aportgen.core
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.helpers.run
import pmb.parse.apkindex
from pmb.core import Chroot
......
......@@ -4,7 +4,6 @@ from pathlib import Path
import pmb.aportgen.core
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
from pmb.core.arch import Arch
import pmb.helpers.run
import pmb.parse.apkindex
......
......@@ -4,7 +4,6 @@ from pathlib import Path
import pmb.aportgen.core
import pmb.build
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.helpers.run
import pmb.parse.apkindex
from pmb.core import Chroot
......
......@@ -6,10 +6,8 @@ from __future__ import annotations
import os
from pathlib import Path
import traceback
import pmb.chroot.apk_static
from pmb.core.arch import Arch
from pmb.helpers import logging
import shlex
from collections.abc import Sequence
import pmb.build
......@@ -30,57 +28,6 @@ from pmb.types import PathString
from pmb.helpers.exceptions import NonBugError
@Cache("chroot", "user_repository", mirrors_exclude=[])
def update_repository_list(
chroot: Chroot,
user_repository: bool = False,
mirrors_exclude: list[str] = [],
check: bool = False,
) -> None:
"""
Update /etc/apk/repositories, if it is outdated (when the user changed the
--mirror-alpine or --mirror-pmOS parameters).
:param mirrors_exclude: mirrors to exclude from the repository list
:param check: This function calls it self after updating the
/etc/apk/repositories file, to check if it was successful.
Only for this purpose, the "check" parameter should be set to
True.
"""
# Read old entries or create folder structure
path = chroot / "etc/apk/repositories"
lines_old: list[str] = []
if path.exists():
# Read all old lines
lines_old = []
with path.open() as handle:
for line in handle:
lines_old.append(line[:-1])
else:
pmb.helpers.run.root(["mkdir", "-p", path.parent])
# Up to date: Save cache, return
lines_new = pmb.helpers.repo.urls(
user_repository=user_repository, mirrors_exclude=mirrors_exclude
)
if lines_old == lines_new:
return
# Check phase: raise error when still outdated
if check:
raise RuntimeError(f"Failed to update: {path}")
# Update the file
logging.debug(f"({chroot}) update /etc/apk/repositories")
if path.exists():
pmb.helpers.run.root(["rm", path])
for line in lines_new:
pmb.helpers.run.root(["sh", "-c", "echo " f"{shlex.quote(line)} >> {path}"])
update_repository_list(
chroot, user_repository=user_repository, mirrors_exclude=mirrors_exclude, check=True
)
@Cache("chroot")
def check_min_version(chroot: Chroot = Chroot.native()) -> None:
"""
......@@ -163,9 +110,7 @@ def packages_get_locally_built_apks(package_list: list[str], arch: Arch) -> list
for channel in channels:
apk_path = get_context().config.work / "packages" / channel / arch / apk_file
if apk_path.exists():
# FIXME: use /mnt/pmb… until MR 2351 is reverted (pmb#2388)
# local.append(apk_path)
local.append(Path("/mnt/pmbootstrap/packages/") / channel / arch / apk_file)
local.append(apk_path)
break
# Record all the packages we have visited so far
......@@ -233,24 +178,17 @@ def install_run_apk(
user_repo += ["--repository", context.config.work / "packages" / channel]
for i, command in enumerate(commands):
# --no-interactive is a parameter to `add`, so it must be appended or apk
# gets confused
command += ["--no-interactive"]
command = user_repo + command
# Ignore missing repos before initial build (bpo#137)
if os.getenv("PMB_APK_FORCE_MISSING_REPOSITORIES") == "1":
command = ["--force-missing-repositories"] + command
if context.offline:
command = ["--no-network"] + command
if i == 0:
pmb.helpers.apk.apk_with_progress(command, chroot)
else:
# Virtual package related commands don't actually install or remove
# packages, but only mark the right ones as explicitly installed.
# They finish up almost instantly, so don't display a progress bar.
pmb.chroot.root(["apk", "--no-progress"] + command, chroot)
# Virtual package related commands don't actually install or remove
# packages, but only mark the right ones as explicitly installed.
# So only display a progress bar for the "apk add" command which is
# always the first one we process (i == 0).
pmb.helpers.apk.run(command, chroot, with_progress=(i == 0))
def install(packages: list[str], chroot: Chroot, build: bool = True, quiet: bool = False) -> None:
......
......@@ -9,14 +9,16 @@ import os
import pmb.chroot
import pmb.chroot.binfmt
import pmb.chroot.apk
import pmb.chroot.apk_static
import pmb.config
import pmb.config.workdir
import pmb.helpers.apk_static
import pmb.helpers.apk
import pmb.helpers.repo
import pmb.helpers.run
import pmb.helpers.other
from pmb.core import Chroot, ChrootType
from pmb.core.context import get_context
from pmb.types import PathString
class UsrMerge(enum.Enum):
......@@ -136,33 +138,27 @@ def init(chroot: Chroot, usr_merge: UsrMerge = UsrMerge.AUTO) -> None:
mark_in_chroot(chroot)
if chroot.exists():
copy_resolv_conf(chroot)
pmb.chroot.apk.update_repository_list(chroot)
pmb.helpers.apk.update_repository_list(chroot.path)
warn_if_chroots_outdated()
return
# Require apk-tools-static
pmb.chroot.apk_static.init()
# Fetch apk.static
pmb.helpers.apk_static.init()
logging.info(f"({chroot}) Creating chroot")
# Initialize cache
apk_cache = config.work / f"cache_apk_{arch}"
pmb.helpers.run.root(["ln", "-s", "-f", "/var/cache/apk", chroot / "etc/apk/cache"])
# Initialize /etc/apk/keys/, resolv.conf, repositories
init_keys()
copy_resolv_conf(chroot)
pmb.chroot.apk.update_repository_list(chroot)
pmb.helpers.apk.update_repository_list(chroot.path)
pmb.config.workdir.chroot_save_init(chroot)
# Install alpine-base
pmb.helpers.repo.update(arch)
pkgs = ["alpine-base"]
cmd = ["--root", chroot.path, "--cache-dir", apk_cache, "--initdb", "--arch", arch]
for channel in pmb.config.pmaports.all_channels():
cmd += ["--repository", config.work / "packages" / channel]
pmb.chroot.apk_static.run(cmd + ["add", *pkgs])
cmd: list[PathString] = ["--initdb"]
pmb.helpers.apk.run(cmd + ["add", *pkgs], chroot)
# Merge /usr
if usr_merge is UsrMerge.AUTO and pmb.config.is_systemd_selected(config):
......
......@@ -51,7 +51,7 @@ def delete(hook: str, suffix: Chroot) -> None:
if hook not in list_chroot(suffix):
raise RuntimeError("There is no such hook installed!")
prefix = pmb.config.initfs_hook_prefix
pmb.chroot.root(["apk", "del", f"{prefix}{hook}"], suffix)
pmb.helpers.apk.run(["del", f"{prefix}{hook}"], suffix)
def update(suffix: Chroot) -> None:
......
......@@ -11,6 +11,7 @@ import pmb.config.workdir
import pmb.chroot
import pmb.config.pmaports
import pmb.config.workdir
import pmb.helpers.apk
import pmb.helpers.cli
import pmb.helpers.pmaports
import pmb.helpers.run
......@@ -107,7 +108,7 @@ def zap(
pmb.config.workdir.clean()
# Chroots were zapped, so no repo lists exist anymore
pmb.chroot.apk.update_repository_list.cache_clear()
pmb.helpers.apk.update_repository_list.cache_clear()
# Let chroot.init be called again
pmb.chroot.init.cache_clear()
......@@ -183,18 +184,6 @@ def zap_pkgs_online_mismatch(confirm=True, dry=False):
# Iterate over existing apk caches
for path in paths:
arch = Arch.from_str(path.name.split("_", 2)[2])
if arch.is_native():
chroot = Chroot.native()
else:
chroot = Chroot.buildroot(arch)
# Skip if chroot does not exist
# FIXME: should we init the buildroot to do it anyway?
# what if we run apk.static with --arch instead?
if not chroot.exists():
continue
# Clean the cache with apk
logging.info(f"({chroot}) apk -v cache clean")
if not dry:
pmb.chroot.root(["apk", "-v", "cache", "clean"], chroot)
pmb.helpers.apk.cache_clean(arch)
......@@ -47,7 +47,6 @@ unmigrated_commands = [
"install",
"checksum",
"build",
"deviceinfo_parse",
"apkbuild_parse",
"apkindex_parse",
"config",
......
......@@ -57,7 +57,7 @@ class RepoBootstrap(commands.Command):
self.check_repo_arg()
def get_packages(self, bootstrap_line):
def get_packages(self, bootstrap_line: str) -> list[str]:
ret = []
for word in bootstrap_line.split(" "):
if word.startswith("["):
......@@ -65,7 +65,7 @@ class RepoBootstrap(commands.Command):
ret += [word]
return ret
def set_progress_total(self, steps):
def set_progress_total(self, steps: dict[str, str]) -> None:
self.progress_total = 0
# Add one progress point per package
......@@ -85,7 +85,7 @@ class RepoBootstrap(commands.Command):
self.progress_done += 1
def run_steps(self, steps):
def run_steps(self, steps: dict[str, str]) -> None:
chroot: Chroot
if self.arch.cpu_emulation_required():
chroot = Chroot(ChrootType.BUILDROOT, self.arch)
......@@ -109,7 +109,7 @@ class RepoBootstrap(commands.Command):
self.log_progress(f"initializing {chroot} chroot (merge /usr: {usr_merge.name})")
# Initialize without pmOS binary package repo
pmb.chroot.apk.update_repository_list(chroot, mirrors_exclude=[self.repo])
pmb.helpers.apk.update_repository_list(chroot.path, mirrors_exclude=[self.repo])
pmb.chroot.init(chroot, usr_merge)
bootstrap_stage = int(step.split("bootstrap_", 1)[1])
......@@ -149,10 +149,10 @@ class RepoBootstrap(commands.Command):
raise RuntimeError(f"{msg}!")
def get_steps(self):
def get_steps(self) -> dict[str, str]:
cfg = pmb.config.pmaports.read_config_repos()
prev_step = 0
ret = {}
ret: dict[str, str] = {}
for key, packages in cfg[self.repo].items():
if not key.startswith("bootstrap_"):
......
......@@ -14,6 +14,7 @@ from collections.abc import Sequence
from pmb.config.file import load, save, serialize
from pmb.config.sudo import which_sudo
from pmb.config.other import is_systemd_selected
from . import workdir
#
......
# Copyright 2023 Johannes Marbach, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import shlex
from collections.abc import Sequence
from pathlib import Path
from typing import Literal
import pmb.chroot
import pmb.config.pmaports
......@@ -10,10 +12,74 @@ from pmb.core.arch import Arch
from pmb.core.chroot import Chroot
from pmb.types import PathString
import pmb.helpers.cli
import pmb.helpers.repo
import pmb.helpers.run
import pmb.helpers.run_core
import pmb.parse.version
from pmb.core.context import get_context
from pmb.helpers import logging
from pmb.meta import Cache
@Cache("root", "user_repository", mirrors_exclude=[])
def update_repository_list(
root: Path,
user_repository: bool | Path = False,
mirrors_exclude: list[str] | Literal[True] = [],
check: bool = False,
) -> None:
"""
Update /etc/apk/repositories, if it is outdated (when the user changed the
--mirror-alpine or --mirror-pmOS parameters).
:param root: the root directory to operate on
:param mirrors_exclude: mirrors to exclude from the repository list
:param check: This function calls it self after updating the
/etc/apk/repositories file, to check if it was successful.
Only for this purpose, the "check" parameter should be set to
True.
"""
# Read old entries or create folder structure
path = root / "etc/apk/repositories"
lines_old: list[str] = []
if path.exists():
# Read all old lines
lines_old = []
with path.open() as handle:
for line in handle:
lines_old.append(line[:-1])
else:
pmb.helpers.run.root(["mkdir", "-p", path.parent])
user_repo_dir: Path | None
if isinstance(user_repository, Path):
user_repo_dir = user_repository
else:
user_repo_dir = Path("/mnt/pmbootstrap/packages") if user_repository else None
# Up to date: Save cache, return
lines_new = pmb.helpers.repo.urls(
user_repository=user_repo_dir, mirrors_exclude=mirrors_exclude
)
if lines_old == lines_new:
return
# Check phase: raise error when still outdated
if check:
raise RuntimeError(f"Failed to update: {path}")
# Update the file
logging.debug(f"({root.name}) update /etc/apk/repositories")
if path.exists():
pmb.helpers.run.root(["rm", path])
for line in lines_new:
pmb.helpers.run.root(["sh", "-c", "echo " f"{shlex.quote(line)} >> {path}"])
update_repository_list(
root,
user_repository=user_repository,
mirrors_exclude=mirrors_exclude,
check=True,
)
def _prepare_fifo() -> Path:
......@@ -43,7 +109,7 @@ def _create_command_with_progress(command, fifo):
:param fifo: path of the fifo
:returns: full command in list form
"""
flags = ["--no-progress", "--progress-fd", "3"]
flags = ["--progress-fd", "3"]
command_full = [command[0]] + flags + command[1:]
command_flat = pmb.helpers.run_core.flat_cmd([command_full])
command_flat = f"exec 3>{fifo}; {command_flat}"
......@@ -66,23 +132,15 @@ def _compute_progress(line):
return cur / tot if tot > 0 else 0
def apk_with_progress(command: Sequence[PathString], chroot: Chroot | None = None) -> None:
def _apk_with_progress(command: Sequence[str]) -> None:
"""Run an apk subcommand while printing a progress bar to STDOUT.
:param command: apk subcommand in list form
:raises RuntimeError: when the apk command fails
"""
fifo = _prepare_fifo()
_command: list[str] = [str(get_context().config.work / "apk.static")]
if chroot:
_command.extend(["--root", str(chroot.path), "--arch", str(chroot.arch)])
for c in command:
if isinstance(c, Arch):
_command.append(str(c))
else:
_command.append(os.fspath(c))
command_with_progress = _create_command_with_progress(_command, fifo)
log_msg = " ".join(_command)
command_with_progress = _create_command_with_progress(command, fifo)
log_msg = " ".join(command)
with pmb.helpers.run.root(["cat", fifo], output="pipe") as p_cat:
with pmb.helpers.run.root(command_with_progress, output="background") as p_apk:
while p_apk.poll() is None:
......@@ -96,6 +154,128 @@ def apk_with_progress(command: Sequence[PathString], chroot: Chroot | None = Non
pmb.helpers.run_core.check_return_code(p_apk.returncode, log_msg)
def _prepare_cmd(command: Sequence[PathString], chroot: Chroot | None) -> list[str]:
"""Prepare the apk command.
Returns a tuple of the first part of the command with generic apk flags, and the second part
with the subcommand and its arguments.
"""
config = get_context().config
# Our _apk_with_progress() wrapper also need --no-progress, since all that does is
# prevent apk itself from rendering progress bars. We instead want it to tell us
# the progress so we can render it. So we always set --no-progress.
_command: list[str] = [str(config.work / "apk.static"), "--no-progress"]
if chroot:
cache_dir = config.work / f"cache_apk_{chroot.arch}"
_command.extend(
[
"--root",
str(chroot.path),
"--arch",
str(chroot.arch),
"--cache-dir",
str(cache_dir),
]
)
local_repos = pmb.helpers.repo.urls(
user_repository=config.work / "packages", mirrors_exclude=True
)
for repo in local_repos:
_command.extend(["--repository", repo])
if get_context().offline:
_command.append("--no-network")
for c in command:
_command.append(os.fspath(c))
# Always be non-interactive
if c == "add":
_command.append("--no-interactive")
return _command
def run(command: Sequence[PathString], chroot: Chroot, with_progress: bool = True) -> None:
"""Run an apk subcommand.
:param command: apk subcommand in list form
:param with_progress: whether to print a progress bar
:param chroot: chroot to run the command in
:raises RuntimeError: when the apk command fails
"""
_command = _prepare_cmd(command, chroot)
# Sanity checks. We should avoid accidentally writing to
# /var/cache/apk on the host!
if "add" in command:
if "--no-interactive" not in _command:
raise RuntimeError(
"Encountered an 'apk add' command without --no-interactive! This is a bug."
)
if "--cache-dir" not in _command:
raise RuntimeError(
"Encountered an 'apk add' command without --cache-dir! This is a bug."
)
if with_progress:
_apk_with_progress(_command)
else:
pmb.helpers.run.root(_command)
def cache_clean(arch: Arch) -> None:
"""Clean the APK cache for a specific architecture."""
work = get_context().config.work
cache_dir = work / f"cache_apk_{arch}"
if not cache_dir.exists():
return
# The problem here is that apk's "cache clean" command really
# expects to be run against an apk-managed rootfs and will return
# errors if it can't access certain paths (even though it will
# actually clean the cache like we want).
# We could just ignore the return value, but then we wouldn't know
# if something actually went wrong with apk...
# So we do this dance of creating a rootfs with only the files that
# APK needs to be happy
tmproot = work / "tmp" / "apk_root"
if not (tmproot / "etc/apk/repositories").exists():
tmproot.mkdir(exist_ok=True)
(tmproot / "var/cache").mkdir(exist_ok=True, parents=True)
(tmproot / "etc/apk").mkdir(exist_ok=True, parents=True)
(tmproot / "lib/apk/db").mkdir(exist_ok=True, parents=True)
(tmproot / "etc/apk/world").touch(exist_ok=True)
(tmproot / "lib/apk/db/installed").touch(exist_ok=True)
(tmproot / "lib/apk/db/triggers").touch(exist_ok=True)
(tmproot / "etc/apk/keys").symlink_to(work / "config_apk_keys")
# Our fake rootfs needs a valid repositories file for apk
# to have something to compare the cache against
update_repository_list(tmproot, user_repository=work / "packages")
# Point our tmproot cache dir to the real cache dir
# this is much simpler than passing --cache-dir to apk
# since even with that flag apk will also check it's
# "static cache".
(tmproot / "var/cache/apk").unlink(missing_ok=True)
(tmproot / "var/cache/apk").symlink_to(cache_dir)
command: list[PathString] = [
"-v",
"--root",
tmproot,
"--arch",
str(arch),
]
command += ["cache", "clean"]
_command = _prepare_cmd(command, None)
pmb.helpers.run.root(_command)
def check_outdated(version_installed, action_msg):
"""Check if the provided alpine version is outdated.
......
......@@ -161,7 +161,8 @@ def init() -> None:
"""
Download, verify, extract $WORK/apk.static.
"""
# Get and parse the APKINDEX
# Get and parse the APKINDEX. alpine_apkindex_path() will implicitly
# download the APKINDEX file if it's missing.
apkindex = pmb.helpers.repo.alpine_apkindex_path("main")
index_data = pmb.parse.apkindex.package("apk-tools-static", indexes=[apkindex])
......@@ -177,13 +178,3 @@ def init() -> None:
apk_name = f"apk-tools-static-{version}.apk"
apk_static = download(apk_name)
extract(version, apk_static)
def run(parameters):
# --no-interactive is a parameter to `add`, so it must be appended or apk
# gets confused
parameters += ["--no-interactive"]
if get_context().offline:
parameters = ["--no-network"] + parameters
pmb.helpers.apk.apk_with_progress(parameters)
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import sys
import pmb.config
from pmb.core.context import Context
from pmb.core.pkgrepo import pkgrepo_default_path
......@@ -89,6 +91,7 @@ def init(args: PmbArgs) -> PmbArgs:
# Initialize logs (we could raise errors below)
pmb.helpers.logging.init(context.log, args.verbose, context.details_to_stdout)
pmb.helpers.logging.debug(f"Pmbootstrap v{pmb.__version__} (Python {sys.version})")
# Initialization code which may raise errors
if args.action not in [
......
......@@ -211,7 +211,7 @@ def chroot(args: PmbArgs) -> None:
size_reserve = 2048 # 2 GiB
pmb.install.blockdevice.create_and_mount_image(args, size_boot, size_root, size_reserve)
pmb.chroot.apk.update_repository_list(chroot, user_repository=True)
pmb.helpers.apk.update_repository_list(chroot.path, user_repository=True)
# TODO: Maybe this could be done better.
output_type = cast(RunOutputType, args.output)
......@@ -462,19 +462,6 @@ def newapkbuild(args: PmbArgs) -> None:
pmb.build.newapkbuild(args.folder, pass_through, get_context().force)
def deviceinfo_parse(args: PmbArgs) -> None:
# Default to all devices
devices = args.devices
if not devices:
devices = pmb.helpers.devices.list_codenames()
# Iterate over all devices
kernel = args.deviceinfo_parse_kernel
for device in devices:
print(f"{device}, with kernel={kernel}:")
print(json.dumps(pmb.parse.deviceinfo(device, kernel), indent=4, sort_keys=True))
def apkbuild_parse(args: PmbArgs) -> None:
# Default to all packages
packages: Sequence[str] = args.packages
......
......@@ -5,7 +5,6 @@ import os
from pathlib import Path
import sys
from typing import Any, Final, TextIO
import pmb.config
from pmb.meta import Cache
logfd: TextIO
......@@ -29,6 +28,12 @@ class log_handler(logging.StreamHandler):
self.details_to_stdout = details_to_stdout
self.quiet = False
# FIXME: importing pmb.config pulls in a whole lot of stuff
# and can easily lead to circular imports, so we defer it until here.
import pmb.config
self.styles = pmb.config.styles
def emit(self, record):
try:
msg = self.format(record)
......@@ -37,7 +42,7 @@ class log_handler(logging.StreamHandler):
if self.details_to_stdout or (not self.quiet and record.levelno >= logging.INFO):
stream = self.stream
styles = pmb.config.styles
styles = self.styles
msg_col = (
msg.replace(
......@@ -147,7 +152,6 @@ def init(logfile: Path, verbose: bool, details_to_stdout: bool = False) -> None:
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logging.debug(f"Pmbootstrap v{pmb.__version__} (Python {sys.version})")
if "--password" in sys.argv:
sys.argv[sys.argv.index("--password") + 1] = "[REDACTED]"
logging.debug(f"$ pmbootstrap {' '.join(sys.argv)}")
......
......@@ -16,6 +16,7 @@ from pmb.core.arch import Arch
from pmb.core.pkgrepo import pkgrepo_names
from pmb.helpers import logging
from pathlib import Path
from typing import Literal
import pmb.config.pmaports
from pmb.meta import Cache
......@@ -54,11 +55,14 @@ def apkindex_hash(url: str, length: int = 8) -> Path:
# FIXME: make config.mirrors a normal dict
# mypy: disable-error-code="literal-required"
@Cache("user_repository", "mirrors_exclude")
def urls(user_repository: bool = False, mirrors_exclude: list[str] = []) -> list[str]:
def urls(
user_repository: Path | None = None, mirrors_exclude: list[str] | Literal[True] = []
) -> list[str]:
"""Get a list of repository URLs, as they are in /etc/apk/repositories.
:param user_repository: add /mnt/pmbootstrap/packages
:param mirrors_exclude: mirrors to exclude (see pmb.core.config.Mirrors)
:param mirrors_exclude: mirrors to exclude (see pmb.core.config.Mirrors) or true to exclude
all mirrors and only return the local repos
:returns: list of mirror strings, like ["/mnt/pmbootstrap/packages",
"http://...", ...]
"""
......@@ -74,7 +78,10 @@ def urls(user_repository: bool = False, mirrors_exclude: list[str] = []) -> list
# Local user repository (for packages compiled with pmbootstrap)
if user_repository:
for channel in pmb.config.pmaports.all_channels():
ret.append(f"/mnt/pmbootstrap/packages/{channel}")
ret.append(str(user_repository / channel))
if mirrors_exclude is True:
return ret
# Don't add the systemd mirror if systemd is disabled
if not pmb.config.is_systemd_selected(config):
......
......@@ -3,7 +3,6 @@
import os
from pathlib import Path
import subprocess
from pmb.core.arch import Arch
import pmb.helpers.run_core
from collections.abc import Sequence
from typing import overload, Literal
......@@ -35,13 +34,8 @@ def user(
See pmb.helpers.run_core.core() for a detailed description of all other
arguments and the return value.
"""
cmd_parts = []
for c in cmd:
if isinstance(c, Arch):
c = str(c)
else:
c = os.fspath(c)
cmd_parts.append(c)
cmd_parts = [os.fspath(c) for c in cmd]
# Readable log message (without all the escaping)
msg = "% "
for key, value in env.items():
......