]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use removeprefix and removesuffix were applicable
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Tue, 29 Nov 2022 12:54:18 +0000 (13:54 +0100)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Fri, 13 Jan 2023 14:19:03 +0000 (15:19 +0100)
mkosi/__init__.py
mkosi/distributions/centos.py
mkosi/manifest.py

index 97ba0344435aec21b234f6da32146ea5a7f7631a..e78c741988b68148d1df8d0e72260100fc061020 100644 (file)
@@ -513,12 +513,7 @@ def remove_files(state: MkosiState) -> None:
 
 def parse_epel_release(release: str) -> int:
     fields = release.split(".")
-    if fields[0].endswith("-stream"):
-        epel_release = fields[0].split("-")[0]
-    else:
-        epel_release = fields[0]
-
-    return int(epel_release)
+    return int(fields[0].removesuffix("-stream"))
 
 
 def install_distribution(state: MkosiState, cached: bool) -> None:
@@ -794,7 +789,7 @@ def copy_git_files(src: Path, dest: Path, *, source_file_transfer: SourceFileTra
         for path, _, filenames in os.walk(top):
             for filename in filenames:
                 fp = os.path.join(path, filename)  # full path
-                fr = os.path.join(".git/", fp[len(top) :])  # relative to top
+                fr = os.path.join(".git/", fp.removeprefix(top))  # relative to top
                 files.add(fr)
 
     # Get submodule files
index 7bea5ef2f6d3ccec657a6fe6f246144affffb9c8..8e93a9d20a44ae4eedd2deae600b108695338312 100644 (file)
@@ -95,18 +95,13 @@ class CentosInstaller(DistributionInstaller):
     @classmethod
     def _is_epel(cls) -> bool:
         name = cls.__name__
-        if name.endswith("Installer"):
-            name = name[:-9]
+        name = name.removesuffix("Installer")
         return name.endswith("Epel")
 
     @staticmethod
     def _parse_epel_release(release: str) -> int:
         fields = release.split(".")
-        if fields[0].endswith("-stream"):
-            epel_release = fields[0].split("-")[0]
-        else:
-            epel_release = fields[0]
-        return int(epel_release)
+        return int(fields[0].removesuffix("-stream"))
 
     @staticmethod
     def _gpg_locations(epel_release: int) -> Tuple[Path, str]:
index b13c961f4af4699f9647704ed8202795b5af643e..3bc9f691db47b6f0fc9e54f672850626e2db200b 100644 (file)
@@ -116,12 +116,12 @@ class Manifest:
             nevra, srpm, name, arch, size, installtime = package.split("\t")
 
             assert nevra.startswith(f"{name}-")
-            evra = nevra[len(name) + 1 :]
+            evra = nevra.removeprefix(f"{name}-")
             # Some packages have architecture '(none)', and it's not part of NEVRA, e.g.:
             # gpg-pubkey-45719a39-5f2c0192 gpg-pubkey (none) 0 1635985199
             if arch != "(none)":
                 assert nevra.endswith(f".{arch}")
-                evr = evra[: len(arch) + 1]
+                evr = evra.removesuffix(f".{arch}")
             else:
                 evr = evra
                 arch = ""