maestral.utils.integration#

This module provides functions for platform integration. Most of the functionality here could also be achieved with psutils, but we want to avoid the large dependency.

Module Contents#

maestral.utils.integration.CPU_CORE_COUNT[source]#
maestral.utils.integration.cat(*paths)[source]#

Attempts to read the content of multiple files which may not exist. Returns the content of the first file which can be read. If none of them can be read return None. Returns an integer if the content is a digit.

Parameters:

paths (os.PathLike[str]) –

Return type:

Union[bytes, None]

maestral.utils.integration.get_inotify_limits()[source]#

Returns the current inotify limit settings as tuple.

Returns:

(max_user_watches, max_user_instances, max_queued_events)

Raises:

OSError – if the settings cannot be read from /proc/sys/fs/inotify. This may happen if /proc/sys is left out of the kernel image or simply not mounted.

Return type:

Tuple[int, int, int]

maestral.utils.integration.cpu_usage_percent(interval=0.1)[source]#

Returns a float representing the CPU utilization of the current process as a percentage. This duplicates the similar method from psutil to avoid the psutil dependency.

Compares process times to system CPU times elapsed before and after the interval (blocking). It is recommended for accuracy that this function be called with an interval of at least 0.1 sec.

A value > 100.0 can be returned in case of processes running multiple threads on different CPU cores. The returned value is explicitly NOT split evenly between all available logical CPUs. This means that a busy loop process running on a system with 2 logical CPUs will be reported as having 100% CPU utilization instead of 50%.

Parameters:

interval (float) – Interval in sec between comparisons of CPU times.

Returns:

CPU usage during interval in percent.

Return type:

float

maestral.utils.integration.check_connection(hostname, timeout=2, logger=None)[source]#

A low latency check for an internet connection.

Parameters:
  • hostname (str) – Hostname to use for connection check.

  • timeout (int) – Timeout in seconds for connection check.

  • logger (Optional[logging.Logger]) – If provided, log output for connection failures will be logged to this logger with the level DEBUG.

Returns:

Connection availability.

Return type:

bool

class maestral.utils.integration.SystemdNotifier[source]#

An interface to notify the systemd the service manager about status changes.

Sends a status message to the systemd the service manager on the socket address provided by the NOTIFY_SOCKET environment variable. Does nothing NOTIFY_SOCKET is not set.

See https://www.freedesktop.org/software/systemd/man/sd_notify.html for a documentation of message formats expected by systemd.

notify(status)[source]#

Send a status update to the service manager.

Parameters:

status (str) – The status update to send.

Return type:

None