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