opt.hidden and opt.disabled is replaced by opt.properties

This commit is contained in:
gwen 2012-08-13 11:48:25 +02:00
parent f48c4c229b
commit 1d5330f15e
3 changed files with 20 additions and 17 deletions

View File

@ -22,21 +22,23 @@
# ____________________________________________________________
class HiddenBaseType(object):
hidden = False
def hide(self):
self.hidden = True
if not 'hidden' in self.properties:
self.properties.append('hidden')
def show(self):
self.hidden = False
if 'hidden' in self.properties:
self.properties.remove('hidden')
def _is_hidden(self):
# dangerous method: how an Option can determine its status by itself ?
return self.hidden
# dangerous method: how an Option() can determine its status by itself ?
return 'hidden' in self.properties
class DisabledBaseType(object):
disabled = False
def disable(self):
self.disabled = True
if not 'disabled' in self.properties:
self.properties.append('disabled')
def enable(self):
self.disabled = False
if 'disabled' in self.properties:
self.properties.remove('disabled')
def _is_disabled(self):
return self.disabled
return 'disabled' in self.properties

View File

@ -22,11 +22,10 @@
# ____________________________________________________________
from copy import copy
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
SpecialOwnersError, MandatoryError, MethodCallError,
DisabledOptionError)
from tiramisu.option import (OptionDescription, Option, SymLinkOption, group_types,
Multi, apply_requires)
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
SpecialOwnersError, MandatoryError, MethodCallError, DisabledOptionError)
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
group_types, Multi, apply_requires)
from tiramisu.autolib import special_owners, special_owner_factory
# ______________________________________________________________________
# generic owner. 'default' is the general config owner after init time

View File

@ -23,7 +23,7 @@
from tiramisu.autolib import special_owners
from tiramisu.basetype import HiddenBaseType, DisabledBaseType
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
SpecialOwnersError, RequiresError, RequirementRecursionError)
SpecialOwnersError, RequiresError, RequirementRecursionError)
available_actions = ['hide', 'show', 'enable', 'disable']
reverse_actions = {'hide': 'show', 'show': 'hide',
'disable':'enable', 'enable': 'disable'}
@ -119,6 +119,7 @@ class Option(HiddenBaseType, DisabledBaseType):
raise ConfigError("invalid default value {0} "
"for option {1}".format(str(default), name))
self.default = default
self.properties = [] # 'hidden', 'disabled'...
def validate(self, value):
if self.multi == False:
@ -371,7 +372,6 @@ class ArbitraryOption(Option):
return self.default
class OptionDescription(HiddenBaseType, DisabledBaseType):
group_type = 'default'
def __init__(self, name, doc, children, requires=None):
self._name = name
@ -379,6 +379,8 @@ class OptionDescription(HiddenBaseType, DisabledBaseType):
self._children = children
self._requires = requires
self._build()
self.properties = [] # 'hidden', 'disabled'...
self.group_type = 'default'
def getdoc(self):
return self.doc