suppression of the notion of normal and expert mode
This commit is contained in:
parent
a88d203790
commit
d05feb78f9
6 changed files with 16 additions and 52 deletions
|
@ -92,6 +92,7 @@ corresponding convenience API provided:
|
||||||
`enable()`:
|
`enable()`:
|
||||||
set the `disabled` attribute to `False`
|
set the `disabled` attribute to `False`
|
||||||
|
|
||||||
|
..
|
||||||
mode
|
mode
|
||||||
|
|
||||||
a mode is `normal` or `expert`, just a category of `Option()` or
|
a mode is `normal` or `expert`, just a category of `Option()` or
|
||||||
|
|
|
@ -251,16 +251,6 @@ def test_setoption_from_option():
|
||||||
booloption.setoption(cfg, False, 'owner')
|
booloption.setoption(cfg, False, 'owner')
|
||||||
assert cfg.bool == False
|
assert cfg.bool == False
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
def test_set_mode_in_config():
|
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True,
|
|
||||||
mode='expert')
|
|
||||||
descr = OptionDescription('descr', '', [booloption])
|
|
||||||
cfg = Config(descr)
|
|
||||||
cfg.cfgimpl_set_mode('expert')
|
|
||||||
raises(ModeOptionError, "cfg.bool")
|
|
||||||
cfg.cfgimpl_set_mode('normal')
|
|
||||||
assert cfg.bool == True
|
|
||||||
#____________________________________________________________
|
|
||||||
def test_dwim_set():
|
def test_dwim_set():
|
||||||
descr = OptionDescription("opt", "", [
|
descr = OptionDescription("opt", "", [
|
||||||
OptionDescription("sub", "", [
|
OptionDescription("sub", "", [
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
# Option and OptionDescription modes
|
|
||||||
modes = ['normal', 'expert']
|
|
||||||
|
|
||||||
class HiddenBaseType(object):
|
class HiddenBaseType(object):
|
||||||
hidden = False
|
hidden = False
|
||||||
|
@ -42,12 +40,3 @@ class DisabledBaseType(object):
|
||||||
def _is_disabled(self):
|
def _is_disabled(self):
|
||||||
return self.disabled
|
return self.disabled
|
||||||
|
|
||||||
class ModeBaseType(object):
|
|
||||||
mode = 'normal'
|
|
||||||
def get_mode(self):
|
|
||||||
return self.mode
|
|
||||||
def set_mode(self, mode):
|
|
||||||
if mode not in modes:
|
|
||||||
raise TypeError("Unknown mode: {0}".format(mode))
|
|
||||||
self.mode = mode
|
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ from copy import copy
|
||||||
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
|
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
|
||||||
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
||||||
SpecialOwnersError, MandatoryError, MethodCallError,
|
SpecialOwnersError, MandatoryError, MethodCallError,
|
||||||
DisabledOptionError, ModeOptionError)
|
DisabledOptionError)
|
||||||
from tiramisu.option import (OptionDescription, Option, SymLinkOption, group_types,
|
from tiramisu.option import (OptionDescription, Option, SymLinkOption, group_types,
|
||||||
Multi, apply_requires, modes)
|
Multi, apply_requires)
|
||||||
from tiramisu.autolib import special_owners, special_owner_factory
|
from tiramisu.autolib import special_owners, special_owner_factory
|
||||||
# ______________________________________________________________________
|
# ______________________________________________________________________
|
||||||
# generic owner. 'default' is the general config owner after init time
|
# generic owner. 'default' is the general config owner after init time
|
||||||
|
@ -39,7 +39,6 @@ class Config(object):
|
||||||
_cfgimpl_frozen = False
|
_cfgimpl_frozen = False
|
||||||
_cfgimpl_owner = default_owner
|
_cfgimpl_owner = default_owner
|
||||||
_cfgimpl_toplevel = None
|
_cfgimpl_toplevel = None
|
||||||
_cfgimpl_mode = 'normal'
|
|
||||||
|
|
||||||
def __init__(self, descr, parent=None, **overrides):
|
def __init__(self, descr, parent=None, **overrides):
|
||||||
self._cfgimpl_descr = descr
|
self._cfgimpl_descr = descr
|
||||||
|
@ -184,12 +183,6 @@ class Config(object):
|
||||||
(opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()):
|
(opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()):
|
||||||
raise DisabledOptionError("this option is disabled:"
|
raise DisabledOptionError("this option is disabled:"
|
||||||
" {0}".format(name))
|
" {0}".format(name))
|
||||||
# expert options
|
|
||||||
# XXX currently doesn't look at the group, is it really necessary ?
|
|
||||||
if self._cfgimpl_toplevel._cfgimpl_mode != 'normal':
|
|
||||||
if opt_or_descr.get_mode() != 'normal':
|
|
||||||
raise ModeOptionError("this option's mode is not normal:"
|
|
||||||
" {0}".format(name))
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# attribute access by passing a path,
|
# attribute access by passing a path,
|
||||||
|
@ -441,13 +434,6 @@ class Config(object):
|
||||||
rootconfig._cfgimpl_disabled = True
|
rootconfig._cfgimpl_disabled = True
|
||||||
rootconfig._cfgimpl_mandatory = True
|
rootconfig._cfgimpl_mandatory = True
|
||||||
|
|
||||||
def cfgimpl_set_mode(self, mode):
|
|
||||||
# normal or expert mode
|
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
|
||||||
if mode not in modes:
|
|
||||||
raise ConfigError("mode {0} not available".format(mode))
|
|
||||||
rootconfig._cfgimpl_mode = mode
|
|
||||||
|
|
||||||
def cfgimpl_read_write(self):
|
def cfgimpl_read_write(self):
|
||||||
# hung up on freeze, hidden and disabled concepts
|
# hung up on freeze, hidden and disabled concepts
|
||||||
self.cfgimpl_unfreeze()
|
self.cfgimpl_unfreeze()
|
||||||
|
|
|
@ -22,6 +22,4 @@ class MandatoryError(Exception):
|
||||||
pass
|
pass
|
||||||
class SpecialOwnersError(Exception):
|
class SpecialOwnersError(Exception):
|
||||||
pass
|
pass
|
||||||
class ModeOptionError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from tiramisu.autolib import special_owners
|
from tiramisu.autolib import special_owners
|
||||||
from tiramisu.basetype import HiddenBaseType, DisabledBaseType, ModeBaseType, modes
|
from tiramisu.basetype import HiddenBaseType, DisabledBaseType
|
||||||
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError,
|
||||||
SpecialOwnersError, RequiresError, RequirementRecursionError)
|
SpecialOwnersError, RequiresError, RequirementRecursionError)
|
||||||
available_actions = ['hide', 'show', 'enable', 'disable']
|
available_actions = ['hide', 'show', 'enable', 'disable']
|
||||||
|
@ -80,7 +80,7 @@ class Multi(list):
|
||||||
super(Multi, self).pop(key)
|
super(Multi, self).pop(key)
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
#
|
#
|
||||||
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
class Option(HiddenBaseType, DisabledBaseType):
|
||||||
#reminder: an Option object is **not** a container for the value
|
#reminder: an Option object is **not** a container for the value
|
||||||
_frozen = False
|
_frozen = False
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
|
@ -379,7 +379,7 @@ class ArbitraryOption(Option):
|
||||||
return self.defaultfactory()
|
return self.defaultfactory()
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
class OptionDescription(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
class OptionDescription(HiddenBaseType, DisabledBaseType):
|
||||||
group_type = 'default'
|
group_type = 'default'
|
||||||
|
|
||||||
def __init__(self, name, doc, children, requires=None):
|
def __init__(self, name, doc, children, requires=None):
|
||||||
|
|
Loading…
Reference in a new issue