review exception
[tiramisu.git] / tiramisu / config.py
index 93cfe34..d4bb430 100644 (file)
@@ -21,8 +21,8 @@
 # the whole pypy projet is under MIT licence
 # ____________________________________________________________
 #from inspect import getmembers, ismethod
-from tiramisu.error import (PropertiesOptionError, NotFoundError,
-                            AmbigousOptionError, NoMatchingOptionFound, MandatoryError)
+from tiramisu.error import (PropertiesOptionError, ConfigError,
+                            AmbigousOptionError, MandatoryError)
 from tiramisu.option import OptionDescription, Option, SymLinkOption
 from tiramisu.setting import groups, Setting, apply_requires
 from tiramisu.value import Values
@@ -86,7 +86,7 @@ class SubConfig(object):
         "validation for the setattr and the getattr"
         if not isinstance(opt_or_descr, Option) and \
                 not isinstance(opt_or_descr, OptionDescription):
-            raise TypeError(_('Unexpected object: {0}').format(repr(opt_or_descr)))
+            raise TypeError(_('unexpected object: {0}').format(repr(opt_or_descr)))
         properties = set(self.cfgimpl_get_settings().get_properties(opt_or_descr))
         #remove this properties, those properties are validate in value/setting
         properties = properties - set(['mandatory', 'frozen'])
@@ -154,16 +154,16 @@ class SubConfig(object):
         apply_requires(child, self)
         #needed to ?
         if child not in self._cfgimpl_descr._children[1]:
-            raise AttributeError(_('unknown option {}').format(name))
+            raise AttributeError(_('unknown option {0}').format(name))
 
         if setting.has_property('everything_frozen'):
-            raise TypeError(_("cannot set a value to the option {} if the whole "
-                            "config has been frozen").format(name))
+            raise ConfigError(_("cannot set a value to the option {0} if the whole "
+                              "config has been frozen").format(name))
 
         if setting.has_property('frozen') and setting.has_property('frozen',
                                                                    child, is_apply_req=False):
-            raise TypeError(_('cannot change the value to {} for '
-                            'option {} this option is frozen').format(str(value), name))
+            raise ConfigError(_('cannot change the value to {0} for '
+                              'option {1} this option is frozen').format(str(value), name))
         self.cfgimpl_get_values()[child] = value
 
     def cfgimpl_get_home_by_path(self, path, force_permissive=False, force_properties=None):
@@ -227,7 +227,7 @@ 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))
+                raise TypeError(_("unknown group_type: {0}").format(group_type))
         for child in self._cfgimpl_descr._children[1]:
             if isinstance(child, OptionDescription):
                 try:
@@ -340,8 +340,8 @@ class SubConfig(object):
                     else:
                         tmypath = mypath + '.'
                         if not path.startswith(tmypath):
-                            raise Exception(_('unexpected path {}, '
-                                            'should start with {}').format(path, mypath))
+                            raise AttributeError(_('unexpected path {0}, '
+                                                 'should start with {1}').format(path, mypath))
                         path = path[len(tmypath):]
                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
         #withoption can be set to None below !
@@ -424,6 +424,7 @@ class Config(SubConfig):
                 except MandatoryError:
                     pass
                 except Exception, e:
+                    #FIXME hu? should have Exception ?
                     raise e  # HiddenOptionError or DisabledOptionError
                 child = getattr(homeconfig._cfgimpl_descr, name)
                 homeconfig.setoption(name, child, value)
@@ -431,7 +432,7 @@ class Config(SubConfig):
                 raise AmbigousOptionError(
                     _('more than one option that ends with {}').format(key))
             else:
-                raise NoMatchingOptionFound(
+                raise AttributeError(
                     _('there is no option that matches {}'
                       ' or the option is hidden or disabled').format(key))
 
@@ -484,7 +485,7 @@ class Config(SubConfig):
         #                return False
         #    return False
         if type_ not in ('option', 'path', 'value'):
-            raise ValueError(_('unknown type_ type {} for _find').format(type_))
+            raise ValueError(_('unknown type_ type {0} for _find').format(type_))
         find_results = []
         opts, paths = self.cfgimpl_get_description()._cache_paths
         for index in range(0, len(paths)):
@@ -518,7 +519,7 @@ class Config(SubConfig):
             else:
                 find_results.append(retval)
         if find_results == []:
-            raise NotFoundError(_("no option found in config with these criteria"))
+            raise AttributeError(_("no option found in config with these criteria"))
         else:
             return find_results