From b8580b79fc15031cee82efb4e8963aed52e2cb36 Mon Sep 17 00:00:00 2001 From: Joerg Behrmann Date: Thu, 24 Nov 2022 15:48:03 +0100 Subject: [PATCH] Remove unused code --- mkosi/__init__.py | 123 +---------------------------- mkosi/distributions/arch.py | 4 - mkosi/distributions/fedora.py | 9 --- tests/test_distributions_fedora.py | 16 ---- 4 files changed, 1 insertion(+), 151 deletions(-) delete mode 100644 tests/test_distributions_fedora.py diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 981824244..381126db1 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -67,7 +67,6 @@ from mkosi.backend import ( MkosiPrinter, MkosiState, OutputFormat, - PackageType, Partition, PartitionIdentifier, PartitionTable, @@ -93,7 +92,6 @@ from mkosi.backend import ( set_umask, should_compress_fs, should_compress_output, - sort_packages, spawn, tmp_dir, warn, @@ -108,7 +106,7 @@ from mkosi.install import ( open_close, ) from mkosi.manifest import Manifest -from mkosi.mounts import mount, mount_api_vfs, mount_bind, mount_overlay, mount_tmpfs +from mkosi.mounts import mount, mount_bind, mount_overlay, mount_tmpfs from mkosi.remove import unlink_try_hard from mkosi.syscall import blkpg_add_partition, blkpg_del_partition @@ -1567,64 +1565,6 @@ def remove_files(state: MkosiState) -> None: remove_glob(*paths) -def invoke_dnf(state: MkosiState, command: str, packages: Iterable[str]) -> None: - release = state.config.release - - config_file = state.workspace / "dnf.conf" - - cmd = 'dnf' if shutil.which('dnf') else 'yum' - - cmdline = [ - cmd, - "-y", - f"--config={config_file}", - "--best", - "--allowerasing", - f"--releasever={release}", - f"--installroot={state.root}", - "--setopt=keepcache=1", - "--setopt=install_weak_deps=0", - "--noplugins", - ] - - if not state.config.repository_key_check: - cmdline += ["--nogpgcheck"] - - if state.config.repositories: - cmdline += ["--disablerepo=*"] + [f"--enablerepo={repo}" for repo in state.config.repositories] - - # TODO: this breaks with a local, offline repository created with 'createrepo' - if state.config.with_network == "never" and not state.config.local_mirror: - cmdline += ["-C"] - - if not state.config.architecture_is_native(): - cmdline += [f"--forcearch={state.config.architecture}"] - - if not state.config.with_docs: - cmdline += ["--nodocs"] - - cmdline += [command, *sort_packages(packages)] - - with mount_api_vfs(state.root): - run(cmdline, env={"KERNEL_INSTALL_BYPASS": state.environment.get("KERNEL_INSTALL_BYPASS", "1")}) - - distribution, _ = detect_distribution() - if distribution not in (Distribution.debian, Distribution.ubuntu): - return - - # On Debian, rpm/dnf ship with a patch to store the rpmdb under ~/ - # so it needs to be copied back in the right location, otherwise - # the rpmdb will be broken. See: https://bugs.debian.org/1004863 - rpmdb_home = state.root / "root/.rpmdb" - if rpmdb_home.exists(): - # Take into account the new location in F36 - rpmdb = state.root / "usr/lib/sysimage/rpm" - if not rpmdb.exists(): - rpmdb = state.root / "var/lib/rpm" - unlink_try_hard(rpmdb) - shutil.move(cast(str, rpmdb_home), rpmdb) - - def link_rpm_db(root: Path) -> None: """Link /var/lib/rpm to /usr/lib/sysimage/rpm for compat with old rpm""" rpmdb = root / "usr/lib/sysimage/rpm" @@ -1640,67 +1580,6 @@ def link_rpm_db(root: Path) -> None: rpmdb_old.symlink_to("../../usr/lib/sysimage/rpm") -def install_packages_dnf(state: MkosiState, packages: Set[str],) -> None: - packages = make_rpm_list(state, packages) - invoke_dnf(state, 'install', packages) - - -class Repo(NamedTuple): - id: str - url: str - gpgpath: Path - gpgurl: Optional[str] = None - - -def setup_dnf(state: MkosiState, repos: Sequence[Repo] = ()) -> None: - gpgcheck = True - - repo_file = state.workspace / "mkosi.repo" - with repo_file.open("w") as f: - for repo in repos: - gpgkey: Optional[str] = None - - if repo.gpgpath.exists(): - gpgkey = f"file://{repo.gpgpath}" - elif repo.gpgurl: - gpgkey = repo.gpgurl - else: - warn(f"GPG key not found at {repo.gpgpath}. Not checking GPG signatures.") - gpgcheck = False - - f.write( - dedent( - f"""\ - [{repo.id}] - name={repo.id} - {repo.url} - gpgkey={gpgkey or ''} - enabled=1 - """ - ) - ) - - if state.config.use_host_repositories: - default_repos = "" - else: - default_repos = f"reposdir={state.workspace} {state.config.repos_dir if state.config.repos_dir else ''}" - - vars_dir = state.workspace / "vars" - vars_dir.mkdir(exist_ok=True) - - config_file = state.workspace / "dnf.conf" - config_file.write_text( - dedent( - f"""\ - [main] - gpgcheck={'1' if gpgcheck else '0'} - {default_repos } - varsdir={vars_dir} - """ - ) - ) - - def parse_epel_release(release: str) -> int: fields = release.split(".") if fields[0].endswith("-stream"): diff --git a/mkosi/distributions/arch.py b/mkosi/distributions/arch.py index 19cee1570..fc2baa2a5 100644 --- a/mkosi/distributions/arch.py +++ b/mkosi/distributions/arch.py @@ -137,10 +137,6 @@ def install_arch(state: MkosiState) -> None: ) ) - keyring = "archlinux" - if platform.machine() == "aarch64": - keyring += "arm" - packages: Set[str] = set() add_packages(state.config, packages, "base") diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index 4b8043e7e..97c94386b 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -74,15 +74,6 @@ class FedoraInstaller(DistributionInstaller): invoke_dnf(state, 'remove', remove) -def fedora_release_cmp(a: str, b: str) -> int: - """Return negative if a Tuple[str, str]: if release.startswith("rawhide-"): release, releasever = release.split("-") diff --git a/tests/test_distributions_fedora.py b/tests/test_distributions_fedora.py deleted file mode 100644 index 8cbe58221..000000000 --- a/tests/test_distributions_fedora.py +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1+ - -import pytest - -from mkosi.distributions.fedora import fedora_release_cmp - - -def test_fedora_release_cmp() -> None: - assert fedora_release_cmp("rawhide", "rawhide") == 0 - assert fedora_release_cmp("32", "32") == 0 - assert fedora_release_cmp("33", "32") > 0 - assert fedora_release_cmp("30", "31") < 0 - assert fedora_release_cmp("-1", "-2") > 0 - assert fedora_release_cmp("1", "-2") > 0 - with pytest.raises(ValueError): - fedora_release_cmp("literal", "rawhide") -- 2.47.3