SCAutolib

This module serves as the initialization point for the SCAutolib package.

It sets up the package-wide logging configuration using coloredlogs. It defines global constants for directory paths used throughout the library for templates, backup files, and data dumps.

Additionally, it establishes validation schemas using the schema library for various configuration sections, including CAs (Certificate Authorities), users, and smart cards. These schemas ensure that input data conforms to expected structures and types, facilitating robust data handling across SCAutolib’s components.

The module also provides a generalized run function, acting as a wrapper for subprocess.run. This wrapper standardizes command execution, logging, error checking, and offers options for controlling standard output/error, return code validation, and post-execution delays.

Functions

run(cmd, stdout=-1, stderr=-1, check=True, print_=True, return_code=None, sleep=0, **kwargs)[source]

Executes an external command as a subprocess, providing a controlled wrapper around subprocess.run. This function standardizes command execution, capturing and optionally printing output, performing robust error checking based on expected return codes, and provides consistent logging of what is being executed.

Parameters:
  • cmd (list or str) – The command to be executed, provided as a list of strings (preferred) or a single space-separated string.

  • stdout (None or int or IO) – Redirects the standard output of the command. Accepts an int representing a file descriptor, or an IO object. Defaults to subprocess.PIPE to capture output.

  • stderr (None or int or IO) – Redirects the standard error of the command. Accepts an int representing a file descriptor, or an IO object. Defaults to subprocess.PIPE to capture output.

  • check (bool) – If True, the function will raise a subprocess.CalledProcessError exception if the command’s return code is not in the return_code list. Defaults to True.

  • print (bool) – If True, the command’s standard output will be logged at DEBUG level and standard error at WARNING level. Defaults to True.

  • return_code (list) – A list of acceptable return codes for the command. If check is True and the command’s return code is not in this list, an exception is raised. Defaults to [0].

  • sleep (int) – The duration in seconds to pause execution after the command completes. Defaults to 0.

  • kwargs – Additional keyword arguments are passed directly to the subprocess.run function.

Raises:

subprocess.CalledProcessError – If check is True and the command’s return code is not among the expected return_code values.

Returns:

An object representing the completed process, including stdout, stderr, and return code.

Return type:

subprocess.CompletedProcess

Modules

SCAutolib.cli_commands

Implementation of CLI commands for SCAutolib.

SCAutolib.controller

This module defines the Controller class, which serves as the central orchestrator for SCAutolib's operations.

SCAutolib.enums

This module defines various enumeration classes used throughout the SCAutolib library.

SCAutolib.exceptions

Exceptions that are used in the SCAutolib library.

SCAutolib.isDistro

This module provides a utility function, isDistro, designed to identify the operating system distribution and its version.

SCAutolib.models

This module serves as the package initializer for SCAutolib.models.

SCAutolib.utils

This module provides a collection of utility and helper functions utilized across the SCAutolib library.