]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make Distribution enum string-based
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Tue, 4 Oct 2022 14:51:00 +0000 (16:51 +0200)
committerJoerg Behrmann <behrmann@physik.fu-berlin.de>
Tue, 22 Nov 2022 15:47:50 +0000 (16:47 +0100)
mkosi/backend.py

index 19db7fe30ec2ca212c4308c8af9da696716c9862..fc87f8c7605776e66f5856c7e3fa470078f1bec7 100644 (file)
@@ -143,33 +143,34 @@ class Verb(enum.Enum):
 class Distribution(enum.Enum):
     package_type: PackageType
 
-    fedora = 0, PackageType.rpm
-    debian = 1, PackageType.deb
-    ubuntu = 2, PackageType.deb
-    arch = 3, PackageType.pkg
-    opensuse = 4, PackageType.rpm
-    mageia = 5, PackageType.rpm
-    centos = 6, PackageType.rpm
-    centos_epel = 7, PackageType.rpm
-    openmandriva = 10, PackageType.rpm
-    rocky = 11, PackageType.rpm
-    rocky_epel = 12, PackageType.rpm
-    alma = 13, PackageType.rpm
-    alma_epel = 14, PackageType.rpm
-    gentoo = 15, PackageType.ebuild
-
-    def __new__(cls, number: int, package_type: PackageType) -> Distribution:
+    fedora       = "fedora", PackageType.rpm
+    debian       = "debian", PackageType.deb
+    ubuntu       = "ubuntu", PackageType.deb
+    arch         = "arch", PackageType.pkg
+    opensuse     = "opensuse", PackageType.rpm
+    mageia       = "mageia", PackageType.rpm
+    centos       = "centos", PackageType.rpm
+    centos_epel  = "centos_epel", PackageType.rpm
+    openmandriva = "openmandriva", PackageType.rpm
+    rocky        = "rocky", PackageType.rpm
+    rocky_epel   = "rocky_epel", PackageType.rpm
+    alma         = "alma", PackageType.rpm
+    alma_epel    = "alma_epel", PackageType.rpm
+    gentoo       = "gentoo", PackageType.ebuild
+
+    def __new__(cls, name: str, package_type: PackageType) -> "Distribution":
         # This turns the list above into enum entries with .package_type attributes.
         # See https://docs.python.org/3.9/library/enum.html#when-to-use-new-vs-init
         # for an explanation.
         entry = object.__new__(cls)
-        entry._value_ = number
+        entry._value_ = name
         entry.package_type = package_type
         return entry
 
     def __str__(self) -> str:
         return self.name
 
+
 def is_rpm_distribution(d: Distribution) -> bool:
     return d in (
         Distribution.fedora,