Package mfutil
Generic utility classes and functions.
Expand source code
"""Generic utility classes and functions."""
__pdoc__ = {
"mfutil.jinja2_extensions": False,
"mfutil.cli_tools": False,
"mfutil.eval": False,
"BashWrapper": False,
"BashWrapperException": False,
"BashWrapperOrRaise": False,
"mfutil.exc": False,
"add_inotify_watch": False,
"create_tmp_dirpath": False,
"eval": False,
"get_ipv4_for_hostname": False,
"get_recursive_mtime": False,
"get_tmp_filepath": False,
"get_unique_hexa_identifier": False,
"get_utc_unix_timestamp": False,
"hash_generator": False,
"kill_process_and_children": False,
"mkdir_p": False,
"mkdir_p_or_die": False
}
from mfutil.bash_wrapper import (
BashWrapper,
BashWrapperOrRaise,
BashWrapperException,
)
from mfutil.misc import (
eval,
get_unique_hexa_identifier,
get_utc_unix_timestamp,
mkdir_p,
mkdir_p_or_die,
get_tmp_filepath,
create_tmp_dirpath,
get_ipv4_for_hostname,
get_recursive_mtime,
kill_process_and_children,
add_inotify_watch,
hash_generator,
)
from mfutil.exc import MFUtilException
__all__ = [
"BashWrapper",
"BashWrapperOrRaise",
"BashWrapperException",
"MFUtilException",
"get_unique_hexa_identifier",
"eval",
"get_utc_unix_timestamp",
"mkdir_p",
"mkdir_p_or_die",
"get_tmp_filepath",
"create_tmp_dirpath",
"get_ipv4_for_hostname",
"get_recursive_mtime",
"kill_process_and_children",
"add_inotify_watch",
"hash_generator"
]
Sub-modules
mfutil.bash_wrapper
mfutil.cli
-
Utility functions to build CLI (Python >= 3.6 only).
mfutil.misc
-
Generic utility classes and functions.
mfutil.net
-
Utility functions around network.
Classes
class MFUtilException (msg=None, original_exception=None, **kwargs)
-
Generic exception class with a way to wrap original exceptions.
Very interesting reading about exceptions in Python: https://julien.danjou.info/python-exceptions-guide/
Usage example:
from mfutil import MFUtilException try: 1/0 except Exception as e: raise MFUtilException("something was wrong", original_exception=e)
Output example:
[...] mfutil.exc.MFUtilException: something was wrong: division by zero
Args
msg
:string
- a custom message for this exception.
original_exception
:Exception
- an Exception object to wrap.
Expand source code
class MFUtilException(Exception): """Generic exception class with a way to wrap original exceptions. Very interesting reading about exceptions in Python: https://julien.danjou.info/python-exceptions-guide/ Usage example: ```python from mfutil import MFUtilException try: 1/0 except Exception as e: raise MFUtilException("something was wrong", original_exception=e) ``` Output example: ``` [...] mfutil.exc.MFUtilException: something was wrong: division by zero ``` """ def __init__(self, msg=None, original_exception=None, **kwargs): """ Args: msg (string): a custom message for this exception. original_exception (Exception): an Exception object to wrap. """ if msg is not None: self.message = msg else: self.message = "mfplugin_exception" if original_exception is not None: Exception.__init__( self, self.message + (": %s" % original_exception), **kwargs ) else: Exception.__init__(self, self.message, **kwargs)
Ancestors
- builtins.Exception
- builtins.BaseException