debian/lib/python/debian_linux/kconfig.py:
Replace entry classes with version from kconfigeditor2. svn path=/dists/trunk/linux/; revision=20669
This commit is contained in:
parent
3c66fca7f0
commit
f1f381b411
|
@ -5,41 +5,55 @@ __all__ = (
|
|||
)
|
||||
|
||||
|
||||
class EntryString(object):
|
||||
__slots__ = "name", "value"
|
||||
class KConfigEntry(object):
|
||||
__slots__ = 'name', 'value', 'comments'
|
||||
|
||||
def __init__(self, name, value):
|
||||
self.name = name
|
||||
self.value = value
|
||||
def __init__(self, name, value, comments=None):
|
||||
self.name, self.value = name, value
|
||||
self.comments = comments or []
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.value == other.value
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.name) | hash(self.value)
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}({!r}, {!r}, {!r})>'.format(self.__class__.__name__, self.name, self.value, self.comments)
|
||||
|
||||
def __str__(self):
|
||||
return "CONFIG_%s=%s" % (self.name, self.value)
|
||||
return 'CONFIG_{}={}'.format(self.name, self.value)
|
||||
|
||||
def write(self):
|
||||
for comment in self.comments:
|
||||
yield '#. ' + comment
|
||||
yield str(self)
|
||||
|
||||
|
||||
class EntryTristate(object):
|
||||
__slots__ = "name", "value"
|
||||
class KConfigEntryTristate(KConfigEntry):
|
||||
__slots__ = ()
|
||||
|
||||
VALUE_NO = 0
|
||||
VALUE_YES = 1
|
||||
VALUE_MOD = 2
|
||||
VALUE_NO = False
|
||||
VALUE_YES = True
|
||||
VALUE_MOD = object()
|
||||
|
||||
def __init__(self, name, value=None):
|
||||
self.name = name
|
||||
def __init__(self, name, value, comments=None):
|
||||
if value == 'n' or value is None:
|
||||
self.value = self.VALUE_NO
|
||||
value = self.VALUE_NO
|
||||
elif value == 'y':
|
||||
self.value = self.VALUE_YES
|
||||
value = self.VALUE_YES
|
||||
elif value == 'm':
|
||||
self.value = self.VALUE_MOD
|
||||
value = self.VALUE_MOD
|
||||
else:
|
||||
raise NotImplementedError
|
||||
super(KConfigEntryTristate, self).__init__(name, value, comments)
|
||||
|
||||
def __str__(self):
|
||||
conf = "CONFIG_%s" % self.name
|
||||
if self.value == self.VALUE_NO:
|
||||
return "# %s is not set" % conf
|
||||
elif self.value == self.VALUE_YES:
|
||||
return "%s=y" % conf
|
||||
elif self.value == self.VALUE_MOD:
|
||||
return "%s=m" % conf
|
||||
if self.value is self.VALUE_MOD:
|
||||
return 'CONFIG_{}=m'.format(self.name)
|
||||
if self.value:
|
||||
return 'CONFIG_{}=y'.format(self.name)
|
||||
return '# CONFIG_{} is not set'.format(self.name)
|
||||
|
||||
|
||||
class KconfigFile(OrderedDict):
|
||||
|
@ -67,9 +81,9 @@ class KconfigFile(OrderedDict):
|
|||
|
||||
def set(self, key, value):
|
||||
if value in ('y', 'm', 'n'):
|
||||
entry = EntryTristate(key, value)
|
||||
entry = KConfigEntryTristate(key, value)
|
||||
else:
|
||||
entry = EntryString(key, value)
|
||||
entry = KConfigEntry(key, value)
|
||||
self[key] = entry
|
||||
|
||||
def str_iter(self):
|
||||
|
|
Loading…
Reference in New Issue