Is root

Lets write this only once (DRY principle)

Returns messages thru callbacks. So do not print or log anything

Module private variables

logging_strict.util.util_root.__all__: tuple[str, str] = ("IsRoot", "check_python_not_old")

Module object exports

logging_strict.util.util_root.g_module: str = "logging_strict.util.util_root"

This module’s dotted path

logging_strict.util.util_root._LOGGER: logging.Logger

Module level logger

logging_strict.util.util_root.g_is_root: bool

True if app run as a service with root privledges. False if run normally and sanely

logging_strict.util.util_root.is_python_old: bool

True if py38- otherwise False

Module objects

class logging_strict.util.util_root.IsRoot

Checks whether or not root DRY principle; don’t repeat yourself; which became tiresome

Class variables

Variables:

__slots__ – Turns off dynamic instance variables

Vartype:

ClassVar[tuple[()]]

classmethod check_not_root(callback=None, is_app_exit=False, is_raise_exc=False)

What to do if app executed as normal user

Parameters:
  • callback (collections.abc.Callable[[], str] | None) – If provided passes error message for handling

  • is_app_exit (bool | None) – True and not normal user, should exit app

  • is_raise_exc (bool | None) – True and not normal user, should raise an Exception

Raises:

PermissionError – Requires root to run

classmethod check_root(callback=None, is_app_exit=False, is_raise_exc=False)

What to do if app executed as root

Parameters:
  • callback (collections.abc.Callable[[], str] | None) – If provided passes error message for handling

  • is_app_exit (bool | None) – True and not root, should exit app

  • is_raise_exc (bool | None) – True and not root, should raise an Exception

Raises:

PermissionError – Requires root to run

static is_root()

Whether or not root.

Returns:

True is root otherwise False

Return type:

bool

classmethod path_home_root()

Replacement for get_logname

Intended to be run only by root, but not necessarily

Returns:

root home folder

Return type:

pathlib.Path

classmethod set_owner_as_user(path_file, is_as_user=False)
Parameters:
  • path_file (Any) – Path to the file

  • is_as_user (Any | None) – Flag. True if file permissions should be as a user otherwise False

logging_strict.util.util_root.check_python_not_old(callback=None, is_app_exit=False, is_raise_exc=False)

Warn raising error if python interpretor version is an unsupported version

Parameters:
  • callback (collections.abc.Callable[[], str] | None) – If provided passes error message for handling

  • is_app_exit (bool | None) – True and before py39, should exit app

  • is_raise_exc (bool | None) – True and before py39, should raise an Exception

Raises:

PermissionError – Requires root to run