Merge branch 'master' into orm
[tiramisu.git] / tiramisu / config.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012-2013 Team tiramisu (see AUTHORS for all contributors)
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 #
18 # The original `Config` design model is unproudly borrowed from
19 # the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
20 # the whole pypy projet is under MIT licence
21 # ____________________________________________________________
22 "options handler global entry point"
23 import weakref
24 from tiramisu.error import PropertiesOptionError, ConfigError
25 from tiramisu.option import OptionDescription, Option, SymLinkOption
26 from tiramisu.setting import groups, Settings, default_encoding
27 from tiramisu.storage import get_storages, get_storage, set_storage, \
28     _impl_getstate_setting
29 from tiramisu.value import Values, Multi
30 from tiramisu.i18n import _
31
32
33 class SubConfig(object):
34     """Sub configuration management entry.
35     Tree if OptionDescription's responsability. SubConfig are generated
36     on-demand. A Config is also a SubConfig.
37     Root Config is call context below
38     """
39     __slots__ = ('_impl_context', '_impl_descr', '_impl_path')
40
41     def __init__(self, descr, context, subpath=None):
42         """ Configuration option management master class
43
44         :param descr: describes the configuration schema
45         :type descr: an instance of ``option.OptionDescription``
46         :param context: the current root config
47         :type context: `Config`
48         :type subpath: `str` with the path name
49         """
50         # main option description
51         if not isinstance(descr, OptionDescription):
52             raise TypeError(_('descr must be an optiondescription, not {0}'
53                               ).format(type(descr)))
54         self._impl_descr = descr
55         # sub option descriptions
56         if not isinstance(context, weakref.ReferenceType):
57             raise ValueError('context must be a Weakref')
58         self._impl_context = context
59         self._impl_path = subpath
60
61     def cfgimpl_reset_cache(self, only_expired=False, only=('values',
62                                                             'settings')):
63         "remove cache (in context)"
64         self._cfgimpl_get_context().cfgimpl_reset_cache(only_expired, only)
65
66     def cfgimpl_get_home_by_path(self, path, force_permissive=False,
67                                  force_properties=None):
68         """:returns: tuple (config, name)"""
69         path = path.split('.')
70         for step in path[:-1]:
71             self = self._getattr(step,
72                                  force_permissive=force_permissive,
73                                  force_properties=force_properties)
74         return self, path[-1]
75
76     #def __hash__(self):
77     #FIXME
78     #    return hash(self.cfgimpl_get_description().impl_getkey(self))
79
80     #def __eq__(self, other):
81     #FIXME
82     #    "Config's comparison"
83     #    if not isinstance(other, Config):
84     #        return False
85     #    return self.cfgimpl_get_description().impl_getkey(self) == \
86     #        other.cfgimpl_get_description().impl_getkey(other)
87
88     #def __ne__(self, other):
89     #FIXME
90     #    "Config's comparison"
91     #    if not isinstance(other, Config):
92     #        return True
93     #    return not self == other
94
95     # ______________________________________________________________________
96     def __iter__(self):
97         """Pythonesque way of parsing group's ordered options.
98         iteration only on Options (not OptionDescriptions)"""
99         for child in self.cfgimpl_get_description().impl_getchildren():
100             if not isinstance(child, OptionDescription):
101                 try:
102                     yield child.impl_getname(), getattr(self, child.impl_getname())
103                 except GeneratorExit:
104                     raise StopIteration
105                 except PropertiesOptionError:
106                     pass  # option with properties
107
108     def iter_all(self):
109         """A way of parsing options **and** groups.
110         iteration on Options and OptionDescriptions."""
111         for child in self.cfgimpl_get_description().impl_getchildren():
112             try:
113                 yield child.impl_getname(), getattr(self, child.impl_getname())
114             except GeneratorExit:
115                 raise StopIteration
116             except PropertiesOptionError:
117                 pass  # option with properties
118
119     def iter_groups(self, group_type=None):
120         """iteration on groups objects only.
121         All groups are returned if `group_type` is `None`, otherwise the groups
122         can be filtered by categories (families, or whatever).
123
124         :param group_type: if defined, is an instance of `groups.GroupType`
125                            or `groups.MasterGroupType` that lives in
126                            `setting.groups`
127         """
128         if group_type is not None and not isinstance(group_type,
129                                                      groups.GroupType):
130             raise TypeError(_("unknown group_type: {0}").format(group_type))
131         for child in self.cfgimpl_get_description().impl_getchildren():
132             if isinstance(child, OptionDescription):
133                 try:
134                     if group_type is None or (group_type is not None and
135                                               child.impl_get_group_type()
136                                               == group_type):
137                         yield child.impl_getname(), getattr(self, child.impl_getname())
138                 except GeneratorExit:
139                     raise StopIteration
140                 except PropertiesOptionError:
141                     pass
142     # ______________________________________________________________________
143
144     def __str__(self):
145         "Config's string representation"
146         lines = []
147         for name, grp in self.iter_groups():
148             lines.append("[{0}]".format(name))
149         for name, value in self:
150             try:
151                 lines.append("{0} = {1}".format(name, value))
152             except UnicodeEncodeError:
153                 lines.append("{0} = {1}".format(name,
154                                                 value.encode(default_encoding)))
155             except PropertiesOptionError:
156                 pass
157         return '\n'.join(lines)
158
159     __repr__ = __str__
160
161     def _cfgimpl_get_context(self):
162         return self._impl_context()
163
164     def cfgimpl_get_description(self):
165         if self._impl_descr is None:
166             raise ConfigError(_('no option description found for this config'
167                                 ' (may be metaconfig without meta)'))
168         else:
169             return self._impl_descr
170
171     def cfgimpl_get_settings(self):
172         return self._cfgimpl_get_context()._impl_settings
173
174     def cfgimpl_get_values(self):
175         return self._cfgimpl_get_context()._impl_values
176
177     # ____________________________________________________________
178     # attribute methods
179     def __setattr__(self, name, value):
180         "attribute notation mechanism for the setting of the value of an option"
181         if name.startswith('_impl_'):
182             object.__setattr__(self, name, value)
183             return
184         self._setattr(name, value)
185
186     def _setattr(self, name, value, force_permissive=False):
187         if '.' in name:
188             homeconfig, name = self.cfgimpl_get_home_by_path(name)
189             return homeconfig.__setattr__(name, value)
190         child = getattr(self.cfgimpl_get_description(), name)
191         if isinstance(child, OptionDescription):
192             raise TypeError(_("can't assign to an OptionDescription"))
193         elif not isinstance(child, SymLinkOption):
194             if self._impl_path is None:
195                 path = name
196             else:
197                 path = self._impl_path + '.' + name
198             self.cfgimpl_get_values().setitem(child, value, path,
199                                               force_permissive=force_permissive)
200         else:
201             context = self._cfgimpl_get_context()
202             path = context.cfgimpl_get_description().impl_get_path_by_opt(
203                 child._opt)
204             context._setattr(path, value, force_permissive=force_permissive)
205
206     def __delattr__(self, name):
207         child = getattr(self.cfgimpl_get_description(), name)
208         self.cfgimpl_get_values().__delitem__(child)
209
210     def __getattr__(self, name):
211         return self._getattr(name)
212
213     def _getattr(self, name, force_permissive=False, force_properties=None,
214                  validate=True):
215         """
216         attribute notation mechanism for accessing the value of an option
217         :param name: attribute name
218         :return: option's value if name is an option name, OptionDescription
219                  otherwise
220         """
221         # attribute access by passing a path,
222         # for instance getattr(self, "creole.general.family.adresse_ip_eth0")
223         if '.' in name:
224             homeconfig, name = self.cfgimpl_get_home_by_path(
225                 name, force_permissive=force_permissive,
226                 force_properties=force_properties)
227             return homeconfig._getattr(name, force_permissive=force_permissive,
228                                        force_properties=force_properties,
229                                        validate=validate)
230         opt_or_descr = getattr(self.cfgimpl_get_description(), name)
231         if self._impl_path is None:
232             subpath = name
233         else:
234             subpath = self._impl_path + '.' + name
235         # symlink options
236         if isinstance(opt_or_descr, SymLinkOption):
237             context = self._cfgimpl_get_context()
238             path = context.cfgimpl_get_description().impl_get_path_by_opt(
239                 opt_or_descr._opt)
240             return context._getattr(path, validate=validate,
241                                     force_properties=force_properties,
242                                     force_permissive=force_permissive)
243         elif isinstance(opt_or_descr, OptionDescription):
244             self.cfgimpl_get_settings().validate_properties(
245                 opt_or_descr, True, False, path=subpath,
246                 force_permissive=force_permissive,
247                 force_properties=force_properties)
248             return SubConfig(opt_or_descr, self._impl_context, subpath)
249         else:
250             return self.cfgimpl_get_values().getitem(
251                 opt_or_descr, path=subpath,
252                 validate=validate,
253                 force_properties=force_properties,
254                 force_permissive=force_permissive)
255
256     def find(self, bytype=None, byname=None, byvalue=None, type_='option',
257              check_properties=True):
258         """
259             finds a list of options recursively in the config
260
261             :param bytype: Option class (BoolOption, StrOption, ...)
262             :param byname: filter by Option.impl_getname()
263             :param byvalue: filter by the option's value
264             :returns: list of matching Option objects
265         """
266         return self._cfgimpl_get_context()._find(bytype, byname, byvalue,
267                                                  first=False,
268                                                  type_=type_,
269                                                  _subpath=self.cfgimpl_get_path(),
270                                                  check_properties=check_properties)
271
272     def find_first(self, bytype=None, byname=None, byvalue=None,
273                    type_='option', display_error=True, check_properties=True):
274         """
275             finds an option recursively in the config
276
277             :param bytype: Option class (BoolOption, StrOption, ...)
278             :param byname: filter by Option.impl_getname()
279             :param byvalue: filter by the option's value
280             :returns: list of matching Option objects
281         """
282         return self._cfgimpl_get_context()._find(
283             bytype, byname, byvalue, first=True, type_=type_,
284             _subpath=self.cfgimpl_get_path(), display_error=display_error,
285             check_properties=check_properties)
286
287     def _find(self, bytype, byname, byvalue, first, type_='option',
288               _subpath=None, check_properties=True, display_error=True):
289         """
290         convenience method for finding an option that lives only in the subtree
291
292         :param first: return only one option if True, a list otherwise
293         :return: find list or an exception if nothing has been found
294         """
295         def _filter_by_name():
296             try:
297                 if byname is None or path == byname or \
298                         path.endswith('.' + byname):
299                     return True
300             except IndexError:
301                 pass
302             return False
303
304         def _filter_by_value():
305             if byvalue is None:
306                 return True
307             try:
308                 value = getattr(self, path)
309                 if isinstance(value, Multi):
310                     return byvalue in value
311                 else:
312                     return value == byvalue
313             except PropertiesOptionError:  # a property is a restriction
314                                            # upon the access of the value
315                 return False
316
317         def _filter_by_type():
318             if bytype is None:
319                 return True
320             if isinstance(option, bytype):
321                 return True
322             return False
323
324         if type_ not in ('option', 'path', 'value'):
325             raise ValueError(_('unknown type_ type {0}'
326                                'for _find').format(type_))
327         find_results = []
328         paths = self.cfgimpl_get_description()._cache_paths[1]
329         for path in paths:
330             option = self.cfgimpl_get_description().impl_get_opt_by_path(path)
331             if isinstance(option, OptionDescription):
332                 continue
333             if _subpath is not None and not path.startswith(_subpath + '.'):
334                 continue
335             if not _filter_by_name():
336                 continue
337             if not _filter_by_value():
338                 continue
339             if not _filter_by_type():
340                 continue
341             #remove option with propertyerror, ...
342             if byvalue is None and check_properties:
343                 try:
344                     value = getattr(self, path)
345                 except PropertiesOptionError:
346                     # a property restricts the access of the value
347                     continue
348             if type_ == 'value':
349                 retval = value
350             elif type_ == 'path':
351                 retval = path
352             elif type_ == 'option':
353                 retval = option
354             if first:
355                 return retval
356             else:
357                 find_results.append(retval)
358         return self._find_return_results(find_results, display_error)
359
360     def _find_return_results(self, find_results, display_error):
361         if find_results == []:
362             if display_error:
363                 raise AttributeError(_("no option found in config"
364                                        " with these criteria"))
365             else:
366                 # translation is slow
367                 raise AttributeError()
368         else:
369             return find_results
370
371     def make_dict(self, flatten=False, _currpath=None, withoption=None,
372                   withvalue=None):
373         """exports the whole config into a `dict`, for example:
374
375         >>> print cfg.make_dict()
376         {'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
377
378
379
380         :param flatten: returns a dict(name=value) instead of a dict(path=value)
381                         ::
382
383                             >>> print cfg.make_dict(flatten=True)
384                             {'var5': None, 'var4': None, 'var6': None}
385
386         :param withoption: returns the options that are present in the very same
387                            `OptionDescription` than the `withoption` itself::
388
389                                 >>> print cfg.make_dict(withoption='var1')
390                                 {'od2.var4': None, 'od2.var5': None,
391                                 'od2.var6': None,
392                                 'od2.var1': u'value',
393                                 'od1.var1': None,
394                                 'od1.var3': None,
395                                 'od1.var2': None}
396
397         :param withvalue: returns the options that have the value `withvalue`
398                           ::
399
400                             >>> print c.make_dict(withoption='var1',
401                                                   withvalue=u'value')
402                             {'od2.var4': None,
403                             'od2.var5': None,
404                             'od2.var6': None,
405                             'od2.var1': u'value'}
406
407         :returns: dict of Option's name (or path) and values
408         """
409         pathsvalues = []
410         if _currpath is None:
411             _currpath = []
412         if withoption is None and withvalue is not None:
413             raise ValueError(_("make_dict can't filtering with value without "
414                                "option"))
415         if withoption is not None:
416             mypath = self.cfgimpl_get_path()
417             for path in self._cfgimpl_get_context()._find(bytype=Option,
418                                                           byname=withoption,
419                                                           byvalue=withvalue,
420                                                           first=False,
421                                                           type_='path',
422                                                           _subpath=mypath):
423                 path = '.'.join(path.split('.')[:-1])
424                 opt = self._cfgimpl_get_context().cfgimpl_get_description(
425                 ).impl_get_opt_by_path(path)
426                 if mypath is not None:
427                     if mypath == path:
428                         withoption = None
429                         withvalue = None
430                         break
431                     else:
432                         tmypath = mypath + '.'
433                         if not path.startswith(tmypath):
434                             raise AttributeError(_('unexpected path {0}, '
435                                                    'should start with {1}'
436                                                    '').format(path, mypath))
437                         path = path[len(tmypath):]
438                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
439         #withoption can be set to None below !
440         if withoption is None:
441             for opt in self.cfgimpl_get_description().impl_getchildren():
442                 path = opt.impl_getname()
443                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
444         if _currpath == []:
445             options = dict(pathsvalues)
446             return options
447         return pathsvalues
448
449     def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
450         if isinstance(opt, OptionDescription):
451             try:
452                 pathsvalues += getattr(self, path).make_dict(flatten,
453                                                              _currpath +
454                                                              path.split('.'))
455             except PropertiesOptionError:
456                 pass  # this just a hidden or disabled option
457         else:
458             try:
459                 value = self._getattr(opt.impl_getname())
460                 if flatten:
461                     name = opt.impl_getname()
462                 else:
463                     name = '.'.join(_currpath + [opt.impl_getname()])
464                 pathsvalues.append((name, value))
465             except PropertiesOptionError:
466                 pass  # this just a hidden or disabled option
467
468     def cfgimpl_get_path(self):
469         descr = self.cfgimpl_get_description()
470         context_descr = self._cfgimpl_get_context().cfgimpl_get_description()
471         return context_descr.impl_get_path_by_opt(descr)
472
473
474 class CommonConfig(SubConfig):
475     "abstract base class for the Config and the MetaConfig"
476     __slots__ = ('_impl_values', '_impl_settings', '_impl_meta')
477
478     def _impl_build_all_paths(self):
479         self.cfgimpl_get_description().impl_build_cache()
480
481     def read_only(self):
482         "read only is a global config's setting, see `settings.py`"
483         self.cfgimpl_get_settings().read_only()
484
485     def read_write(self):
486         "read write is a global config's setting, see `settings.py`"
487         self.cfgimpl_get_settings().read_write()
488
489     def getowner(self, opt):
490         """convenience method to retrieve an option's owner
491         from the config itself
492         """
493         if not isinstance(opt, Option) and not isinstance(opt, SymLinkOption):
494             raise TypeError(_('opt in getowner must be an option not {0}'
495                               '').format(type(opt)))
496         return self.cfgimpl_get_values().getowner(opt)
497
498     def unwrap_from_path(self, path, force_permissive=False):
499         """convenience method to extract and Option() object from the Config()
500         and it is **fast**: finds the option directly in the appropriate
501         namespace
502
503         :returns: Option()
504         """
505         if '.' in path:
506             homeconfig, path = self.cfgimpl_get_home_by_path(
507                 path, force_permissive=force_permissive)
508             return getattr(homeconfig.cfgimpl_get_description(), path)
509         return getattr(self.cfgimpl_get_description(), path)
510
511     def cfgimpl_get_path(self):
512         return None
513
514     def cfgimpl_get_meta(self):
515         return self._impl_meta
516
517     # information
518     def impl_set_information(self, key, value):
519         """updates the information's attribute
520
521         :param key: information's key (ex: "help", "doc"
522         :param value: information's value (ex: "the help string")
523         """
524         self._impl_values.set_information(key, value)
525
526     def impl_get_information(self, key, default=None):
527         """retrieves one information's item
528
529         :param key: the item string (ex: "help")
530         """
531         return self._impl_values.get_information(key, default)
532
533
534 # ____________________________________________________________
535 class Config(CommonConfig):
536     "main configuration management entry"
537     __slots__ = ('__weakref__', '_impl_test')
538
539     def __init__(self, descr, session_id=None, persistent=False):
540         """ Configuration option management master class
541
542         :param descr: describes the configuration schema
543         :type descr: an instance of ``option.OptionDescription``
544         :param context: the current root config
545         :type context: `Config`
546         :param session_id: session ID is import with persistent Config to
547         retrieve good session
548         :type session_id: `str`
549         :param persistent: if persistent, don't delete storage when leaving
550         :type persistent: `boolean`
551         """
552         settings, values = get_storages(self, session_id, persistent)
553         self._impl_settings = Settings(self, settings)
554         self._impl_values = Values(self, values)
555         super(Config, self).__init__(descr, weakref.ref(self))
556         self._impl_build_all_paths()
557         self._impl_meta = None
558         #undocumented option used only in test script
559         self._impl_test = False
560
561     def __getstate__(self):
562         if self._impl_meta is not None:
563             raise ConfigError('cannot serialize Config with meta')
564         slots = set()
565         for subclass in self.__class__.__mro__:
566             if subclass is not object:
567                 slots.update(subclass.__slots__)
568         slots -= frozenset(['_impl_context', '__weakref__'])
569         state = {}
570         for slot in slots:
571             try:
572                 state[slot] = getattr(self, slot)
573             except AttributeError:
574                 pass
575         storage = self._impl_values._p_._storage
576         if not storage.serializable:
577             raise ConfigError('this storage is not serialisable, could be a '
578                               'none persistent storage')
579         state['_storage'] = {'session_id': storage.session_id,
580                              'persistent': storage.persistent}
581         state['_impl_setting'] = _impl_getstate_setting()
582         return state
583
584     def __setstate__(self, state):
585         for key, value in state.items():
586             if key not in ['_storage', '_impl_setting']:
587                 setattr(self, key, value)
588         set_storage(**state['_impl_setting'])
589         self._impl_context = weakref.ref(self)
590         self._impl_settings.context = weakref.ref(self)
591         self._impl_values.context = weakref.ref(self)
592         storage = get_storage(test=self._impl_test, **state['_storage'])
593         self._impl_values._impl_setstate(storage)
594         self._impl_settings._impl_setstate(storage)
595
596     def cfgimpl_reset_cache(self,
597                             only_expired=False,
598                             only=('values', 'settings')):
599         if 'values' in only:
600             self.cfgimpl_get_values().reset_cache(only_expired=only_expired)
601         if 'settings' in only:
602             self.cfgimpl_get_settings().reset_cache(only_expired=only_expired)
603
604
605 #class MetaConfig(CommonConfig):
606 #    __slots__ = ('_impl_children',)
607
608 #    def __init__(self, children, meta=True, session_id=None, persistent=False):
609 #        if not isinstance(children, list):
610 #            raise ValueError(_("metaconfig's children must be a list"))
611 #        self._impl_descr = None
612 #        self._impl_path = None
613 #        if meta:
614 #            for child in children:
615 #                if not isinstance(child, CommonConfig):
616 #                    raise TypeError(_("metaconfig's children "
617 #                                      "must be config, not {0}"
618 #                                      ).format(type(child)))
619 #                if self._impl_descr is None:
620 #                    self._impl_descr = child.cfgimpl_get_description()
621 #                elif not self._impl_descr is child.cfgimpl_get_description():
622 #                    raise ValueError(_('all config in metaconfig must '
623 #                                       'have the same optiondescription'))
624 #                if child.cfgimpl_get_meta() is not None:
625 #                    raise ValueError(_("child has already a metaconfig's"))
626 #                child._impl_meta = self
627
628 #        self._impl_children = children
629 #        settings, values = get_storages(self, session_id, persistent)
630 #        self._impl_settings = Settings(self, settings)
631 #        self._impl_values = Values(self, values)
632 #        self._impl_meta = None
633
634 #    def cfgimpl_get_children(self):
635 #        return self._impl_children
636
637 #    def cfgimpl_get_context(self):
638 #        "a meta config is a config wich has a setting, that is itself"
639 #        return self
640
641 #    def cfgimpl_reset_cache(self,
642 #                            only_expired=False,
643 #                            only=('values', 'settings')):
644 #        if 'values' in only:
645 #            self.cfgimpl_get_values().reset_cache(only_expired=only_expired)
646 #        if 'settings' in only:
647 #            self.cfgimpl_get_settings().reset_cache(only_expired=only_expired)
648 #        for child in self._impl_children:
649 #            child.cfgimpl_reset_cache(only_expired=only_expired, only=only)
650
651 #    def set_contexts(self, path, value):
652 #        for child in self._impl_children:
653 #            try:
654 #                if not isinstance(child, MetaConfig):
655 #                    setattr(child, path, value)
656 #                else:
657 #                    child.set_contexts(path, value)
658 #            except PropertiesOptionError:
659 #                pass
660
661 #    def find_first_contexts(self, byname=None, bypath=None, byvalue=None,
662 #                            type_='path', display_error=True):
663 #        ret = []
664 #        try:
665 #            if bypath is None and byname is not None and \
666 #                    self.cfgimpl_get_description() is not None:
667 #                bypath = self._find(bytype=None, byvalue=None, byname=byname,
668 #                                    first=True, type_='path',
669 #                                    check_properties=False,
670 #                                    display_error=display_error)
671 #        except ConfigError:
672 #            pass
673 #        for child in self._impl_children:
674 #            try:
675 #                if not isinstance(child, MetaConfig):
676 #                    if bypath is not None:
677 #                        if byvalue is not None:
678 #                            if getattr(child, bypath) == byvalue:
679 #                                ret.append(child)
680 #                        else:
681 #                            #not raise
682 #                            getattr(child, bypath)
683 #                            ret.append(child)
684 #                    else:
685 #                        ret.append(child.find_first(byname=byname,
686 #                                                    byvalue=byvalue,
687 #                                                    type_=type_,
688 #                                                    display_error=False))
689 #                else:
690 #                    ret.extend(child.find_first_contexts(byname=byname,
691 #                                                         bypath=bypath,
692 #                                                         byvalue=byvalue,
693 #                                                         type_=type_,
694 #                                                         display_error=False))
695 #            except AttributeError:
696 #                pass
697 #        return self._find_return_results(ret, display_error)
698
699
700 def mandatory_warnings(config):
701     """convenience function to trace Options that are mandatory and
702     where no value has been set
703
704     :returns: generator of mandatory Option's path
705
706     """
707     #if value in cache, properties are not calculated
708     config.cfgimpl_reset_cache(only=('values',))
709     for path in config.cfgimpl_get_description().impl_getpaths(
710             include_groups=True):
711         try:
712             config._getattr(path, force_properties=frozenset(('mandatory',)))
713         except PropertiesOptionError as err:
714             if err.proptype == ['mandatory']:
715                 yield path
716     config.cfgimpl_reset_cache(only=('values',))