From: Joerg Behrmann Date: Tue, 4 Oct 2022 14:51:00 +0000 (+0200) Subject: Make Distribution enum string-based X-Git-Tag: v15~384^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3cc412f30b7d89d0a9737d573a193d88b4cb0b7;p=thirdparty%2Fmkosi.git Make Distribution enum string-based --- diff --git a/mkosi/backend.py b/mkosi/backend.py index 19db7fe30..fc87f8c76 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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,