first version with sqlalchemy option's storage
[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         """
258             finds a list of options recursively in the config
259
260             :param bytype: Option class (BoolOption, StrOption, ...)
261             :param byname: filter by Option.impl_getname()
262             :param byvalue: filter by the option's value
263             :returns: list of matching Option objects
264         """
265         return self._cfgimpl_get_context()._find(bytype, byname, byvalue,
266                                                  first=False,
267                                                  type_=type_,
268                                                  _subpath=self.cfgimpl_get_path()
269                                                  )
270
271     def find_first(self, bytype=None, byname=None, byvalue=None,
272                    type_='option', display_error=True):
273         """
274             finds an option recursively in the config
275
276             :param bytype: Option class (BoolOption, StrOption, ...)
277             :param byname: filter by Option.impl_getname()
278             :param byvalue: filter by the option's value
279             :returns: list of matching Option objects
280         """
281         return self._cfgimpl_get_context()._find(
282             bytype, byname, byvalue, first=True, type_=type_,
283             _subpath=self.cfgimpl_get_path(), display_error=display_error)
284
285     def _find(self, bytype, byname, byvalue, first, type_='option',
286               _subpath=None, check_properties=True, display_error=True):
287         """
288         convenience method for finding an option that lives only in the subtree
289
290         :param first: return only one option if True, a list otherwise
291         :return: find list or an exception if nothing has been found
292         """
293         def _filter_by_name():
294             try:
295                 if byname is None or path == byname or \
296                         path.endswith('.' + byname):
297                     return True
298             except IndexError:
299                 pass
300             return False
301
302         def _filter_by_value():
303             if byvalue is None:
304                 return True
305             try:
306                 value = getattr(self, path)
307                 if isinstance(value, Multi):
308                     return byvalue in value
309                 else:
310                     return value == byvalue
311             except PropertiesOptionError:  # a property is a restriction
312                                            # upon the access of the value
313                 return False
314
315         def _filter_by_type():
316             if bytype is None:
317                 return True
318             if isinstance(option, bytype):
319                 return True
320             return False
321
322         if type_ not in ('option', 'path', 'value'):
323             raise ValueError(_('unknown type_ type {0}'
324                                'for _find').format(type_))
325         find_results = []
326         paths = self.cfgimpl_get_description()._cache_paths[1]
327         for path in paths:
328             option = self.cfgimpl_get_description().impl_get_opt_by_path(path)
329             if isinstance(option, OptionDescription):
330                 continue
331             if _subpath is not None and not path.startswith(_subpath + '.'):
332                 continue
333             if not _filter_by_name():
334                 continue
335             if not _filter_by_value():
336                 continue
337             if not _filter_by_type():
338                 continue
339             #remove option with propertyerror, ...
340             if byvalue is None and check_properties:
341                 try:
342                     value = getattr(self, path)
343                 except PropertiesOptionError:
344                     # a property restricts the access of the value
345                     continue
346             if type_ == 'value':
347                 retval = value
348             elif type_ == 'path':
349                 retval = path
350             elif type_ == 'option':
351                 retval = option
352             if first:
353                 return retval
354             else:
355                 find_results.append(retval)
356         return self._find_return_results(find_results, display_error)
357
358     def _find_return_results(self, find_results, display_error):
359         if find_results == []:
360             if display_error:
361                 raise AttributeError(_("no option found in config"
362                                        " with these criteria"))
363             else:
364                 # translation is slow
365                 raise AttributeError()
366         else:
367             return find_results
368
369     def make_dict(self, flatten=False, _currpath=None, withoption=None,
370                   withvalue=None):
371         """exports the whole config into a `dict`, for example:
372
373         >>> print cfg.make_dict()
374         {'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
375
376
377
378         :param flatten: returns a dict(name=value) instead of a dict(path=value)
379                         ::
380
381                             >>> print cfg.make_dict(flatten=True)
382                             {'var5': None, 'var4': None, 'var6': None}
383
384         :param withoption: returns the options that are present in the very same
385                            `OptionDescription` than the `withoption` itself::
386
387                                 >>> print cfg.make_dict(withoption='var1')
388                                 {'od2.var4': None, 'od2.var5': None,
389                                 'od2.var6': None,
390                                 'od2.var1': u'value',
391                                 'od1.var1': None,
392                                 'od1.var3': None,
393                                 'od1.var2': None}
394
395         :param withvalue: returns the options that have the value `withvalue`
396                           ::
397
398                             >>> print c.make_dict(withoption='var1',
399                                                   withvalue=u'value')
400                             {'od2.var4': None,
401                             'od2.var5': None,
402                             'od2.var6': None,
403                             'od2.var1': u'value'}
404
405         :returns: dict of Option's name (or path) and values
406         """
407         pathsvalues = []
408         if _currpath is None:
409             _currpath = []
410         if withoption is None and withvalue is not None:
411             raise ValueError(_("make_dict can't filtering with value without "
412                                "option"))
413         if withoption is not None:
414             mypath = self.cfgimpl_get_path()
415             for path in self._cfgimpl_get_context()._find(bytype=Option,
416                                                           byname=withoption,
417                                                           byvalue=withvalue,
418                                                           first=False,
419                                                           type_='path',
420                                                           _subpath=mypath):
421                 path = '.'.join(path.split('.')[:-1])
422                 opt = self._cfgimpl_get_context().cfgimpl_get_description(
423                 ).impl_get_opt_by_path(path)
424                 if mypath is not None:
425                     if mypath == path:
426                         withoption = None
427                         withvalue = None
428                         break
429                     else:
430                         tmypath = mypath + '.'
431                         if not path.startswith(tmypath):
432                             raise AttributeError(_('unexpected path {0}, '
433                                                    'should start with {1}'
434                                                    '').format(path, mypath))
435                         path = path[len(tmypath):]
436                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
437         #withoption can be set to None below !
438         if withoption is None:
439             for opt in self.cfgimpl_get_description().impl_getchildren():
440                 path = opt.impl_getname()
441                 self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
442         if _currpath == []:
443             options = dict(pathsvalues)
444             return options
445         return pathsvalues
446
447     def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
448         if isinstance(opt, OptionDescription):
449             try:
450                 pathsvalues += getattr(self, path).make_dict(flatten,
451                                                              _currpath +
452                                                              path.split('.'))
453             except PropertiesOptionError:
454                 pass  # this just a hidden or disabled option
455         else:
456             try:
457                 value = self._getattr(opt.impl_getname())
458                 if flatten:
459                     name = opt.impl_getname()
460                 else:
461                     name = '.'.join(_currpath + [opt.impl_getname()])
462                 pathsvalues.append((name, value))
463             except PropertiesOptionError:
464                 pass  # this just a hidden or disabled option
465
466     def cfgimpl_get_path(self):
467         descr = self.cfgimpl_get_description()
468         context_descr = self._cfgimpl_get_context().cfgimpl_get_description()
469         return context_descr.impl_get_path_by_opt(descr)
470
471
472 class CommonConfig(SubConfig):
473     "abstract base class for the Config and the MetaConfig"
474     __slots__ = ('_impl_values', '_impl_settings', '_impl_meta')
475
476     def _impl_build_all_paths(self):
477         self.cfgimpl_get_description().impl_build_cache()
478
479     def read_only(self):
480         "read only is a global config's setting, see `settings.py`"
481         self.cfgimpl_get_settings().read_only()
482
483     def read_write(self):
484         "read write is a global config's setting, see `settings.py`"
485         self.cfgimpl_get_settings().read_write()
486
487     def getowner(self, opt):
488         """convenience method to retrieve an option's owner
489         from the config itself
490         """
491         if not isinstance(opt, Option) and not isinstance(opt, SymLinkOption):
492             raise TypeError(_('opt in getowner must be an option not {0}'
493                               '').format(type(opt)))
494         return self.cfgimpl_get_values().getowner(opt)
495
496     def unwrap_from_path(self, path, force_permissive=False):
497         """convenience method to extract and Option() object from the Config()
498         and it is **fast**: finds the option directly in the appropriate
499         namespace
500
501         :returns: Option()
502         """
503         if '.' in path:
504             homeconfig, path = self.cfgimpl_get_home_by_path(
505                 path, force_permissive=force_permissive)
506             return getattr(homeconfig.cfgimpl_get_description(), path)
507         return getattr(self.cfgimpl_get_description(), path)
508
509     def cfgimpl_get_path(self):
510         return None
511
512     def cfgimpl_get_meta(self):
513         return self._impl_meta
514
515     # information
516     def impl_set_information(self, key, value):
517         """updates the information's attribute
518
519         :param key: information's key (ex: "help", "doc"
520         :param value: information's value (ex: "the help string")
521         """
522         self._impl_values.set_information(key, value)
523
524     def impl_get_information(self, key, default=None):
525         """retrieves one information's item
526
527         :param key: the item string (ex: "help")
528         """
529         return self._impl_values.get_information(key, default)
530
531
532 # ____________________________________________________________
533 class Config(CommonConfig):
534     "main configuration management entry"
535     __slots__ = ('__weakref__', '_impl_test')
536
537     def __init__(self, descr, session_id=None, persistent=False):
538         """ Configuration option management master class
539
540         :param descr: describes the configuration schema
541         :type descr: an instance of ``option.OptionDescription``
542         :param context: the current root config
543         :type context: `Config`
544         :param session_id: session ID is import with persistent Config to
545         retrieve good session
546         :type session_id: `str`
547         :param persistent: if persistent, don't delete storage when leaving
548         :type persistent: `boolean`
549         """
550         settings, values = get_storages(self, session_id, persistent)
551         self._impl_settings = Settings(self, settings)
552         self._impl_values = Values(self, values)
553         super(Config, self).__init__(descr, weakref.ref(self))
554         self._impl_build_all_paths()
555         self._impl_meta = None
556         #undocumented option used only in test script
557         self._impl_test = False
558
559     def __getstate__(self):
560         if self._impl_meta is not None:
561             raise ConfigError('cannot serialize Config with meta')
562         slots = set()
563         for subclass in self.__class__.__mro__:
564             if subclass is not object:
565                 slots.update(subclass.__slots__)
566         slots -= frozenset(['_impl_context', '__weakref__'])
567         state = {}
568         for slot in slots:
569             try:
570                 state[slot] = getattr(self, slot)
571             except AttributeError:
572                 pass
573         storage = self._impl_values._p_._storage
574         if not storage.serializable:
575             raise ConfigError('this storage is not serialisable, could be a '
576                               'none persistent storage')
577         state['_storage'] = {'session_id': storage.session_id,
578                              'persistent': storage.persistent}
579         state['_impl_setting'] = _impl_getstate_setting()
580         return state
581
582     def __setstate__(self, state):
583         for key, value in state.items():
584             if key not in ['_storage', '_impl_setting']:
585                 setattr(self, key, value)
586         set_storage(**state['_impl_setting'])
587         self._impl_context = weakref.ref(self)
588         self._impl_settings.context = weakref.ref(self)
589         self._impl_values.context = weakref.ref(self)
590         storage = get_storage(test=self._impl_test, **state['_storage'])
591         self._impl_values._impl_setstate(storage)
592         self._impl_settings._impl_setstate(storage)
593
594     def cfgimpl_reset_cache(self,
595                             only_expired=False,
596                             only=('values', 'settings')):
597         if 'values' in only:
598             self.cfgimpl_get_values().reset_cache(only_expired=only_expired)
599         if 'settings' in only:
600             self.cfgimpl_get_settings().reset_cache(only_expired=only_expired)
601
602
603 #class MetaConfig(CommonConfig):
604 #    __slots__ = ('_impl_children',)
605
606 #    def __init__(self, children, meta=True, session_id=None, persistent=False):
607 #        if not isinstance(children, list):
608 #            raise ValueError(_("metaconfig's children must be a list"))
609 #        self._impl_descr = None
610 #        self._impl_path = None
611 #        if meta:
612 #            for child in children:
613 #                if not isinstance(child, CommonConfig):
614 #                    raise TypeError(_("metaconfig's children "
615 #                                      "must be config, not {0}"
616 #                                      ).format(type(child)))
617 #                if self._impl_descr is None:
618 #                    self._impl_descr = child.cfgimpl_get_description()
619 #                elif not self._impl_descr is child.cfgimpl_get_description():
620 #                    raise ValueError(_('all config in metaconfig must '
621 #                                       'have the same optiondescription'))
622 #                if child.cfgimpl_get_meta() is not None:
623 #                    raise ValueError(_("child has already a metaconfig's"))
624 #                child._impl_meta = self
625
626 #        self._impl_children = children
627 #        settings, values = get_storages(self, session_id, persistent)
628 #        self._impl_settings = Settings(self, settings)
629 #        self._impl_values = Values(self, values)
630 #        self._impl_meta = None
631
632 #    def cfgimpl_get_children(self):
633 #        return self._impl_children
634
635 #    def cfgimpl_get_context(self):
636 #        "a meta config is a config wich has a setting, that is itself"
637 #        return self
638
639 #    def cfgimpl_reset_cache(self,
640 #                            only_expired=False,
641 #                            only=('values', 'settings')):
642 #        if 'values' in only:
643 #            self.cfgimpl_get_values().reset_cache(only_expired=only_expired)
644 #        if 'settings' in only:
645 #            self.cfgimpl_get_settings().reset_cache(only_expired=only_expired)
646 #        for child in self._impl_children:
647 #            child.cfgimpl_reset_cache(only_expired=only_expired, only=only)
648
649 #    def set_contexts(self, path, value):
650 #        for child in self._impl_children:
651 #            try:
652 #                if not isinstance(child, MetaConfig):
653 #                    setattr(child, path, value)
654 #                else:
655 #                    child.set_contexts(path, value)
656 #            except PropertiesOptionError:
657 #                pass
658
659 #    def find_first_contexts(self, byname=None, bypath=None, byvalue=None,
660 #                            type_='path', display_error=True):
661 #        ret = []
662 #        try:
663 #            if bypath is None and byname is not None and \
664 #                    self.cfgimpl_get_description() is not None:
665 #                bypath = self._find(bytype=None, byvalue=None, byname=byname,
666 #                                    first=True, type_='path',
667 #                                    check_properties=False,
668 #                                    display_error=display_error)
669 #        except ConfigError:
670 #            pass
671 #        for child in self._impl_children:
672 #            try:
673 #                if not isinstance(child, MetaConfig):
674 #                    if bypath is not None:
675 #                        if byvalue is not None:
676 #                            if getattr(child, bypath) == byvalue:
677 #                                ret.append(child)
678 #                        else:
679 #                            #not raise
680 #                            getattr(child, bypath)
681 #                            ret.append(child)
682 #                    else:
683 #                        ret.append(child.find_first(byname=byname,
684 #                                                    byvalue=byvalue,
685 #                                                    type_=type_,
686 #                                                    display_error=False))
687 #                else:
688 #                    ret.extend(child.find_first_contexts(byname=byname,
689 #                                                         bypath=bypath,
690 #                                                         byvalue=byvalue,
691 #                                                         type_=type_,
692 #                                                         display_error=False))
693 #            except AttributeError:
694 #                pass
695 #        return self._find_return_results(ret, display_error)
696
697
698 def mandatory_warnings(config):
699     """convenience function to trace Options that are mandatory and
700     where no value has been set
701
702     :returns: generator of mandatory Option's path
703
704     """
705     #if value in cache, properties are not calculated
706     config.cfgimpl_reset_cache(only=('values',))
707     for path in config.cfgimpl_get_description().impl_getpaths(
708             include_groups=True):
709         try:
710             config._getattr(path, force_properties=frozenset(('mandatory',)))
711         except PropertiesOptionError as err:
712             if err.proptype == ['mandatory']:
713                 yield path
714     config.cfgimpl_reset_cache(only=('values',))