From 90366e0a85e84d8635e4bc93f04159c096134f33 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 16 Oct 2021 10:45:43 +0200 Subject: [PATCH] Simplify generation of pacman.conf --- chroot.py | 4 ++-- distro.py | 33 ++++++++++----------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/chroot.py b/chroot.py index dd1b342..b783ffa 100644 --- a/chroot.py +++ b/chroot.py @@ -3,7 +3,7 @@ import logging import subprocess import os from config import config -from distro import get_base_distros, RepoInfo +from distro import get_base_distro, RepoInfo from shlex import quote as shell_quote from utils import mount from distro import get_kupfer_local @@ -28,7 +28,7 @@ def create_chroot(chroot_name: str, bind_mounts: dict[str, str] = BIND_BUILD_DIRS): base_chroot = f'base_{arch}' chroot_path = get_chroot_path(chroot_name, override_basepath=chroot_base_path) - base_distro = get_base_distros()[arch] + base_distro = get_base_distro(arch) pacman_conf_target = chroot_path + '/etc/pacman.conf' # copy base_chroot instead of creating from scratch every time diff --git a/distro.py b/distro.py index e77432a..8b41cde 100644 --- a/distro.py +++ b/distro.py @@ -95,9 +95,9 @@ class Distro: def _repos_config_snippet(self, extra_repos: dict[str, RepoInfo] = {}) -> str: extras = [Repo(name, url_template=info.url_template, arch=self.arch, options=info.options, scan=False) for name, info in extra_repos.items()] - return '\n'.join(repo.config_snippet() for repo in (list(self.repos.values()) + extras)) + return '\n\n'.join(repo.config_snippet() for repo in (list(self.repos.values()) + extras)) - def get_pacman_conf(self, extra_repos: dict[str, RepoInfo] = [], check_space=False): + def get_pacman_conf(self, extra_repos: dict[str, RepoInfo] = {}, check_space=False): header = f''' # # /etc/pacman.conf @@ -170,30 +170,17 @@ LocalFileSigLevel = Optional return header + self._repos_config_snippet(extra_repos) -_base_distros: dict[str, Distro] = None -_kupfer_distros: dict[str, Distro] = {} - - -def get_base_distros() -> dict[str, Distro]: - global _base_distros - if not _base_distros: - _distros: dict[str, Distro] = {} - for arch, distro_conf in BASE_DISTROS.items(): - repos = {name: RepoInfo(url_template=url) for name, url in distro_conf['repos'].items()} - _distros[arch] = Distro(arch=arch, repo_infos=repos, scan=False) - _base_distros = _distros - return _base_distros +def get_base_distro(arch: str) -> Distro: + repos = {name: RepoInfo(url_template=url) for name, url in BASE_DISTROS[arch]['repos'].items()} + return Distro(arch=arch, repo_infos=repos, scan=False) def get_kupfer(arch: str, url_template: str) -> Distro: - global _kupfer_distros - if arch not in _kupfer_distros: - repos = {name: RepoInfo(url_template=url_template, options={'SigLevel': 'Never'}) for name in REPOSITORIES} - _kupfer_distros[arch] = Distro( - arch=arch, - repo_infos=repos, - ) - return _kupfer_distros[arch] + repos = {name: RepoInfo(url_template=url_template, options={'SigLevel': 'Never'}) for name in REPOSITORIES} + return Distro( + arch=arch, + repo_infos=repos, + ) def get_kupfer_https(arch: str) -> Distro: