Simplify generation of pacman.conf

This commit is contained in:
jld3103 2021-10-16 10:45:43 +02:00
parent 37b5ecb34b
commit 90366e0a85
2 changed files with 12 additions and 25 deletions

View file

@ -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

View file

@ -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: