add ability to override pacman mirror in devtools configuration

This commit also extends configuration of the multilib option, adding
the ability to exlcude multilib repository from repositories list

Note, that in order to support repository list and mirror correctly,
alpm configuration section is now architectture specific
This commit is contained in:
2023-01-13 18:46:15 +02:00
parent 4d482520cd
commit 93876307f8
12 changed files with 112 additions and 35 deletions

View File

@ -818,6 +818,7 @@ def _set_service_setup_parser(root: SubParserAction) -> argparse.ArgumentParser:
type=Path, default=Path("/usr/share/devtools/pacman-extra.conf"))
parser.add_argument("--makeflags-jobs", help="append MAKEFLAGS variable with parallelism set to number of cores",
action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--mirror", help="use the specified explicitly mirror instead of including mirrorlist")
parser.add_argument("--multilib", help="add or do not multilib repository",
action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--packager", help="packager name and email", required=True)

View File

@ -21,7 +21,7 @@ import argparse
from pathlib import Path
from pwd import getpwuid
from typing import Type
from typing import Optional, Type
from ahriman.application.application import Application
from ahriman.application.handlers import Handler
@ -58,15 +58,14 @@ class Setup(Handler):
report(bool): force enable or disable reporting
unsafe(bool): if set no user check will be performed before path creation
"""
Setup.configuration_create_ahriman(args, architecture, args.repository, configuration.include,
configuration.repository_paths)
Setup.configuration_create_ahriman(args, architecture, args.repository, configuration)
configuration.reload()
application = Application(architecture, configuration, report=report, unsafe=unsafe)
Setup.configuration_create_makepkg(args.packager, args.makeflags_jobs, application.repository.paths)
Setup.executable_create(application.repository.paths, args.build_command, architecture)
Setup.configuration_create_devtools(args.build_command, architecture, args.from_configuration,
Setup.configuration_create_devtools(args.build_command, architecture, args.from_configuration, args.mirror,
args.multilib, args.repository, application.repository.paths)
Setup.configuration_create_sudo(application.repository.paths, args.build_command, architecture)
@ -91,7 +90,7 @@ class Setup(Handler):
@staticmethod
def configuration_create_ahriman(args: argparse.Namespace, architecture: str, repository: str,
include_path: Path, paths: RepositoryPaths) -> None:
root: Configuration) -> None:
"""
create service specific configuration
@ -99,37 +98,41 @@ class Setup(Handler):
args(argparse.Namespace): command line args
architecture(str): repository architecture
repository(str): repository name
include_path(Path): path to directory with configuration includes
paths(RepositoryPaths): repository paths instance
root(Configuration): root configuration instance
"""
configuration = Configuration()
section = Configuration.section_name("build", architecture)
build_command = Setup.build_command(paths.root, args.build_command, architecture)
build_command = Setup.build_command(root.repository_paths.root, args.build_command, architecture)
configuration.set_option(section, "build_command", str(build_command))
configuration.set_option("repository", "name", repository)
if args.build_as_user is not None:
configuration.set_option(section, "makechrootpkg_flags", f"-U {args.build_as_user}")
section = Configuration.section_name("alpm", architecture)
if args.mirror is not None:
configuration.set_option(section, "mirror", args.mirror)
if not args.multilib:
repositories = filter(lambda r: r != "multilib", root.getlist("alpm", "repositories"))
configuration.set_option(section, "repositories", " ".join(repositories))
section = Configuration.section_name("sign", architecture)
if args.sign_key is not None:
section = Configuration.section_name("sign", architecture)
configuration.set_option(section, "target", " ".join([target.name.lower() for target in args.sign_target]))
configuration.set_option(section, "key", args.sign_key)
section = Configuration.section_name("web", architecture)
if args.web_port is not None:
section = Configuration.section_name("web", architecture)
configuration.set_option(section, "port", str(args.web_port))
if args.web_unix_socket is not None:
section = Configuration.section_name("web", architecture)
configuration.set_option(section, "unix_socket", str(args.web_unix_socket))
target = include_path / "00-setup-overrides.ini"
target = root.include / "00-setup-overrides.ini"
with target.open("w") as ahriman_configuration:
configuration.write(ahriman_configuration)
@staticmethod
def configuration_create_devtools(prefix: str, architecture: str, source: Path,
def configuration_create_devtools(prefix: str, architecture: str, source: Path, mirror: Optional[str],
multilib: bool, repository: str, paths: RepositoryPaths) -> None:
"""
create configuration for devtools based on ``source`` configuration
@ -141,6 +144,7 @@ class Setup(Handler):
prefix(str): command prefix in {prefix}-{architecture}-build
architecture(str): repository architecture
source(Path): path to source configuration file
mirror(Optional[str]): link to package server mirror
multilib(bool): add or do not multilib repository to the configuration
repository(str): repository name
paths(RepositoryPaths): repository paths instance
@ -163,6 +167,14 @@ class Setup(Handler):
if multilib:
configuration.set_option("multilib", "Include", str(Setup.MIRRORLIST_PATH))
# override Include option to Server in case if mirror option set
if mirror is not None:
for section in filter(lambda s: s != "options", configuration.sections()):
if configuration.get(section, "Include", fallback=None) != str(Setup.MIRRORLIST_PATH):
continue
configuration.remove_option(section, "Include")
configuration.set_option(section, "Server", mirror)
# add repository itself
configuration.set_option(repository, "SigLevel", "Optional TrustAll") # we don't care
configuration.set_option(repository, "Server", f"file://{paths.repository}")

View File

@ -45,8 +45,8 @@ class Pacman(LazyLogging):
Args:
architecture(str): repository architecture
configuration(Configuration): configuration instance
refresh_database(int): synchronize local cache to remote. If set to ``0``, no syncronization will be
enabled, if set to ``1`` - normal syncronization, if set to ``2`` - force syncronization
refresh_database(int): synchronize local cache to remote. If set to ``0``, no synchronization will be
enabled, if set to ``1`` - normal synchronization, if set to ``2`` - force synchronization
"""
self.__create_handle_fn: Callable[[], Handle] = lambda: self.__create_handle(
architecture, configuration, refresh_database=refresh_database)
@ -58,8 +58,8 @@ class Pacman(LazyLogging):
Args:
architecture(str): repository architecture
configuration(Configuration): configuration instance
refresh_database(int): synchronize local cache to remote. If set to ``0``, no syncronization will be
enabled, if set to ``1`` - normal syncronization, if set to ``2`` - force syncronization
refresh_database(int): synchronize local cache to remote. If set to ``0``, no synchronization will be
enabled, if set to ``1`` - normal synchronization, if set to ``2`` - force synchronization
Returns:
Handle: fully initialized pacman handle
@ -126,7 +126,7 @@ class Pacman(LazyLogging):
Returns:
DB: loaded pacman database instance
"""
self.logger.info("loading pacman databases")
self.logger.info("loading pacman database %s", repository)
database: DB = handle.register_syncdb(repository, SIG_PACKAGE)
# replace variables in mirror address
database.servers = [mirror.replace("$repo", repository).replace("$arch", architecture)]
@ -138,7 +138,7 @@ class Pacman(LazyLogging):
Args:
handle(Handle): pacman handle which will be used for database sync
force(bool): force database syncronization (same as ``pacman -Syy``)
force(bool): force database synchronization (same as ``pacman -Syy``)
"""
self.logger.info("refresh ahriman's home pacman database (force refresh %s)", force)
transaction = handle.init_transaction()

View File

@ -61,7 +61,7 @@ class Configuration(configparser.RawConfigParser):
>>> path, architecture = configuration.check_loaded()
"""
ARCHITECTURE_SPECIFIC_SECTIONS = ["build", "sign", "web"]
ARCHITECTURE_SPECIFIC_SECTIONS = ["alpm", "build", "sign", "web"]
SYSTEM_CONFIGURATION_PATH = Path(sys.prefix) / "share" / "ahriman" / "settings" / "ahriman.ini"
converters: Dict[str, Callable[[str], Any]] # typing guard