remove (g|s)et_modified_*, now it's exportation/importation
This commit is contained in:
@ -580,7 +580,9 @@ class TiramisuOption(CommonTiramisu):
|
||||
return self._get_option().impl_get_group_type()
|
||||
|
||||
@count
|
||||
def _list(self, type='all', group_type=None):
|
||||
def _list(self,
|
||||
type='all',
|
||||
group_type=None):
|
||||
if type == 'optiondescription':
|
||||
return self.config_bag.config.getattr(self.path,
|
||||
None,
|
||||
@ -620,10 +622,6 @@ class TiramisuContextValue(TiramisuContext):
|
||||
def mandatory_warnings(self):
|
||||
return self.config_bag.config.cfgimpl_get_values().mandatory_warnings(self.config_bag)
|
||||
|
||||
@count
|
||||
def get_modified(self):
|
||||
return self.config_bag.config.cfgimpl_get_values().get_modified_values()
|
||||
|
||||
def set(self,
|
||||
path,
|
||||
value,
|
||||
@ -647,13 +645,19 @@ class TiramisuContextValue(TiramisuContext):
|
||||
self.config_bag,
|
||||
**kwargs)
|
||||
|
||||
@count
|
||||
def reset(self,
|
||||
path):
|
||||
self.config_bag.config.reset(path, self.config_bag)
|
||||
|
||||
def export(self):
|
||||
@count
|
||||
def exportation(self):
|
||||
return self.config_bag.config.cfgimpl_get_values()._p_.exportation()
|
||||
|
||||
@count
|
||||
def importation(self, values):
|
||||
return self.config_bag.config.cfgimpl_get_values()._p_.importation(values)
|
||||
|
||||
|
||||
class TiramisuContextOwner(TiramisuContext):
|
||||
@count
|
||||
@ -705,22 +709,23 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
def get(self):
|
||||
return set(self.config_bag.setting_properties)
|
||||
|
||||
@count
|
||||
def get_modified(self):
|
||||
return self.config_bag.config.cfgimpl_get_settings().get_modified_properties()
|
||||
|
||||
@count
|
||||
def set_modified(self, props):
|
||||
return self.config_bag.config.cfgimpl_get_settings().set_modified_properties(props)
|
||||
|
||||
@count
|
||||
def set(self, props):
|
||||
self.config_bag.config.cfgimpl_get_settings().set_context_properties(props)
|
||||
self.config_bag.setting_properties = self.config_bag.config.cfgimpl_get_settings().get_context_properties()
|
||||
|
||||
@count
|
||||
def reset(self):
|
||||
self.config_bag.config.cfgimpl_get_settings().reset()
|
||||
|
||||
@count
|
||||
def exportation(self):
|
||||
return self.config_bag.config.cfgimpl_get_settings()._p_.exportation()
|
||||
|
||||
@count
|
||||
def importation(self, properties):
|
||||
return self.config_bag.config.cfgimpl_get_settings()._p_.importation(properties)
|
||||
|
||||
|
||||
class TiramisuContextPermissive(TiramisuContext):
|
||||
|
||||
@ -728,6 +733,15 @@ class TiramisuContextPermissive(TiramisuContext):
|
||||
def set(self, permissives):
|
||||
self.config_bag.config.cfgimpl_get_settings().set_context_permissive(permissives)
|
||||
|
||||
@count
|
||||
def exportation(self):
|
||||
return self.config_bag.config.cfgimpl_get_settings()._pp_.exportation()
|
||||
|
||||
@count
|
||||
def importation(self, permissives):
|
||||
return self.config_bag.config.cfgimpl_get_settings()._pp_.importation(permissives)
|
||||
|
||||
|
||||
|
||||
class TiramisuContextOption(TiramisuContext):
|
||||
@count
|
||||
@ -769,11 +783,15 @@ class TiramisuContextOption(TiramisuContext):
|
||||
withvalue=withvalue)
|
||||
|
||||
@count
|
||||
def list(self, type='all', group_type=None):
|
||||
def list(self,
|
||||
type='all',
|
||||
group_type=None,
|
||||
recursive=False):
|
||||
if type == 'optiondescription':
|
||||
return self.config_bag.config.iter_groups(self.config_bag, group_type)
|
||||
elif type == 'all':
|
||||
return self.config_bag.config.cfgimpl_get_children(self.config_bag)
|
||||
return self.config_bag.config.cfgimpl_get_children(recursive,
|
||||
self.config_bag)
|
||||
else:
|
||||
raise APIError(_('unknown list type {}').format(type))
|
||||
|
||||
|
@ -100,7 +100,6 @@ class SubConfig(object):
|
||||
for woption in opt._get_dependencies(self):
|
||||
option = woption()
|
||||
option_path = option.impl_getpath(self)
|
||||
print(option_path, resetted_opts)
|
||||
if option_path in resetted_opts:
|
||||
continue
|
||||
self.reset_one_option_cache(values,
|
||||
@ -159,40 +158,6 @@ class SubConfig(object):
|
||||
return self, path[-1]
|
||||
|
||||
# ______________________________________________________________________
|
||||
# def __iter__(self, force_permissive=False):
|
||||
# """Pythonesque way of parsing group's ordered options.
|
||||
# iteration only on Options (not OptionDescriptions)"""
|
||||
# setting_properties = self.cfgimpl_get_context().cfgimpl_get_settings().get_context_properties()
|
||||
# for child in self.cfgimpl_get_description().impl_getchildren(context=self._cfgimpl_get_context()):
|
||||
# if not child.impl_is_optiondescription():
|
||||
# try:
|
||||
# name = child.impl_getname()
|
||||
# yield name, self.getattr(name,
|
||||
# force_permissive=force_permissive,
|
||||
# setting_properties=setting_properties)
|
||||
# except GeneratorExit: # pragma: optional cover
|
||||
# if sys.version_info[0] < 3:
|
||||
# raise StopIteration
|
||||
# else:
|
||||
# raise GeneratorExit()
|
||||
# except PropertiesOptionError: # pragma: optional cover
|
||||
# pass # option with properties
|
||||
#
|
||||
# def iter_all(self, force_permissive=False):
|
||||
# """A way of parsing options **and** groups.
|
||||
# iteration on Options and OptionDescriptions."""
|
||||
# for child in self.cfgimpl_get_description().impl_getchildren():
|
||||
# try:
|
||||
# yield child.impl_getname(), self.getattr(child.impl_getname(),
|
||||
# force_permissive=force_permissive)
|
||||
# except GeneratorExit: # pragma: optional cover
|
||||
# if sys.version_info[0] < 3:
|
||||
# raise StopIteration
|
||||
# else:
|
||||
# raise GeneratorExit()
|
||||
# except PropertiesOptionError: # pragma: optional cover
|
||||
# pass # option with properties
|
||||
|
||||
def iter_groups(self,
|
||||
config_bag,
|
||||
group_type=None):
|
||||
@ -207,7 +172,6 @@ class SubConfig(object):
|
||||
if group_type is not None and not isinstance(group_type,
|
||||
groups.GroupType): # pragma: optional cover
|
||||
raise TypeError(_("unknown group_type: {0}").format(group_type))
|
||||
context = self._cfgimpl_get_context()
|
||||
for child in self.cfgimpl_get_description().impl_getchildren(config_bag):
|
||||
if child.impl_is_optiondescription():
|
||||
nconfig_bag = config_bag.copy('nooption')
|
||||
@ -223,7 +187,8 @@ class SubConfig(object):
|
||||
except PropertiesOptionError: # pragma: optional cover
|
||||
pass
|
||||
|
||||
def cfgimpl_get_children(self, config_bag):
|
||||
def cfgimpl_get_children(self,
|
||||
config_bag):
|
||||
context = self._cfgimpl_get_context()
|
||||
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag):
|
||||
nconfig_bag = config_bag.copy('nooption')
|
||||
@ -844,10 +809,10 @@ class _CommonConfig(SubConfig):
|
||||
force_values=force_values,
|
||||
force_settings=force_settings)
|
||||
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
|
||||
config.cfgimpl_get_settings()._p_.set_modified_properties(self.cfgimpl_get_settings(
|
||||
)._p_.get_modified_properties())
|
||||
config.cfgimpl_get_settings()._pp_.set_modified_permissives(self.cfgimpl_get_settings(
|
||||
)._pp_.get_modified_permissives())
|
||||
config.cfgimpl_get_settings()._p_.importation(self.cfgimpl_get_settings(
|
||||
)._p_.exportation())
|
||||
config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
|
||||
)._pp_.exportation())
|
||||
return config
|
||||
|
||||
|
||||
|
@ -771,18 +771,6 @@ class Settings(object):
|
||||
self._read(rw_remove,
|
||||
rw_append)
|
||||
|
||||
#____________________________________________________________
|
||||
# get modified properties/permissives
|
||||
|
||||
def get_modified_properties(self):
|
||||
return self._p_.get_modified_properties()
|
||||
|
||||
def set_modified_properties(self, props):
|
||||
return self._p_.set_modified_properties(props)
|
||||
|
||||
def get_modified_permissives(self):
|
||||
return self._pp_.get_modified_permissives()
|
||||
|
||||
#____________________________________________________________
|
||||
# default owner methods
|
||||
|
||||
|
@ -55,13 +55,13 @@ class Properties(Cache):
|
||||
if path in self._properties:
|
||||
del(self._properties[path])
|
||||
|
||||
def get_modified_properties(self):
|
||||
def exportation(self):
|
||||
"""return all modified settings in a dictionary
|
||||
example: {'path1': set(['prop1', 'prop2'])}
|
||||
"""
|
||||
return copy(self._properties)
|
||||
|
||||
def set_modified_properties(self, properties):
|
||||
def importation(self, properties):
|
||||
self._properties = properties
|
||||
|
||||
|
||||
@ -88,12 +88,12 @@ class Permissives(Cache):
|
||||
print('getpermissive', path, ret)
|
||||
return ret
|
||||
|
||||
def get_modified_permissives(self):
|
||||
def exportation(self):
|
||||
"""return all modified permissives in a dictionary
|
||||
example: {'path1': set(['perm1', 'perm2'])}
|
||||
"""
|
||||
return copy(self._permissives)
|
||||
|
||||
def set_modified_permissives(self, permissives):
|
||||
def importation(self, permissives):
|
||||
self._permissives = permissives
|
||||
|
||||
|
@ -176,26 +176,6 @@ class Values(Cache):
|
||||
_resetvalue(3)
|
||||
self._values = tuple(values)
|
||||
|
||||
def get_modified_values(self):
|
||||
"""return all values in a dictionary
|
||||
example: {'path1': (owner, 'value1'), 'path2': (owner, 'value2')}
|
||||
"""
|
||||
values = {}
|
||||
for idx, path in enumerate(self._values[0]):
|
||||
indexes = self._values[1][idx]
|
||||
value = self._values[2][idx]
|
||||
owner = self._values[3][idx]
|
||||
if indexes is not None:
|
||||
val = {}
|
||||
own = {}
|
||||
for cpt, index in enumerate(indexes):
|
||||
val[str(index)] = value[cpt]
|
||||
own[str(index)] = owner[cpt]
|
||||
value = val
|
||||
owner = own
|
||||
values[path] = (owner, value)
|
||||
return values
|
||||
|
||||
# owner
|
||||
def setowner(self, path, owner, index=None):
|
||||
"""change owner for a path
|
||||
|
@ -117,13 +117,13 @@ class Settings(Cache, SqlAlchemyBase):
|
||||
#replace None by a frozenset()
|
||||
return {None: frozenset()}.get(ret, ret)
|
||||
|
||||
def get_modified_properties(self):
|
||||
def exportation(self):
|
||||
"""return all modified settings in a dictionary
|
||||
example: {'path1': set(['prop1', 'prop2'])}
|
||||
"""
|
||||
return self._properties
|
||||
|
||||
def get_modified_permissives(self):
|
||||
def importation(self):
|
||||
"""return all modified permissives in a dictionary
|
||||
example: {'path1': set(['perm1', 'perm2'])}
|
||||
"""
|
||||
|
@ -111,21 +111,6 @@ class Values(Cache):
|
||||
session.delete(val)
|
||||
session.commit()
|
||||
|
||||
def get_modified_values(self):
|
||||
"""return all values in a dictionary
|
||||
example: {'path1': (owner, 'value1'), 'path2': (owner, 'value2')}
|
||||
"""
|
||||
session = self.getsession()
|
||||
ret = {}
|
||||
for val in session.query(Value).filter_by(
|
||||
session_id=self._storage.session_id).all():
|
||||
value = val.value
|
||||
if isinstance(val.value, list):
|
||||
value = tuple(val.value)
|
||||
ret[val.path] = (val.owner, value)
|
||||
del(session)
|
||||
return ret
|
||||
|
||||
# owner
|
||||
def setowner(self, path, owner, session, index=None):
|
||||
"""change owner for a path
|
||||
|
@ -57,7 +57,7 @@ class Properties(Sqlite3DB):
|
||||
self._storage.execute("DELETE FROM property WHERE path = ? AND session_id = ?",
|
||||
(path, self._session_id))
|
||||
|
||||
def get_modified_properties(self):
|
||||
def exportation(self):
|
||||
"""return all modified settings in a dictionary
|
||||
example: {'path1': set(['prop1', 'prop2'])}
|
||||
"""
|
||||
@ -70,7 +70,7 @@ class Properties(Sqlite3DB):
|
||||
ret[path] = self._sqlite_decode(properties)
|
||||
return ret
|
||||
|
||||
def set_modified_properties(self, properties):
|
||||
def importation(self, properties):
|
||||
self._storage.execute("DELETE FROM property", commit=False)
|
||||
for path, property_ in properties.items():
|
||||
self._storage.execute("INSERT INTO property(path, properties, session_id) "
|
||||
@ -104,7 +104,7 @@ class Permissives(Sqlite3DB):
|
||||
else:
|
||||
return frozenset(self._sqlite_decode(permissives[0]))
|
||||
|
||||
def get_modified_permissives(self):
|
||||
def exportation(self):
|
||||
"""return all modified permissives in a dictionary
|
||||
example: {'path1': set(['perm1', 'perm2'])}
|
||||
"""
|
||||
@ -117,7 +117,7 @@ class Permissives(Sqlite3DB):
|
||||
ret[path] = self._sqlite_decode(permissives)
|
||||
return ret
|
||||
|
||||
def set_modified_permissives(self, permissives):
|
||||
def importation(self, permissives):
|
||||
self._storage.execute("DELETE FROM permissive", commit=False)
|
||||
for path, permissive in permissives.items():
|
||||
self._storage.execute("INSERT INTO permissive(path, permissives, session_id) "
|
||||
|
@ -86,31 +86,6 @@ class Values(Sqlite3DB):
|
||||
self._storage.execute("DELETE FROM value WHERE path = ? AND session_id = ?", (path, self._session_id),
|
||||
commit=_commit)
|
||||
|
||||
def get_modified_values(self):
|
||||
"""return all values in a dictionary
|
||||
example: {option1: (owner, 'value1'), option2: (owner, 'value2')}
|
||||
"""
|
||||
ret = {}
|
||||
for path, value, owner, index, _ in self._storage.select("SELECT * FROM value WHERE "
|
||||
"session_id = ?",
|
||||
(self._session_id,),
|
||||
only_one=False):
|
||||
path = self._sqlite_decode_path(path)
|
||||
owner = getattr(owners, owner)
|
||||
|
||||
value = self._sqlite_decode(value)
|
||||
if isinstance(value, list):
|
||||
value = tuple(value)
|
||||
if index is None:
|
||||
ret[path] = (owner, value)
|
||||
else:
|
||||
if path in ret:
|
||||
ret[path][0][str(index)] = owner
|
||||
ret[path][1][str(index)] = value
|
||||
else:
|
||||
ret[path] = ({str(index): owner}, {str(index): value})
|
||||
return ret
|
||||
|
||||
# owner
|
||||
def setowner(self, path, owner, session, index=None):
|
||||
"""change owner for an option
|
||||
|
@ -315,9 +315,6 @@ class Values(object):
|
||||
isempty = value is None or value == empty
|
||||
return isempty
|
||||
|
||||
def get_modified_values(self):
|
||||
return self._p_.get_modified_values()
|
||||
|
||||
#______________________________________________________________________
|
||||
# set value
|
||||
|
||||
|
Reference in New Issue
Block a user