sleepguard package

Subpackages

Submodules

sleepguard.guard module

A script that monitors several types of activity and prevents the system from sleeping if the average activity level is above a threshold over a specified period of time.

class sleepguard.guard.ProgramOptions(*, config_path: Path | None = None, configuration: SleepGuardConfiguration | None = None)[source]

Bases: Dataclass

General options for the program.

config_path: pathlib.Path | None = None

The path to a configuration file. This will override any other configuration files found in supported locations.

configuration: SleepGuardConfiguration | None = None

Override individual configuration options specified in the loaded configuration file.

class sleepguard.guard.SleepGuardConfiguration(*, monitor_criteria: 'list[MonitorCriteria]' = <factory>, poll_period: 'Optional[int]' = None, burn_in: 'Optional[int]' = None, log_level: 'Optional[int]' = None, log_format: 'Optional[str]' = None, syslog_address: 'Optional[str]' = None)[source]

Bases: Serializable

burn_in: int | None = None

The monitored statistics will sensitive to outliers early in the monitoring, so we will not start guarding until after the burn in period to allow some data points to be acquired.

decode_into_subclasses: ClassVar[bool] = False
log_format: str | None = None

The log format.

log_level: int | None = None

The python log level to use (as an integer)

monitor_criteria: list[MonitorCriteria]
poll_period: int | None = None

The number of seconds the script will check to see if the monitored system resources are above their respective thresholds.

syslog_address: str | None = None

The address of the syslog server.

sleepguard.guard.assign_defaults(config: SleepGuardConfiguration) SleepGuardConfiguration[source]

Assign default values for configuration values that have not been set.

Parameters:

config

Returns:

sleepguard.guard.get_default_configuration_path() Path[source]

Get the absolute path of the default configuration file.

Returns:

sleepguard.guard.get_existing_configuration_files() list[Path][source]

Find and return any existing config files in the supported system or user directories.

Returns:

sleepguard.guard.get_sleep_inhibitor_method() str[source]

Gets the method used to keep the system awake.

Returns:

sleepguard.guard.get_supported_configuration_paths() list[Path][source]

Get a list of the supported configuration paths in order from the least priority to the highest.

Returns:

sleepguard.guard.get_system_monitors(config: SleepGuardConfiguration) list[UtilizationMonitor][source]

Get the list of system resource monitors to use.

Returns:

sleepguard.guard.install_default_configuration() Path[source]

Install a default configuration in the user’s home directory, if no configuration is detected in any of the supported locations.

Returns:

The path to the newly created default configuration file.

sleepguard.guard.is_system_util_above_threshold(monitors: Iterable[UtilizationMonitor]) UtilizationMonitor | None[source]

Checks if any of the measured utilization types are above their corresponding threshold.

Parameters:

monitors

Returns:

The first monitor that is above their threshold or None if all are below their respective thresholds.

sleepguard.guard.load_configuration(options: ProgramOptions | None) SleepGuardConfiguration[source]

Load the project settings.

Returns:

sleepguard.guard.main(options: ProgramOptions | None = None)[source]
Returns:

sleepguard.guard.merge_configurations(configurations: list[SleepGuardConfiguration]) SleepGuardConfiguration[source]

Merge multiple configuration values into a single configuration value by prioritizing the most local configuration values.

Parameters:

configurations

Returns:

sleepguard.guard.merge_fields(current_config: SleepGuardConfiguration, final_fields: dict[str, Any])[source]
Parameters:
  • current_config

  • final_fields

Returns:

sleepguard.guard.merge_monitor_criteria(current_config: SleepGuardConfiguration, final_monitor_criteria: dict[str, MonitorCriteria])[source]

Update the monitor criteria from the current configuration.

Parameters:
  • current_config

  • final_monitor_criteria

Returns:

sleepguard.guard.setup_logging(configuration: SleepGuardConfiguration) Logger[source]

Setup the logging.

Parameters:

configuration

Returns:

sleepguard.guard.signal_handler(sig, frame)[source]

Log that we are shutting down if Ctrl+C is pressed or SIGTERM is received.

Parameters:
  • sig

  • frame

Returns:

Module contents