generic owners shall live in settings
This commit is contained in:
parent
ca2f4487dd
commit
cda5d8c0bd
@ -117,7 +117,7 @@ class Config(object):
|
||||
return setattr(homeconfig, name, value)
|
||||
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
|
||||
self._validate(name, getattr(self._cfgimpl_descr, name))
|
||||
self.setoption(name, value, owners.user)
|
||||
self.setoption(name, value, settings.get_owner())
|
||||
|
||||
def _validate(self, name, opt_or_descr, permissive=False):
|
||||
"validation for the setattr and the getattr"
|
||||
@ -355,7 +355,7 @@ class Config(object):
|
||||
pass
|
||||
except Exception, e:
|
||||
raise e # HiddenOptionError or DisabledOptionError
|
||||
homeconfig.setoption(name, value, owners.user)
|
||||
homeconfig.setoption(name, value, settings.get_owner())
|
||||
elif len(candidates) > 1:
|
||||
raise AmbigousOptionError(
|
||||
'more than one option that ends with %s' % (key, ))
|
||||
|
@ -65,7 +65,7 @@ class Multi(list):
|
||||
super(Multi, self).__init__(lst)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
return self._setvalue(value, key, who=owners.user)
|
||||
return self._setvalue(value, key, who=settings.get_owner())
|
||||
|
||||
def append(self, value, add_master=True):
|
||||
"""the list value can be updated (appened)
|
||||
@ -79,14 +79,14 @@ class Multi(list):
|
||||
raise IndexError("in a group with a master, you mustn't add "
|
||||
"a value in a slave's Multi value")
|
||||
except TypeError:
|
||||
return self._setvalue(value, who=settings.owner)
|
||||
return self._setvalue(value, who=settings.get_owner())
|
||||
multis = []
|
||||
for name, multi in self.config:
|
||||
multis.append(multi)
|
||||
for multi in multis:
|
||||
if master == multi.opt._name:
|
||||
if add_master:
|
||||
ret = multi._setvalue(value, who=settings.owner)
|
||||
ret = multi._setvalue(value, who=settings.get_owner())
|
||||
else:
|
||||
ret = value
|
||||
else:
|
||||
@ -99,13 +99,16 @@ class Multi(list):
|
||||
if not self.opt._validate(value):
|
||||
raise ConfigError("invalid value {0} "
|
||||
"for option {1}".format(str(value), self.opt._name))
|
||||
if not isinstance(who, owners.Owner):
|
||||
raise TypeError("invalid owner {0} for the value {1}".format(
|
||||
str(who), str(value)))
|
||||
oldvalue = list(self)
|
||||
if key is None:
|
||||
ret = super(Multi, self).append(value)
|
||||
else:
|
||||
ret = super(Multi, self).__setitem__(key, value)
|
||||
if who != None:
|
||||
self.opt.setowner(self.config, who)
|
||||
self.opt.setowner(self.config, getattr(owners, who))
|
||||
self.config._cfgimpl_previous_values[self.opt._name] = oldvalue
|
||||
return ret
|
||||
|
||||
@ -140,7 +143,7 @@ class Multi(list):
|
||||
def _pop(self, key, change_who=True):
|
||||
oldvalue = list(self)
|
||||
if change_who:
|
||||
self.opt.setowner(self.config, settings.owner)
|
||||
self.opt.setowner(self.config, settings.get_owner())
|
||||
self.config._cfgimpl_previous_values[self.opt._name] = oldvalue
|
||||
return super(Multi, self).pop(key)
|
||||
# ____________________________________________________________
|
||||
@ -331,7 +334,7 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||
(not the toplevel config)
|
||||
:return: boolean
|
||||
"""
|
||||
return self.getowner(config) == 'default'
|
||||
return self.getowner(config) == owners.default
|
||||
|
||||
def setoption(self, config, value):
|
||||
"""changes the option's value with the value_owner's who
|
||||
|
@ -114,6 +114,9 @@ class Setting():
|
||||
frozen = True
|
||||
# enables validation function for options if set
|
||||
validator = False
|
||||
# generic owner
|
||||
owner = owners.user
|
||||
|
||||
#____________________________________________________________
|
||||
# properties methods
|
||||
def has_properties(self):
|
||||
@ -134,7 +137,7 @@ class Setting():
|
||||
"deletes property propname in the Config's properties attribute"
|
||||
if self.has_property(propname):
|
||||
self.properties.remove(propname)
|
||||
|
||||
#____________________________________________________________
|
||||
def set_permissive(self, permissive):
|
||||
if not isinstance(permissive, list):
|
||||
raise TypeError('permissive must be a list')
|
||||
@ -183,7 +186,12 @@ class Setting():
|
||||
|
||||
def set_owner(self, owner):
|
||||
":param owner: sets the default value for owner at the Config level"
|
||||
if not isinstance(owner, owners.Owner):
|
||||
raise TypeError("invalid generic owner {0}".format(str(owner)))
|
||||
self.owner = owner
|
||||
|
||||
def get_owner(self):
|
||||
return self.owner
|
||||
|
||||
# Setting is actually a singleton
|
||||
settings = Setting()
|
||||
|
Loading…
Reference in New Issue
Block a user