Le cache des paths est dans l'OptionDescription
Utilisation des slots pour la Config Il faut 566Mo de mémoire pour charger 50 variantes de 100 serveurs chacuns (5000 serveurs en tout). ref #5111
This commit is contained in:
parent
899f864f8d
commit
d00153787d
|
@ -16,7 +16,7 @@
|
|||
# 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 original `Config` design model is unproudly borrowed from
|
||||
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
|
||||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
|
@ -41,7 +41,7 @@ class CommonType(object):
|
|||
# def show(self):
|
||||
# self.del_property('hidden')
|
||||
# def _is_hidden(self):
|
||||
# # dangerous method: how an Option() can determine its status by itself ?
|
||||
# # dangerous method: how an Option() can determine its status by itself ?
|
||||
# return self.has_property('hidden')
|
||||
|
||||
#class DisabledBaseType(BaseType):
|
||||
|
@ -52,13 +52,13 @@ class CommonType(object):
|
|||
# def _is_disabled(self):
|
||||
# return self.has_property('disabled')
|
||||
|
||||
# commonly used properties. Option and OptionDescription will have these methods
|
||||
common_properties = {'hidden': ('hide', 'show', '_is_hidden'),
|
||||
# commonly used properties. Option and OptionDescription will have these methods
|
||||
common_properties = {'hidden': ('hide', 'show', '_is_hidden'),
|
||||
'disabled': ('disable', 'enable', '_is_disabled')
|
||||
}
|
||||
|
||||
basetype_methods = dict()
|
||||
|
||||
|
||||
def build_properties(prop, add_prop, del_prop, is_prop):
|
||||
def add_property(self):
|
||||
self.add_property(prop)
|
||||
|
@ -66,11 +66,11 @@ def build_properties(prop, add_prop, del_prop, is_prop):
|
|||
self.del_property(prop)
|
||||
def is_property(self):
|
||||
return self.has_property(prop)
|
||||
return {add_prop:add_property, del_prop:del_property,
|
||||
return {add_prop:add_property, del_prop:del_property,
|
||||
is_prop:is_property}
|
||||
|
||||
for propname, meth_names in common_properties.items():
|
||||
basetype_methods.update(build_properties(propname, meth_names[0], meth_names[1],
|
||||
basetype_methods.update(build_properties(propname, meth_names[0], meth_names[1],
|
||||
meth_names[2]))
|
||||
|
||||
BaseType = type('BaseType', (CommonType,), basetype_methods)
|
||||
|
|
|
@ -33,11 +33,10 @@ from tiramisu.value import Values
|
|||
# ____________________________________________________________
|
||||
class Config(object):
|
||||
"main configuration management entry"
|
||||
# __slots__ = ('__dict__', '_cfgimpl_toplevel', '_cfgimpl_descr', '_cfgimpl_subconfigs',
|
||||
# '_cfgimpl_parent', '_cfgimpl_all_paths', '_cfgimpl_warnings',
|
||||
# '_cfgimpl_toplevel', '_cfgimpl_slots', '_cfgimpl_build_all_paths')
|
||||
_cfgimpl_toplevel = None
|
||||
|
||||
__slots__ = ('_cfgimpl_descr', '_cfgimpl_subconfigs',
|
||||
'_cfgimpl_parent', '_cfgimpl_warnings', '_cfgimpl_permissive',
|
||||
'_cfgimpl_context', '_cfgimpl_settings', '_cfgimpl_values',
|
||||
'_cfgimpl_slots', '_cfgimpl_build_all_paths')
|
||||
def __init__(self, descr, parent=None, context=None, valid_opt_names=True):
|
||||
""" Configuration option management master class
|
||||
|
||||
|
@ -62,14 +61,13 @@ class Config(object):
|
|||
self._cfgimpl_settings = Setting()
|
||||
self._cfgimpl_settings.valid_opt_names = valid_opt_names
|
||||
self._cfgimpl_values = Values(self._cfgimpl_context)
|
||||
self._cfgimpl_all_paths = {}
|
||||
#self._cfgimpl_all_paths = {}
|
||||
else:
|
||||
if context is None:
|
||||
raise ConfigError("cannot find a value for this config")
|
||||
valid_opt_names = context._cfgimpl_settings.valid_opt_names
|
||||
"warnings are a great idea, let's make up a better use of it"
|
||||
self._cfgimpl_warnings = []
|
||||
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
|
||||
if valid_opt_names:
|
||||
# some api members shall not be used as option's names !
|
||||
#methods = getmembers(self, ismethod)
|
||||
|
@ -82,9 +80,9 @@ class Config(object):
|
|||
self._cfgimpl_build_all_paths()
|
||||
|
||||
def _cfgimpl_build_all_paths(self):
|
||||
if self._cfgimpl_all_paths == None:
|
||||
raise ConfigError('cache paths must not be None')
|
||||
self._cfgimpl_descr.build_cache(self._cfgimpl_all_paths)
|
||||
# if self._cfgimpl_all_paths == None:
|
||||
# raise ConfigError('cache paths must not be None')
|
||||
self._cfgimpl_descr.build_cache() #self._cfgimpl_all_paths)
|
||||
|
||||
def cfgimpl_get_settings(self):
|
||||
return self._cfgimpl_context._cfgimpl_settings
|
||||
|
@ -156,7 +154,8 @@ class Config(object):
|
|||
def __setattr__(self, name, value):
|
||||
"attribute notation mechanism for the setting of the value of an option"
|
||||
if name.startswith('_cfgimpl_'):
|
||||
self.__dict__[name] = value
|
||||
#self.__dict__[name] = value
|
||||
object.__setattr__(self, name, value)
|
||||
return
|
||||
if '.' in name:
|
||||
homeconfig, name = self.cfgimpl_get_home_by_path(name)
|
||||
|
|
|
@ -424,6 +424,7 @@ class OptionDescription(BaseType, BaseInformation):
|
|||
self._build()
|
||||
self.properties = [] # 'hidden', 'disabled'...
|
||||
self.informations = {}
|
||||
self._cache_paths = {}
|
||||
|
||||
def getdoc(self):
|
||||
return self.doc
|
||||
|
@ -474,7 +475,9 @@ class OptionDescription(BaseType, BaseInformation):
|
|||
paths.append('.'.join(currpath + [attr]))
|
||||
return paths
|
||||
|
||||
def build_cache(self, paths, currpath=None):
|
||||
def build_cache(self, currpath=None):
|
||||
if currpath is None and self._cache_paths != {}:
|
||||
return
|
||||
if currpath is None:
|
||||
currpath = []
|
||||
for option in self._children:
|
||||
|
@ -483,10 +486,10 @@ class OptionDescription(BaseType, BaseInformation):
|
|||
continue
|
||||
if isinstance(option, OptionDescription):
|
||||
currpath.append(attr)
|
||||
option.build_cache(paths, currpath=currpath)
|
||||
option.build_cache(currpath=currpath)
|
||||
currpath.pop()
|
||||
else:
|
||||
paths[option] = str('.'.join(currpath + [attr]))
|
||||
self._cache_paths[option] = str('.'.join(currpath + [attr]))
|
||||
|
||||
# ____________________________________________________________
|
||||
def set_group_type(self, group_type):
|
||||
|
|
Loading…
Reference in New Issue