Important
This project is under development. All source code and features on the main branch are for the purpose of testing or evaluation and not production ready.
Module with common libs used in MFD modules.
Params:
timeout: float- Time, after which bool(obj) will become Truefirst_check_start: bool- IfTrue- start counting from the firstbool(obj)attempt, otherwise counting is started at object creation.
Representation:
bool(obj:TimeoutCounter)returnsFalseif timer last less than timeout andTrueif more.
Context manager to temporarily suppress log messages.
By default, suppresses all log messages from levels 0 - MODULE_DEBUG (inclusive).
Can be parametrized by providing level argument.
from mfd_common_libs import DisableLogger
with DisableLogger():
# do somethingfrom mfd_common_libs import DisableLogger
with DisableLogger(level=logging.INFO):
# do somethingIt's a decorator, which logs name and passed arguments to decorated method. Uses given logger Params:
logger- object of Logger
import logging
from mfd_common_libs import log_func_info
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
@log_func_info(logger)
def calling_someone(someone):
pass
calling_someone('Adam')logs MODULE_DEBUG:__main__:Calling func: calling_someone with arguments: ['Adam']
It's a decorator, which checks if OS of connected device is expected/supported. It can be used in implementation of modules.
Requires Connection object from mfd_connect as argument in function!
Params:
- handle OSName written as python arguments eg.
@os_supported(OSName.LINUX)or@os_supported(OSName.LINUX, OSName.WINDOWS)
Raises OSSupportedDecoratorErrorif not found necessary 'connection' and UnexpectedOSException when OS is unexpected.
Usually usage:
from mfd_common_libs import os_supported
from mfd_typing import OSName
class MyModule:
"""My module."""
@os_supported(OSName.LINUX, OSName.WINDOWS, OSName.FREEBSD)
def __init__(self, *, connection):
self._conn = connectionWhen your class doesn't have implemented custom __init__, but uses from parent, you need to define __init__ like as bottom:
from mfd_common_libs import os_supported
from mfd_typing import OSName
class MyModule:
"""My module."""
def __init__(self, *, connection):
self._conn = connection
class MyModuleWithInherit(MyModule):
"""My child module."""
__init__ = os_supported(OSName.LINUX)(MyModule.__init__)
def some_method(self):
passadd_logging_level(level_name: str, level_value: int) -> None- Add a new logging level to theloggingmodule. Does nothing if logging name is already declared.add_logging_group(level_group: LevelGroup) -> None- Add all log levels related to the given group to the logging module.
Basically, add all log levels which include LevelGroup substring.
So for exampleadd_logging_group(LevelGroup.BL)will add:log_levels.BL_STEPlog_levels.BL_INFOlog_levels.BL_DEBUG
class LevelGroup(Enum):
"""Names of log levels' groups."""
BL = auto()
MFD = auto()
TEST = auto()MODULE_DEBUGlog level should be used when any activity during debugging the module is worth logging.CMDlog level should be used only for executed command line (ex. from mfd-connect execute_command method).OUTlog level should be used only for logging output from executed command line (ex. from mfd-connect execute_command method).TEST_PASSlog level should be used in test cases to provide information about test result.TEST_FAILlog level should be used in test cases to provide information about test result.TEST_STEPlog level should be used in test cases to provide information on high level steps being performed.TEST_INFOlog level should be used in test cases to provide additional information between step and debug.TEST_DEBUGlog level should be used in test cases for debug information about steps performed.BL_STEPlog level should be used in Business Logic to provide information on high level steps being performed.BL_INFOlog level should be used in Business Logic to provide additional information between step and debug.BL_DEBUGlog level should be used in Business Logic for debug information for steps performed.MFD_STEPlog level should be used in MFDs to provide information on high level steps being performed.MFD_INFOlog level should be used in MFDs to provide additional information between step and debug.MFD_DEBUGlog level should be used in MFDs for debug information about steps performed and is preferred to MODULE_DEBUG.
LevelGroup.BLincludes:BL_STEPBL_INFOBL_DEBUG
LevelGroup.MFDincludes:MFD_STEPMFD_INFOMFD_DEBUGMODULE_DEBUG
LevelGroup.TESTincludes:TEST_PASSTEST_FAILTEST_STEPTEST_INFOTEST_DEBUG
- LINUX
- WINDOWS
- ESXI
- FREEBSD
- EFI shell support
If you encounter any bugs or have suggestions for improvements, you're welcome to contribute directly or open an issue here.