diff --git a/tiramisu/config.py b/tiramisu/config.py index 58e9067..ff6595d 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -57,11 +57,13 @@ class Config(object): if parent is None: self._cfgimpl_settings = Setting() self._cfgimpl_values = Values(self._cfgimpl_context) + self._cfgimpl_all_paths = {} else: if context is None: raise ConfigError("cannot find a value for this config") self._cfgimpl_settings = None self._cfgimpl_values = None + self._cfgimpl_all_paths = None "warnings are a great idea, let's make up a better use of it" self._cfgimpl_warnings = [] self._cfgimpl_toplevel = self._cfgimpl_get_toplevel() @@ -70,6 +72,13 @@ class Config(object): self._cfgimpl_slots = [key for key, value in methods if not key.startswith("_")] self._cfgimpl_build() + if parent is None: + 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) def cfgimpl_get_settings(self): return self._cfgimpl_context._cfgimpl_settings @@ -326,7 +335,16 @@ class Config(object): subpath.insert(0, obj._cfgimpl_descr._name) obj = obj._cfgimpl_parent return ".".join(subpath) + # ______________________________________________________________________ +# def cfgimpl_previous_value(self, path): +# "stores the previous value" +# home, name = self._cfgimpl_get_home_by_path(path) +# # FIXME fucking name +# return home._cfgimpl_context._cfgimpl_values.previous_values[name] +# def get_previous_value(self, name): +# "for the time being, only the previous Option's value is accessible" +# return self._cfgimpl_context._cfgimpl_values.previous_values[name] # ______________________________________________________________________ def add_warning(self, warning): "Config implements its own warning pile. Could be useful" @@ -413,17 +431,19 @@ class Config(object): """ paths = [] for path in self._cfgimpl_descr.getpaths(include_groups=include_groups): - try: - value = getattr(self, path) - - except MandatoryError: - if mandatory or allpaths: - paths.append(path) - except PropertiesOptionError: - if allpaths: - paths.append(path) # option which have properties added - else: + if allpaths: paths.append(path) + else: + try: + value = getattr(self, path) + + except MandatoryError: + if mandatory: + paths.append(path) + except PropertiesOptionError: + pass + else: + paths.append(path) return paths def _find(self, bytype, byname, byvalue, byattrs, first): diff --git a/tiramisu/option.py b/tiramisu/option.py index d43d7f8..02dd613 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -444,6 +444,21 @@ class OptionDescription(BaseType): else: paths.append('.'.join(currpath + [attr])) return paths + + def build_cache(self, paths, currpath=None): + if currpath is None: + currpath = [] + for option in self._children: + attr = option._name + if attr.startswith('_cfgimpl'): + continue + if isinstance(option, OptionDescription): + currpath.append(attr) + option.build_cache(paths, currpath=currpath) + currpath.pop() + else: + paths[option] = '.'.join(currpath + [attr]) + # ____________________________________________________________ def set_group_type(self, group_type): """sets a given group object to an OptionDescription diff --git a/tiramisu/value.py b/tiramisu/value.py index cd256fc..db3b8f8 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -55,9 +55,18 @@ class Values(object): if opt not in self.values: if opt.is_multi(): multitype = self._get_multitype(opt) - return Multi(opt.getdefault(), self.context, opt, multitype) + value = Multi(opt.getdefault(), self.context, opt, multitype) else: - return opt.getdefault() + value = opt.getdefault() + + if opt in self.slaves: + masterpath = self.context._cfgimpl_all_paths[self.slaves[opt]] + mastervalue = getattr(self.context, masterpath) + masterlen = len(mastervalue) + if len(value) < masterlen: + for num in range(0, masterlen - len(value)): + value.append(None, force=True) + return value return self.values[opt] def reset(self, opt):