dnf/0075-Generalize-_BoolDefault-to-just-_Default-allow-choic.patch
Aleš Matěj 3d5ca2af86 Add dedicated lock for clean command
Resolves: RHEL-83124
2026-07-14 14:04:18 +02:00

51 lines
1.6 KiB
Diff

From 181a8762ccd830ebc1c7077cbbeaf621d2a0d08b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Tue, 7 Jul 2026 07:48:29 +0200
Subject: [PATCH 2/4] Generalize _BoolDefault to just _Default, allow choices
This is useful if we want a demand with more states than just True/False
---
dnf/cli/demand.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/dnf/cli/demand.py b/dnf/cli/demand.py
index f82a75b1..ac19930b 100644
--- a/dnf/cli/demand.py
+++ b/dnf/cli/demand.py
@@ -21,9 +21,10 @@
from __future__ import unicode_literals
-class _BoolDefault(object):
- def __init__(self, default):
+class _Default(object):
+ def __init__(self, default, choices=None):
self.default = default
+ self.choices = choices
self._storing_name = '__%s%x' % (self.__class__.__name__, id(self))
def __get__(self, obj, objtype=None):
@@ -33,6 +34,8 @@ class _BoolDefault(object):
return self.default
def __set__(self, obj, val):
+ if self.choices is not None and val not in self.choices:
+ raise ValueError('Invalid demand value: %s' % val)
objdict = obj.__dict__
if self._storing_name in objdict:
current_val = objdict[self._storing_name]
@@ -40,6 +43,10 @@ class _BoolDefault(object):
raise AttributeError('Demand already set.')
objdict[self._storing_name] = val
+
+_BoolDefault = _Default
+
+
class DemandSheet(object):
"""Collection of demands that different CLI parts have on other parts. :api"""
--
2.54.0