pyyeti.cla.DR_Results.all_base_events

DR_Results.all_base_events(top_level_name='Top Level')[source]

A generator for looping over all base events

Parameters:

top_level_name (str; optional) – This is the name of the event at the top level of the results structure

Yields:
  • name (str) – The next base-level dictionary key.

  • base (DR_Results instance) – The next base-level DR_Results item. Its entries are the SimpleNamespace data structures for each category.

  • path (list) – List of strings showing the path to the base event, including the name of the base event itself.

Notes

Entries that are neither a DR_Results nor a SimpleNamespace are quietly ignored.

Examples

Since this routine doesn’t actually operate on the results, we can make up an otherwise useless and fake results structure for demonstration. Here, we’ll have two non-base events: the top level one and “NonBase”, and two base events: “Base1” and “Base2”. “Base1” is under “NonBase” while “Base2” is under the top level. We’ll also have two data recovery categories for each base event: ‘ATM’ and ‘LTM’.

The following demonstrates three generators available for DR_Results: all_base_events(), all_nonbase_events(), and all_categories():

>>> from types import SimpleNamespace
>>> from pyyeti import cla
>>> from pyyeti.pp import PP
>>> res = cla.DR_Results()
>>> res['NonBase'] = cla.DR_Results()
>>> res['NonBase']['Base1'] = cla.DR_Results()
>>> res['NonBase']['Base1']['ATM'] = SimpleNamespace()
>>> res['NonBase']['Base1']['LTM'] = SimpleNamespace()
>>> res['Base2'] = cla.DR_Results()
>>> res['Base2']['ATM'] = SimpleNamespace()
>>> res['Base2']['LTM'] = SimpleNamespace()
>>> res['empty'] = cla.DR_Results()  # for testing
>>> PP(res, 5)
<class 'pyyeti.cla.dr_results.DR_Results'>[n=3]
    'NonBase': <class 'pyyeti.cla.dr_results.DR_Results'>[n=1]
        'Base1': <class 'pyyeti.cla.dr_results.DR_Results'>[n=2]
            'ATM': <class 'types.SimpleNamespace'>[n=0]
            'LTM': <class 'types.SimpleNamespace'>[n=0]
    'Base2'  : <class 'pyyeti.cla.dr_results.DR_Results'>[n=2]
        'ATM': <class 'types.SimpleNamespace'>[n=0]
        'LTM': <class 'types.SimpleNamespace'>[n=0]
    'empty'  : <class 'pyyeti.cla.dr_results.DR_Results'>[n=0]

<pyyeti.pp.PP object at ...>

Show the base events:

>>> for name, base, path in res.all_base_events():
...     print(f"{name}, {base}, {path}")
Base1, DR_Results ... ['ATM', 'LTM'], ['NonBase', 'Base1']
Base2, DR_Results ... ['ATM', 'LTM'], ['Base2']

Show the non-base events:

>>> for name, nonb, path in res.all_nonbase_events():
...     print(f"{name}, {nonb}, {path}")
Top Level, DR_Results ... ['NonBase', 'Base2', 'empty'], []
NonBase, DR_Results ... ['Base1'], ['NonBase']

Show all the data recovery categories:

>>> for name, cat, path in res.all_categories():
...     print(f"{name}, {cat}, {path}")
ATM, namespace(), ['NonBase', 'Base1', 'ATM']
LTM, namespace(), ['NonBase', 'Base1', 'LTM']
ATM, namespace(), ['Base2', 'ATM']
LTM, namespace(), ['Base2', 'LTM']