pungi/pungi/phases/phases_metadata.py
Haibo Lin 41a629969c Format code base with black
https://black.readthedocs.io/en/stable/

JIRA: COMPOSE-4086
Signed-off-by: Haibo Lin <hlin@redhat.com>
2020-02-05 17:35:47 +08:00

36 lines
1021 B
Python

# -*- coding: utf-8 -*-
from inspect import isclass
from pungi.phases.base import PhaseBase
def gather_phases_metadata(source_object):
"""
Code gathers metadata from Phase classes.
Metadata are 'name' attributes of the corresponding classes.
Metadata are gathered without creating instances of Phase classes.
"""
if not source_object:
raise ValueError(
"PhasesMetadata can not load any data - it got empty parameter"
)
phases = []
for item in dir(source_object):
cls = getattr(source_object, item) # get all objects references
if not isclass(cls): # filter out non-classes
continue
if issubclass(cls, PhaseBase):
try:
name_attr = getattr(cls, "name")
phases.append(name_attr)
except AttributeError:
raise AttributeError(
"Bad phase-class format: '%s' is missing attribute 'name'" % item
)
return phases