Merge branch 'master' into orm
Conflicts: test/test_config_api.py tiramisu/autolib.py tiramisu/config.py tiramisu/option.py tiramisu/value.py
This commit is contained in:
@ -2,26 +2,22 @@
|
||||
"sets the options of the configuration objects Config object itself"
|
||||
# Copyright (C) 2012-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 free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published by the
|
||||
# Free Software Foundation, either version 3 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.
|
||||
# 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 Lesser 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
|
||||
#
|
||||
# The original `Config` design model is unproudly borrowed from
|
||||
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
|
||||
# the whole pypy projet is under MIT licence
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from time import time
|
||||
from copy import copy
|
||||
from logging import getLogger
|
||||
import weakref
|
||||
from tiramisu.error import (RequirementError, PropertiesOptionError,
|
||||
ConstError, ConfigError)
|
||||
@ -104,6 +100,12 @@ rw_append = set(['frozen', 'disabled', 'validator', 'hidden'])
|
||||
rw_remove = set(['permissive', 'everything_frozen', 'mandatory'])
|
||||
|
||||
|
||||
log = getLogger('tiramisu')
|
||||
#FIXME
|
||||
#import logging
|
||||
#logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
class _NameSpace(object):
|
||||
"""convenient class that emulates a module
|
||||
@ -212,34 +214,12 @@ def populate_owners():
|
||||
setattr(owners, 'addowner', addowner)
|
||||
|
||||
|
||||
def populate_multitypes():
|
||||
"""all multi option should have a type, this type is automaticly set do
|
||||
not touch this
|
||||
|
||||
default
|
||||
default's multi option set if not master or slave
|
||||
|
||||
master
|
||||
master's option in a group with master's type, name of this option
|
||||
should be the same name of the optiondescription
|
||||
|
||||
slave
|
||||
slave's option in a group with master's type
|
||||
|
||||
"""
|
||||
setattr(multitypes, 'default', multitypes.DefaultMultiType('default'))
|
||||
setattr(multitypes, 'master', multitypes.MasterMultiType('master'))
|
||||
setattr(multitypes, 'slave', multitypes.SlaveMultiType('slave'))
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
# populate groups, owners and multitypes with default attributes
|
||||
# populate groups and owners with default attributes
|
||||
groups = GroupModule()
|
||||
populate_groups()
|
||||
owners = OwnerModule()
|
||||
populate_owners()
|
||||
multitypes = MultiTypeModule()
|
||||
populate_multitypes()
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
@ -370,7 +350,10 @@ class Settings(object):
|
||||
self._p_.reset_properties(_path)
|
||||
self._getcontext().cfgimpl_reset_cache()
|
||||
|
||||
def _getproperties(self, opt=None, path=None, is_apply_req=True):
|
||||
def _getproperties(self, opt=None, path=None, _is_apply_req=True):
|
||||
"""
|
||||
be careful, _is_apply_req doesn't copy properties
|
||||
"""
|
||||
if opt is None:
|
||||
props = copy(self._p_.getproperties(path, default_properties))
|
||||
else:
|
||||
@ -384,15 +367,16 @@ class Settings(object):
|
||||
is_cached, props = self._p_.getcache(path, ntime)
|
||||
if is_cached:
|
||||
return copy(props)
|
||||
props = copy(self._p_.getproperties(path, opt._properties))
|
||||
if is_apply_req:
|
||||
props = self._p_.getproperties(path, opt._properties)
|
||||
if _is_apply_req:
|
||||
props = copy(props)
|
||||
props |= self.apply_requires(opt, path)
|
||||
if 'cache' in self:
|
||||
if 'expire' in self:
|
||||
if ntime is None:
|
||||
ntime = int(time())
|
||||
ntime = ntime + expires_time
|
||||
self._p_.setcache(path, props, ntime)
|
||||
if 'cache' in self:
|
||||
if 'expire' in self:
|
||||
if ntime is None:
|
||||
ntime = int(time())
|
||||
ntime = ntime + expires_time
|
||||
self._p_.setcache(path, copy(props), ntime)
|
||||
return props
|
||||
|
||||
def append(self, propname):
|
||||
@ -408,6 +392,10 @@ class Settings(object):
|
||||
props.remove(propname)
|
||||
self._setproperties(props, None, None)
|
||||
|
||||
def extend(self, propnames):
|
||||
for propname in propnames:
|
||||
self.append(propname)
|
||||
|
||||
def _setproperties(self, properties, opt, path):
|
||||
"""save properties for specified opt
|
||||
(never save properties if same has option properties)
|
||||
@ -605,7 +593,7 @@ class Settings(object):
|
||||
" '{0}' with requirement on: "
|
||||
"'{1}'").format(path, reqpath))
|
||||
try:
|
||||
value = context._getattr(reqpath, force_permissive=True)
|
||||
value = context.getattr(reqpath, force_permissive=True)
|
||||
except PropertiesOptionError as err:
|
||||
if not transitive:
|
||||
continue
|
||||
@ -642,6 +630,15 @@ class Settings(object):
|
||||
def get_modified_permissives(self):
|
||||
return self._p_.get_modified_permissives()
|
||||
|
||||
def get_with_property(self, propname):
|
||||
opts, paths = self._getcontext().cfgimpl_get_description(
|
||||
)._cache_paths
|
||||
for index in range(0, len(paths)):
|
||||
opt = opts[index]
|
||||
path = paths[index]
|
||||
if propname in self._getproperties(opt, path, False):
|
||||
yield (opt, path)
|
||||
|
||||
def __getstate__(self):
|
||||
return {'_p_': self._p_, '_owner': str(self._owner)}
|
||||
|
||||
|
Reference in New Issue
Block a user