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)
returnsFalse
if timer last less than timeout andTrue
if more.
Context manager to temporarily suppress log messages.
from mfd_common_libs import DisableLogger
with DisableLogger():
# do something
It'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 OSSupportedDecoratorError
if 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 = connection
When 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):
pass
add_logging_level(level_name: str, level_value: int) -> None
- Add a new logging level to thelogging
module. 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_STEP
log_levels.BL_INFO
log_levels.BL_DEBUG
class LevelGroup(Enum):
"""Names of log levels' groups."""
BL = auto()
MFD = auto()
TEST = auto()
MODULE_DEBUG
log level should be used when any activity during debugging the module is worth logging.CMD
log level should be used only for executed command line (ex. from mfd-connect execute_command method).OUT
log level should be used only for logging output from executed command line (ex. from mfd-connect execute_command method).TEST_PASS
log level should be used in test cases to provide information about test result.TEST_FAIL
log level should be used in test cases to provide information about test result.TEST_STEP
log level should be used in test cases to provide information on high level steps being performed.TEST_INFO
log level should be used in test cases to provide additional information between step and debug.TEST_DEBUG
log level should be used in test cases for debug information about steps performed.BL_STEP
log level should be used in Business Logic to provide information on high level steps being performed.BL_INFO
log level should be used in Business Logic to provide additional information between step and debug.BL_DEBUG
log level should be used in Business Logic for debug information for steps performed.MFD_STEP
log level should be used in MFDs to provide information on high level steps being performed.MFD_INFO
log level should be used in MFDs to provide additional information between step and debug.MFD_DEBUG
log level should be used in MFDs for debug information about steps performed and is preferred to MODULE_DEBUG.
LevelGroup.BL
includes:BL_STEP
BL_INFO
BL_DEBUG
LevelGroup.MFD
includes:MFD_STEP
MFD_INFO
MFD_DEBUG
MODULE_DEBUG
LevelGroup.TEST
includes:TEST_PASS
TEST_FAIL
TEST_STEP
TEST_INFO
TEST_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.