adds information attribute to an option

This commit is contained in:
Emmanuel Garette 2013-03-12 17:45:28 +01:00
parent 729feb3239
commit e1357fd5c5
1 changed files with 24 additions and 22 deletions

View File

@ -53,7 +53,29 @@ def valid_name(name):
#____________________________________________________________ #____________________________________________________________
# #
class Option(BaseType): class BaseInformation:
informations = {}
def set_information(self, key, value):
"""updates the information's attribute
(wich is a dictionnary)
:param key: information's key (ex: "help", "doc"
:param value: information's value (ex: "the help string")
"""
self.informations[key] = value
def get_information(self, key):
"""retrieves one information's item
:param key: the item string (ex: "help")
"""
if key in self.informations:
return self.informations[key]
else:
raise ValueError("Information's item not found: {0}".format(key))
class Option(BaseType, BaseInformation):
""" """
Abstract base class for configuration option's. Abstract base class for configuration option's.
@ -87,7 +109,6 @@ class Option(BaseType):
raise NameError("invalid name: {0} for option".format(name)) raise NameError("invalid name: {0} for option".format(name))
self._name = name self._name = name
self.doc = doc self.doc = doc
self.informations = {}
self._requires = requires self._requires = requires
self._mandatory = mandatory self._mandatory = mandatory
self.multi = multi self.multi = multi
@ -195,25 +216,6 @@ class Option(BaseType):
"accesses the Option's doc" "accesses the Option's doc"
return self.doc return self.doc
def set_information(self, key, value):
"""updates the information's attribute
(wich is a dictionnary)
:param key: information's key (ex: "help", "doc"
:param value: information's value (ex: "the help string")
"""
self.informations[key] = value
def get_information(self, key):
"""retrieves one information's item
:param key: the item string (ex: "help")
"""
if key in self.informations:
return self.informations[key]
else:
raise ValueError("Information's item not found: {0}".format(key))
def getcallback(self): def getcallback(self):
"a callback is only a link, the name of an external hook" "a callback is only a link, the name of an external hook"
return self.callback return self.callback
@ -398,7 +400,7 @@ class NetmaskOption(Option):
# by now the validation is nothing but a string, use IPy instead # by now the validation is nothing but a string, use IPy instead
return isinstance(value, str) return isinstance(value, str)
class OptionDescription(BaseType): class OptionDescription(BaseType, BaseInformation):
"""Config's schema (organisation, group) and container of Options""" """Config's schema (organisation, group) and container of Options"""
# the group_type is useful for filtering OptionDescriptions in a config # the group_type is useful for filtering OptionDescriptions in a config
group_type = groups.default group_type = groups.default