tiramisu/tiramisu/storage/dictionary/setting.py

71 lines
2.4 KiB
Python
Raw Normal View History

2013-08-14 23:06:31 +02:00
# -*- coding: utf-8 -*-
"default plugin for setting: set it in a simple dictionary"
# Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ____________________________________________________________
2013-09-22 20:57:52 +02:00
from ..util import Cache
2013-08-14 23:06:31 +02:00
2013-08-20 09:47:12 +02:00
class Settings(Cache):
2013-08-14 23:06:31 +02:00
__slots__ = ('_properties', '_permissives')
2013-08-20 22:45:11 +02:00
def __init__(self, storage):
2013-08-14 23:06:31 +02:00
# properties attribute: the name of a property enables this property
# key is None for global properties
self._properties = {}
# permissive properties
self._permissives = {}
2013-08-27 09:46:52 +02:00
super(Settings, self).__init__(storage)
2013-08-14 23:06:31 +02:00
# propertives
def setproperties(self, path, properties):
self._properties[path] = properties
2013-08-14 23:06:31 +02:00
def getproperties(self, path, default_properties):
return self._properties.get(path, set(default_properties))
2013-08-14 23:06:31 +02:00
def hasproperties(self, path):
return path in self._properties
2013-08-14 23:06:31 +02:00
2013-08-20 09:47:12 +02:00
def reset_all_propertives(self):
2013-08-19 11:01:21 +02:00
self._properties.clear()
2013-08-14 23:06:31 +02:00
def reset_properties(self, path):
2013-08-14 23:06:31 +02:00
try:
del(self._properties[path])
2013-08-14 23:06:31 +02:00
except KeyError:
pass
# permissive
def setpermissive(self, path, permissive):
self._permissives[path] = frozenset(permissive)
2013-08-14 23:06:31 +02:00
def getpermissive(self, path=None):
return self._permissives.get(path, frozenset())
2013-09-22 20:57:52 +02:00
def get_modified_properties(self):
"""return all modified settings in a dictionary
example: {'path1': set(['prop1', 'prop2'])}
"""
return self._properties
def get_modified_permissives(self):
"""return all modified permissives in a dictionary
example: {'path1': set(['perm1', 'perm2'])}
"""
return self._permissives