From 462d2fa301e5ddbe3c02a02cdfda01fc7f14dd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Br=C3=A9nainn=20Woodsend?= Date: Thu, 19 Oct 2023 20:17:42 +0100 Subject: [PATCH] Refactor mirror.install -> mirror.install_command. --- polycotylus/_alpine.py | 6 +++--- polycotylus/_arch.py | 4 ++-- polycotylus/_debian.py | 4 ++-- polycotylus/_mirror.py | 16 ++++++++-------- polycotylus/_opensuse.py | 4 ++-- polycotylus/_void.py | 4 ++-- tests/shared.py | 2 +- tests/test_alpine.py | 2 +- tests/test_manjaro.py | 2 +- tests/test_mirror.py | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/polycotylus/_alpine.py b/polycotylus/_alpine.py index 8f43c55..c8293fa 100644 --- a/polycotylus/_alpine.py +++ b/polycotylus/_alpine.py @@ -51,7 +51,7 @@ def tag(_, cls): def _package_manager_queries(cls): with cls.mirror: container = _docker.run(cls.base_image, f""" - {cls.mirror.install} + {cls.mirror.install_command} apk update apk search -q > /packages apk info -q > /base-packages @@ -175,7 +175,7 @@ def dockerfile(self): return self._formatter(f""" FROM {self.base_image} AS base - RUN {self.mirror.install} + RUN {self.mirror.install_command} RUN echo -e {repr(public.read_text("utf8"))} > "/etc/apk/keys/{public.name}" RUN apk add shadow sudo @@ -226,7 +226,7 @@ def abuild_keys(self): with self.mirror: container = _docker.run(self.base_image, f""" - {self.mirror.install} + {self.mirror.install_command} apk add -q abuild echo 'PACKAGER="{self.project.maintainer_slug}"' >> /etc/abuild.conf echo 'MAINTAINER="$PACKAGER"' >> /etc/abuild.conf diff --git a/polycotylus/_arch.py b/polycotylus/_arch.py index 7aba322..66f7129 100644 --- a/polycotylus/_arch.py +++ b/polycotylus/_arch.py @@ -38,7 +38,7 @@ class Arch(BaseDistribution): def _package_manager_queries(cls): with cls.mirror: container = _docker.run(cls.base_image, f""" - {cls.mirror.install} + {cls.mirror.install_command} pacman -Sy pacman -Ssq > /packages pacman -Qq > /base-packages @@ -144,7 +144,7 @@ def dockerfile(self): return self._formatter(f""" FROM {self.base_image} AS base - RUN {self.mirror.install} + RUN {self.mirror.install_command} RUN pacman -Syu --noconfirm --needed sudo {self._install_user()} RUN mkdir /io && chown user /io diff --git a/polycotylus/_debian.py b/polycotylus/_debian.py index de44add..c637a32 100644 --- a/polycotylus/_debian.py +++ b/polycotylus/_debian.py @@ -96,7 +96,7 @@ def distro_root(self): def _package_manager_queries(cls): with cls.mirror: container = _docker.run(cls.base_image, f""" - {cls.mirror.install} + {cls.mirror.install_command} apt-get update apt list -qq > /available apt list --installed -qq > /installed @@ -148,7 +148,7 @@ def inject_source(self): def dockerfile(self): return self._formatter(f""" FROM {self.base_image} AS build - RUN {self.mirror.install} + RUN {self.mirror.install_command} ENV LANG=C.UTF-8 LC_ALL=C LANGUAGE=C DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends sudo diff --git a/polycotylus/_mirror.py b/polycotylus/_mirror.py index c37def6..00b8982 100644 --- a/polycotylus/_mirror.py +++ b/polycotylus/_mirror.py @@ -27,7 +27,7 @@ class CachedMirror: """ def __init__(self, base_url, base_dir, index_patterns, ignore_patterns, - port, install, last_sync_time, package_version_pattern="(.+)()()", + port, install_command, last_sync_time, package_version_pattern="(.+)()()", handler=None): """ Args: @@ -43,7 +43,7 @@ def __init__(self, base_url, base_dir, index_patterns, ignore_patterns, 404 errors. This can usually be left empty. port: An integer port number. Any number not already used will do. - install: + install_command: A shell command which replaces the distribution's list of mirrors with this mirror. last_sync_time: @@ -65,8 +65,8 @@ def __init__(self, base_url, base_dir, index_patterns, ignore_patterns, if platform.system() in ("Darwin", "Windows"): # pragma: no cover # Docker's --network=host option doesn't work on macOS or Windows. # https://github.com/docker/for-mac/issues/1031 - install = install.replace("localhost", "host.docker.internal") - self.install = install + install_command = install_command.replace("localhost", "host.docker.internal") + self.install_command = install_command self._lock = threading.Lock() self._listeners = 0 self.last_sync_time = last_sync_time @@ -79,7 +79,7 @@ def with_(self, **kwargs): base_url=self.base_url, base_dir=self.base_dir, index_patterns=self.index_patterns, ignore_patterns=self.ignore_patterns, port=self.port, - install=self.install, last_sync_time=self.last_sync_time, + install_command=self.install_command, last_sync_time=self.last_sync_time, package_version_pattern=self.package_version_pattern, handler=self.handler, ) @@ -103,7 +103,7 @@ def serve(self): """Enable this mirror and block until killed (via Ctrl+C).""" with self: print(f"http://localhost:{self.port}", "=>", self.base_url) - print(f"Install via:\n{self.install}") + print(f"Install via:\n{self.install_command}") self.verbose = True with contextlib.suppress(KeyboardInterrupt): while True: @@ -452,7 +452,7 @@ def upstream_url(self): base_url=_manjaro_preferred_mirror, base_dir=cache_root / "manjaro", port=8903, - install="if grep -q /arm-stable/ /etc/pacman.d/mirrorlist ; then echo 'Server = http://localhost:8903/arm-stable/$repo/$arch' > /etc/pacman.d/mirrorlist; else echo 'Server = http://localhost:8903/stable/$repo/$arch' > /etc/pacman.d/mirrorlist; fi; sed -i 's/#Color/Color/' /etc/pacman.conf", + install_command="if grep -q /arm-stable/ /etc/pacman.d/mirrorlist ; then echo 'Server = http://localhost:8903/arm-stable/$repo/$arch' > /etc/pacman.d/mirrorlist; else echo 'Server = http://localhost:8903/stable/$repo/$arch' > /etc/pacman.d/mirrorlist; fi; sed -i 's/#Color/Color/' /etc/pacman.conf", ) mirrors["opensuse"] = CachedMirror( "http://download.opensuse.org", @@ -478,7 +478,7 @@ def upstream_url(self): base_url="http://archive.ubuntu.com/ubuntu/", base_dir=cache_root / "ubuntu2304", port=8906, - install=r"sed -i -E 's|http://(.*).ubuntu.com/|http://localhost:8906/\1/|g' /etc/apt/sources.list", + install_command=r"sed -i -E 's|http://(.*).ubuntu.com/|http://localhost:8906/\1/|g' /etc/apt/sources.list", handler=UbuntuRequestHandler, ) mirrors["ubuntu2310"] = mirrors["ubuntu2304"].with_( diff --git a/polycotylus/_opensuse.py b/polycotylus/_opensuse.py index 0631578..6207b03 100644 --- a/polycotylus/_opensuse.py +++ b/polycotylus/_opensuse.py @@ -57,7 +57,7 @@ def __init__(self, project, architecture=None): def _package_manager_queries(cls): with cls.mirror: container = _docker.run(cls.base_image, f""" - {cls.mirror.install} + {cls.mirror.install_command} zypper refresh zypper search > /packages zypper info --requires osc > /osc-info @@ -287,7 +287,7 @@ def dockerfile(self): out = self._formatter(f""" FROM {self.base_image} as base - RUN {self.mirror.install} + RUN {self.mirror.install_command} RUN mkdir /io WORKDIR /io diff --git a/polycotylus/_void.py b/polycotylus/_void.py index ead2df2..ee259d7 100644 --- a/polycotylus/_void.py +++ b/polycotylus/_void.py @@ -65,7 +65,7 @@ def build_test_image(self): def _package_manager_queries(cls): with cls.mirror: container = _docker.run(cls.base_image, f""" - {cls.mirror.install} + {cls.mirror.install_command} xbps-install -ySu xbps xbps-query -Rs '' > /all xbps-query -Rx base-chroot > /base @@ -100,7 +100,7 @@ def dockerfile(self): return self._formatter(f""" ARG tag FROM ghcr.io/void-linux/void-linux:${{tag}} AS base - RUN {self.mirror.install} + RUN {self.mirror.install_command} RUN rm -f /etc/xbps.d/noextract.conf RUN xbps-install -ySu xbps bash shadow sudo CMD ["/bin/bash"] diff --git a/tests/shared.py b/tests/shared.py index b9ea9fa..8e6be38 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -71,7 +71,7 @@ def test_python_extras(self, monkeypatch): for (packages, imports) in _group_python_extras(self.cls.python_extras): mirror = self.cls.mirror script = self.cls._formatter(f""" - {mirror.install} + {mirror.install_command} {self.package_install} python3 {shlex.join(packages)} python3 -c 'import {", ".join(imports)}' """) diff --git a/tests/test_alpine.py b/tests/test_alpine.py index fd05ed2..7bb2970 100644 --- a/tests/test_alpine.py +++ b/tests/test_alpine.py @@ -52,7 +52,7 @@ def test_abuild_lint(): self.generate() with self.mirror: _docker.run(Alpine.base_image, f""" - {self.mirror.install} + {self.mirror.install_command} apk add -q atools apkbuild-lint /io/APKBUILD """, volumes=[(self.distro_root, "/io")], architecture=self.docker_architecture) diff --git a/tests/test_manjaro.py b/tests/test_manjaro.py index dbe8f6d..1db8d47 100644 --- a/tests/test_manjaro.py +++ b/tests/test_manjaro.py @@ -30,7 +30,7 @@ def test_mirror_detection(monkeypatch): with Manjaro.mirror: for architecture in ["x86_64", "aarch64"]: _docker.run("manjarolinux/base", f""" - {Manjaro.mirror.install} + {Manjaro.mirror.install_command} pacman -Sy """, architecture=architecture, tty=True) assert requests, "Mirror is being ignored" diff --git a/tests/test_mirror.py b/tests/test_mirror.py index 1ac4f7a..df774a1 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -29,7 +29,7 @@ def _alpine_mirror(tmp_path): _alpine.index_patterns, ["*.penguin"], 9989, - _alpine.install.replace("8901", "9989"), + _alpine.install_command.replace("8901", "9989"), (_alpine_sync_time,), ) @@ -254,7 +254,7 @@ def test_tar_integrity(tmp_path): for i in range(3): with self: - _docker.run("alpine", f"{self.install} && apk add libbz2") + _docker.run("alpine", f"{self.install_command} && apk add libbz2") @pytest.mark.filterwarnings("ignore", category=pytest.PytestUnhandledThreadExceptionWarning)