opt.hidden and opt.disabled is replaced by opt.properties
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
"enables us to carry out a calculation and return an option's value"
|
||||
from tiramisu.error import DisabledOptionError, SpecialOwnersError
|
||||
from tiramisu.error import PropertiesOptionError, SpecialOwnersError
|
||||
# ____________________________________________________________
|
||||
# automatic Option object
|
||||
special_owners = ['auto', 'fill']
|
||||
@ -45,10 +45,10 @@ def calc_factory(name, callback, callback_params, config):
|
||||
try:
|
||||
opt_value = getattr(config, path)
|
||||
opt = config.unwrap_from_path(path)
|
||||
except DisabledOptionError, e:
|
||||
except PropertiesOptionError, e:
|
||||
if chek_disabled:
|
||||
continue
|
||||
raise DisabledOptionError(e)
|
||||
raise PropertiesOptionError(e)
|
||||
is_multi = opt.is_multi()
|
||||
if is_multi:
|
||||
if opt_value != None:
|
||||
|
@ -21,7 +21,11 @@
|
||||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
|
||||
class HiddenBaseType(object):
|
||||
class BaseType(object):
|
||||
def has_properties(self):
|
||||
return bool(len(self.properties))
|
||||
|
||||
class HiddenBaseType(BaseType):
|
||||
def hide(self):
|
||||
if not 'hidden' in self.properties:
|
||||
self.properties.append('hidden')
|
||||
@ -32,7 +36,7 @@ class HiddenBaseType(object):
|
||||
# dangerous method: how an Option() can determine its status by itself ?
|
||||
return 'hidden' in self.properties
|
||||
|
||||
class DisabledBaseType(object):
|
||||
class DisabledBaseType(BaseType):
|
||||
def disable(self):
|
||||
if not 'disabled' in self.properties:
|
||||
self.properties.append('disabled')
|
||||
|
@ -21,9 +21,9 @@
|
||||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
from copy import copy
|
||||
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
|
||||
from tiramisu.error import (PropertiesOptionError, ConfigError, NotFoundError,
|
||||
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
||||
SpecialOwnersError, MandatoryError, MethodCallError, DisabledOptionError)
|
||||
SpecialOwnersError, MandatoryError, MethodCallError)
|
||||
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
|
||||
group_types, Multi, apply_requires)
|
||||
from tiramisu.autolib import special_owners, special_owner_factory
|
||||
@ -32,8 +32,7 @@ from tiramisu.autolib import special_owners, special_owner_factory
|
||||
default_owner = 'user'
|
||||
# ____________________________________________________________
|
||||
class Config(object):
|
||||
_cfgimpl_hidden = True
|
||||
_cfgimpl_disabled = True
|
||||
_cfgimpl_properties = ['hidden', 'disabled']
|
||||
_cfgimpl_mandatory = True
|
||||
_cfgimpl_frozen = False
|
||||
_cfgimpl_owner = default_owner
|
||||
@ -126,33 +125,40 @@ class Config(object):
|
||||
if isinstance(child, OptionDescription):
|
||||
self._cfgimpl_values[child._name].cfgimpl_set_owner(owner)
|
||||
# ____________________________________________________________
|
||||
def _cfgimpl_has_properties(self):
|
||||
return bool(len(self._cfgimpl_properties))
|
||||
|
||||
def cfgimpl_hide(self):
|
||||
if self._cfgimpl_parent != None:
|
||||
raise MethodCallError("this method root_hide() shall not be"
|
||||
"used with non-root Config() object")
|
||||
rootconfig = self._cfgimpl_get_toplevel()
|
||||
rootconfig._cfgimpl_hidden = True
|
||||
if 'hidden' not in rootconfig._cfgimpl_properties:
|
||||
rootconfig._cfgimpl_properties.append('hidden')
|
||||
|
||||
def cfgimpl_show(self):
|
||||
if self._cfgimpl_parent != None:
|
||||
raise MethodCallError("this method root_hide() shall not be"
|
||||
"used with non-root Config() object")
|
||||
rootconfig = self._cfgimpl_get_toplevel()
|
||||
rootconfig._cfgimpl_hidden = False
|
||||
# ____________________________________________________________
|
||||
if 'hidden' in rootconfig._cfgimpl_properties:
|
||||
rootconfig._cfgimpl_properties.remove('hidden')
|
||||
|
||||
def cfgimpl_disable(self):
|
||||
if self._cfgimpl_parent != None:
|
||||
raise MethodCallError("this method root_hide() shall not be"
|
||||
"used with non-root Confit() object")
|
||||
rootconfig = self._cfgimpl_get_toplevel()
|
||||
rootconfig._cfgimpl_disabled = True
|
||||
|
||||
if 'disabled' not in rootconfig._cfgimpl_properties:
|
||||
rootconfig._cfgimpl_properties.append('disabled')
|
||||
|
||||
def cfgimpl_enable(self):
|
||||
if self._cfgimpl_parent != None:
|
||||
raise MethodCallError("this method root_hide() shall not be"
|
||||
"used with non-root Confit() object")
|
||||
rootconfig = self._cfgimpl_get_toplevel()
|
||||
rootconfig._cfgimpl_disabled = False
|
||||
if 'disabled' in rootconfig._cfgimpl_properties:
|
||||
rootconfig._cfgimpl_properties.remove('disabled')
|
||||
# ____________________________________________________________
|
||||
def __setattr__(self, name, value):
|
||||
if '.' in name:
|
||||
@ -172,16 +178,16 @@ class Config(object):
|
||||
def _validate(self, name, opt_or_descr):
|
||||
apply_requires(opt_or_descr, self)
|
||||
if not type(opt_or_descr) == OptionDescription:
|
||||
# hidden options
|
||||
if self._cfgimpl_toplevel._cfgimpl_hidden and \
|
||||
(opt_or_descr._is_hidden() or self._cfgimpl_descr._is_hidden()):
|
||||
raise HiddenOptionError("trying to access to a hidden option:"
|
||||
" {0}".format(name))
|
||||
# disabled options
|
||||
if self._cfgimpl_toplevel._cfgimpl_disabled and \
|
||||
(opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()):
|
||||
raise DisabledOptionError("this option is disabled:"
|
||||
" {0}".format(name))
|
||||
# hidden or disabled options
|
||||
# XXX let's have a group with a hidden property
|
||||
# and an option with a disabled property,
|
||||
# then it matches anyway... is it important to fix this ?
|
||||
if self._cfgimpl_toplevel._cfgimpl_has_properties() and \
|
||||
(opt_or_descr.has_properties() or \
|
||||
self._cfgimpl_descr.has_properties()):
|
||||
raise PropertiesOptionError("trying to access to the option: {0} "
|
||||
"with properties: {1}".format(name,
|
||||
str(opt_or_descr.properties)))
|
||||
|
||||
def __getattr__(self, name):
|
||||
# attribute access by passing a path,
|
||||
@ -500,7 +506,7 @@ class Config(object):
|
||||
|
||||
def getpaths(self, include_groups=False, allpaths=False, mandatory=False):
|
||||
"""returns a list of all paths in self, recursively, taking care of
|
||||
the context (hidden/disabled)
|
||||
the context of properties (hidden/disabled)
|
||||
"""
|
||||
paths = []
|
||||
for path in self._cfgimpl_descr.getpaths(include_groups=include_groups):
|
||||
@ -528,7 +534,7 @@ def make_dict(config, flatten=False):
|
||||
value = getattr(config, path)
|
||||
pathsvalues.append((pathname, value))
|
||||
except:
|
||||
pass # this just a hidden or disabled option
|
||||
pass # this just a hidden or disabled option
|
||||
options = dict(pathsvalues)
|
||||
return options
|
||||
|
||||
|
@ -6,10 +6,8 @@ class ConfigError(Exception):
|
||||
pass
|
||||
class ConflictConfigError(ConfigError):
|
||||
pass
|
||||
class HiddenOptionError(AttributeError):
|
||||
class PropertiesOptionError(AttributeError):
|
||||
pass
|
||||
class DisabledOptionError(AttributeError):
|
||||
pass
|
||||
class NotFoundError(Exception):
|
||||
pass
|
||||
class MethodCallError(Exception):
|
||||
|
Reference in New Issue
Block a user