* config herite from BaseInformation class
[tiramisu.git] / tiramisu / config.py
index c98daa9..a8608ff 100644 (file)
 # ____________________________________________________________
 #from inspect import getmembers, ismethod
 from tiramisu.error import PropertiesOptionError, ConfigError
-from tiramisu.option import OptionDescription, Option, SymLinkOption
+from tiramisu.option import OptionDescription, Option, SymLinkOption, \
+    BaseInformation
 from tiramisu.setting import groups, Setting
 from tiramisu.value import Values
 from tiramisu.i18n import _
 
 
-class SubConfig(object):
+class SubConfig(BaseInformation):
     "sub configuration management entry"
-    __slots__ = ('_cfgimpl_context', '_cfgimpl_descr')
+    __slots__ = ('_impl_context', '_impl_descr')
 
     def __init__(self, descr, context):
         """ Configuration option management master class
@@ -44,11 +45,11 @@ class SubConfig(object):
         if not isinstance(descr, OptionDescription):
             raise ValueError(_('descr must be an optiondescription, not {0}'
                                '').format(type(descr)))
-        self._cfgimpl_descr = descr
+        self._impl_descr = descr
         # sub option descriptions
         if not isinstance(context, SubConfig):
             raise ValueError('context must be a SubConfig')
-        self._cfgimpl_context = context
+        self._impl_context = context
 
     def cfgimpl_reset_cache(self, only_expired=False, only=('values',
                                                             'settings')):
@@ -68,14 +69,14 @@ class SubConfig(object):
         return self, path[-1]
 
     def __hash__(self):
-        return hash(self.cfgimpl_get_description().optimpl_getkey(self))
+        return hash(self.cfgimpl_get_description().impl_getkey(self))
 
     def __eq__(self, other):
         "Config comparison"
         if not isinstance(other, Config):
             return False
-        return self.cfgimpl_get_description().optimpl_getkey(self) == \
-            other.cfgimpl_get_description().optimpl_getkey(other)
+        return self.cfgimpl_get_description().impl_getkey(self) == \
+            other.cfgimpl_get_description().impl_getkey(other)
 
     def __ne__(self, other):
         "Config comparison"
@@ -87,7 +88,7 @@ class SubConfig(object):
     def __iter__(self):
         """Pythonesque way of parsing group's ordered options.
         iteration only on Options (not OptionDescriptions)"""
-        for child in self.cfgimpl_get_description().optimpl_getchildren():
+        for child in self.cfgimpl_get_description().impl_getchildren():
             if not isinstance(child, OptionDescription):
                 try:
                     yield child._name, getattr(self, child._name)
@@ -99,7 +100,7 @@ class SubConfig(object):
     def iter_all(self):
         """A way of parsing options **and** groups.
         iteration on Options and OptionDescriptions."""
-        for child in self.cfgimpl_get_description().optimpl_getchildren():
+        for child in self.cfgimpl_get_description().impl_getchildren():
             try:
                 yield child._name, getattr(self, child._name)
             except GeneratorExit:
@@ -120,11 +121,11 @@ class SubConfig(object):
         if group_type is not None:
             if not isinstance(group_type, groups.GroupType):
                 raise TypeError(_("unknown group_type: {0}").format(group_type))
-        for child in self.cfgimpl_get_description().optimpl_getchildren():
+        for child in self.cfgimpl_get_description().impl_getchildren():
             if isinstance(child, OptionDescription):
                 try:
                     if group_type is None or (group_type is not None and
-                                              child.optimpl_get_group_type()
+                                              child.impl_get_group_type()
                                               == group_type):
                         yield child._name, getattr(self, child._name)
                 except GeneratorExit:
@@ -148,25 +149,25 @@ class SubConfig(object):
     __repr__ = __str__
 
     def cfgimpl_get_context(self):
-        return self._cfgimpl_context
+        return self._impl_context
 
     def cfgimpl_get_description(self):
-        if self._cfgimpl_descr is None:
+        if self._impl_descr is None:
             raise ConfigError(_('no optiondescription for this config (may be MetaConfig without meta)'))
         else:
-            return self._cfgimpl_descr
+            return self._impl_descr
 
     def cfgimpl_get_settings(self):
-        return self.cfgimpl_get_context()._cfgimpl_settings
+        return self.cfgimpl_get_context()._impl_settings
 
     def cfgimpl_get_values(self):
-        return self.cfgimpl_get_context()._cfgimpl_values
+        return self.cfgimpl_get_context()._impl_values
 
     # ____________________________________________________________
     # attribute methods
     def __setattr__(self, name, value):
         "attribute notation mechanism for the setting of the value of an option"
-        if name.startswith('_cfgimpl_'):
+        if name.startswith('_impl_'):
             #self.__dict__[name] = value
             object.__setattr__(self, name, value)
             return
@@ -182,7 +183,7 @@ class SubConfig(object):
                                               force_permissive=force_permissive)
         else:
             context = self.cfgimpl_get_context()
-            path = context.cfgimpl_get_description().optimpl_get_path_by_opt(child._opt)
+            path = context.cfgimpl_get_description().impl_get_path_by_opt(child._opt)
             context._setattr(path, value, force_permissive=force_permissive)
 
     def __delattr__(self, name):
@@ -210,14 +211,15 @@ class SubConfig(object):
                                        force_properties=force_properties,
                                        validate=validate)
         # special attributes
-        if name.startswith('_cfgimpl_') or name.startswith('cfgimpl_'):
+        if name.startswith('_impl_') or name.startswith('cfgimpl_') \
+                or name.startswith('impl_'):
             # if it were in __dict__ it would have been found already
             return object.__getattribute__(self, name)
         opt_or_descr = getattr(self.cfgimpl_get_description(), name)
         # symlink options
         if isinstance(opt_or_descr, SymLinkOption):
             context = self.cfgimpl_get_context()
-            path = context.cfgimpl_get_description().optimpl_get_path_by_opt(opt_or_descr._opt)
+            path = context.cfgimpl_get_description().impl_get_path_by_opt(opt_or_descr._opt)
             return context._getattr(path, validate=validate,
                                     force_properties=force_properties,
                                     force_permissive=force_permissive)
@@ -371,7 +373,7 @@ class SubConfig(object):
                                                          type_='path',
                                                          _subpath=mypath):
                 path = '.'.join(path.split('.')[:-1])
-                opt = self.cfgimpl_get_context().cfgimpl_get_description().optimpl_get_opt_by_path(path)
+                opt = self.cfgimpl_get_context().cfgimpl_get_description().impl_get_opt_by_path(path)
                 if mypath is not None:
                     if mypath == path:
                         withoption = None
@@ -387,7 +389,7 @@ class SubConfig(object):
                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
         #withoption can be set to None below !
         if withoption is None:
-            for opt in self.cfgimpl_get_description().optimpl_getchildren():
+            for opt in self.cfgimpl_get_description().impl_getchildren():
                 path = opt._name
                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
         if _currpath == []:
@@ -416,14 +418,14 @@ class SubConfig(object):
     def cfgimpl_get_path(self):
         descr = self.cfgimpl_get_description()
         context_descr = self.cfgimpl_get_context().cfgimpl_get_description()
-        return context_descr.optimpl_get_path_by_opt(descr)
+        return context_descr.impl_get_path_by_opt(descr)
 
 
 class ConfigCommon(SubConfig):
-    __slots__ = ('_cfgimpl_values', '_cfgimpl_settings', '_cfgimpl_meta')
+    __slots__ = ('_impl_values', '_impl_settings', '_impl_meta')
 
-    def _cfgimpl_build_all_paths(self):
-        self.cfgimpl_get_description().optimpl_build_cache()
+    def _impl_build_all_paths(self):
+        self.cfgimpl_get_description().impl_build_cache()
 
     def read_only(self):
         self.cfgimpl_get_settings().read_only()
@@ -432,7 +434,7 @@ class ConfigCommon(SubConfig):
         self.cfgimpl_get_settings().read_write()
 
     def getowner(self, path):
-        opt = self.cfgimpl_get_description().optimpl_get_opt_by_path(path)
+        opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
         return self.cfgimpl_get_values().getowner(opt)
 
     def unwrap_from_path(self, path):
@@ -451,7 +453,7 @@ class ConfigCommon(SubConfig):
         return None
 
     def cfgimpl_get_meta(self):
-        return self._cfgimpl_meta
+        return self._impl_meta
 
 
 # ____________________________________________________________
@@ -467,11 +469,12 @@ class Config(ConfigCommon):
         :param context: the current root config
         :type context: `Config`
         """
-        self._cfgimpl_settings = Setting(self)
-        self._cfgimpl_values = Values(self)
-        super(Config, self).__init__(descr, self)  # , slots)
-        self._cfgimpl_build_all_paths()
-        self._cfgimpl_meta = None
+        self._impl_settings = Setting(self)
+        self._impl_values = Values(self)
+        super(Config, self).__init__(descr, self)
+        self._impl_build_all_paths()
+        self._impl_meta = None
+        self._impl_informations = {}
 
     def cfgimpl_reset_cache(self, only_expired=False, only=('values', 'settings')):
         if 'values' in only:
@@ -481,30 +484,30 @@ class Config(ConfigCommon):
 
 
 class MetaConfig(ConfigCommon):
-    __slots__ = ('_cfgimpl_children',)
+    __slots__ = ('_impl_children',)
 
     def __init__(self, children, meta=True):
         if not isinstance(children, list):
             raise ValueError(_("metaconfig's children must be a list"))
-        self._cfgimpl_descr = None
+        self._impl_descr = None
         if meta:
             for child in children:
                 if not isinstance(child, ConfigCommon):
                     raise ValueError(_("metaconfig's children must be Config, not {0}"
                                        "".format(type(child))))
-                if self._cfgimpl_descr is None:
-                    self._cfgimpl_descr = child.cfgimpl_get_description()
-                elif not self._cfgimpl_descr is child.cfgimpl_get_description():
+                if self._impl_descr is None:
+                    self._impl_descr = child.cfgimpl_get_description()
+                elif not self._impl_descr is child.cfgimpl_get_description():
                     raise ValueError(_('all config in MetaConfig must have same '
                                        'optiondescription'))
                 if child.cfgimpl_get_meta() is not None:
                     raise ValueError(_("child has already a metaconfig's"))
-                child._cfgimpl_meta = self
+                child._impl_meta = self
 
-        self._cfgimpl_children = children
-        self._cfgimpl_settings = Setting(self)
-        self._cfgimpl_values = Values(self)
-        self._cfgimpl_meta = None
+        self._impl_children = children
+        self._impl_settings = Setting(self)
+        self._impl_values = Values(self)
+        self._impl_meta = None
 
     def cfgimpl_get_context(self):
         return self
@@ -514,11 +517,11 @@ class MetaConfig(ConfigCommon):
             self.cfgimpl_get_values().reset_cache(only_expired=only_expired)
         if 'settings' in only:
             self.cfgimpl_get_settings().reset_cache(only_expired=only_expired)
-        for child in self._cfgimpl_children:
+        for child in self._impl_children:
             child.cfgimpl_reset_cache(only_expired=only_expired, only=only)
 
     def set_contexts(self, path, value):
-        for child in self._cfgimpl_children:
+        for child in self._impl_children:
             try:
                 if not isinstance(child, MetaConfig):
                     setattr(child, path, value)
@@ -537,7 +540,7 @@ class MetaConfig(ConfigCommon):
                                     check_properties=False)
         except ConfigError:
             pass
-        for child in self._cfgimpl_children:
+        for child in self._impl_children:
             try:
                 if not isinstance(child, MetaConfig):
                     if bypath is not None:
@@ -570,9 +573,9 @@ def mandatory_warnings(config):
     """
     #if value in cache, properties are not calculated
     config.cfgimpl_reset_cache(only=('values',))
-    for path in config.cfgimpl_get_description().optimpl_getpaths(include_groups=True):
+    for path in config.cfgimpl_get_description().impl_getpaths(include_groups=True):
         try:
-            config._getattr(path, force_properties=('mandatory',))
+            config._getattr(path, force_properties=frozenset(('mandatory',)))
         except PropertiesOptionError, err:
             if err.proptype == ['mandatory']:
                 yield path