def uut_get_instance(platform, *args, **kwargs): ''' UUT class loader This function loads the relevant uut class depending on the platform. It supports a factory interface, defined by the platform, where it will try to autodetect a class subclassing UUTBase abstract class Args: platform (list[str]): Platforms available ''' log = logging.getLogger(__name__) log.debug('init platform:%s args:%s kwargs:%s', platform, args, kwargs) uut = None for plat in platform: mod_name = get_parent_module(__name__, __file__) # get parent module mod_name += '.' + plat try: class_list = find_subclass(mod_name, UutBase) # get all available interfaces for entry in class_list: log.info('registering uut platform:%s interface:%s class:%s', platform, entry.interface, entry.__name__) uut = entry(*args, **kwargs) return uut # only one interface is used except ImportError: log.info('platform:%s no uut interface found', plat) raise RuntimeError('no uut platform:%s found' % (platform))
def kymera_get_instance(platform, uut, *args, **kwargs): ''' Kymera class loader This function loads the relevant kymera class depending on the platform. It supports a factory interface, defined by the platform, where it will try to autodetect a class subclassing KymeraBase abstract class Args: platform (list[str]): Platforms available uut (kats.kalimba.uut.UutBase): Instance of class uut ''' log = logging.getLogger(__name__) log.debug('init platform:%s uut:%s', platform, uut) kymera = None for plat in platform: mod_name = get_parent_module(__name__, __file__) # get parent module mod_name += '.' + plat try: class_list = find_subclass( mod_name, KymeraBase) # get all available interfaces for entry in class_list: log.info( 'registering kymera platform:%s interface:%s class:%s', platform, entry.interface, entry.__name__) kymera = entry(uut, *args, **kwargs) return kymera # only one interface is used except ImportError: log.info('platform:%s no kymera interface found', plat) raise RuntimeError('no kymera platform:%s found' % (platform))
def __init__(self, platform, kymera): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self._kymera = kymera # we depend on kymera to message the uut self._plugins = {} # registered plugins mod_name = get_parent_module(__name__, __file__) class_list = find_subclass(mod_name, EndpointBase) for entry in class_list: try: if list(set(entry.platform).intersection(platform)): self._register(entry.platform, entry.interface, entry) except Exception: # pylint: disable=broad-except pass
def __init__(self, platform, kalcmd): self._log = logging.getLogger(__name__) if not hasattr(self, '_log') else self._log self._platform = platform self._kalcmd = kalcmd self._plugins = {} mod_name = get_parent_module(__name__, __file__) class_list = find_subclass(mod_name, StreamBase) for entry in class_list: try: if list(set(entry.platform).intersection(platform)): self._register(entry.platform, entry.interface, entry) except Exception: # pylint: disable=broad-except pass
def __init__(self, platform, kymera): self._log = logging.getLogger(__name__) if not hasattr( self, '_log') else self._log self._kymera = kymera # we depend on kymera to message the uut self._plugins = {} # registered plugins mod_name = get_parent_module(__name__, __file__) # get parent module try: class_list = find_subclass( mod_name, CapabilityBase) # get all available interfaces for entry in class_list: if entry.platform in platform and entry != CapabilityGeneric: self._register(entry.platform, entry.interface, entry) except ImportError: self._log.info('no capabilities found') try: gen_cap = CapabilityGenericInfo() gen_cap_list = gen_cap.enum_interface() for entry in gen_cap_list: self._register_multiple(entry[3], entry[0], entry[1], entry[2]) except Exception: # pylint: disable=broad-except self._log.warning('generic capabilities not available')
''' Audio file helper ''' import logging import os from kats.framework.library.factory import find_subclass from kats.library.module import get_parent_module from .audio_base import AudioBase, MODE_DEFAULT DEFAULT_INTERFACE = '_default_interface_' REGISTERED_AUDIO_FILE = {DEFAULT_INTERFACE: None} MOD_NAME = get_parent_module(__name__, __file__) # get parent module try: CLASS_LIST = find_subclass(MOD_NAME, AudioBase) # get all available interfaces for entry in CLASS_LIST: log = logging.getLogger(__name__) log.info('registering audio file interface:%s class:%s', entry.interface, entry.__name__) REGISTERED_AUDIO_FILE[entry.interface] = entry if entry.default_interface: REGISTERED_AUDIO_FILE[DEFAULT_INTERFACE] = entry except ImportError: log = logging.getLogger(__name__) log.info('no audio file interfaces found')