76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"default plugin for value: 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
|
|
#
|
|
# ____________________________________________________________
|
|
|
|
#FIXME
|
|
from tiramisu.plugins.dictionary.cache import PluginCache
|
|
|
|
|
|
class PluginValues(PluginCache):
|
|
__slots__ = ('_values',)
|
|
|
|
def __init__(self, config_id):
|
|
"""init plugin means create values storage
|
|
"""
|
|
self._values = {}
|
|
# should init cache too
|
|
super(PluginValues, self).__init__()
|
|
|
|
# value
|
|
def _p_setvalue(self, opt, value):
|
|
"""set value for an option
|
|
a specified value must be associated to an owner
|
|
"""
|
|
owner = self.context.cfgimpl_get_settings().getowner()
|
|
self._values[opt] = (owner, value)
|
|
|
|
def _p_getvalue(self, opt):
|
|
"""get value for an option
|
|
return: only value, not the owner
|
|
"""
|
|
return self._values[opt][1]
|
|
|
|
def _p_hasvalue(self, opt):
|
|
"""if opt has a value
|
|
return: boolean
|
|
"""
|
|
return opt in self._values
|
|
|
|
def _p_resetvalue(self, opt):
|
|
"""remove value means delete value in storage
|
|
"""
|
|
del(self._values[opt])
|
|
|
|
def _p_get_modified_values(self):
|
|
"""return all values in a dictionary
|
|
example: {option1: (owner, 'value1'), option2: (owner, 'value2')}
|
|
"""
|
|
return self._values
|
|
|
|
# owner
|
|
def _p_setowner(self, opt, owner):
|
|
"""change owner for an option
|
|
"""
|
|
self._values[opt] = (owner, self._values[opt][1])
|
|
|
|
def _p_getowner(self, opt, default):
|
|
"""get owner for an option
|
|
return: owner object
|
|
"""
|
|
return self._values.get(opt, (default, None))[0]
|