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.PIPEto 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.PIPEto capture output.check (bool) – If
True, the function will raise asubprocess.CalledProcessErrorexception if the command’s return code is not in thereturn_codelist. Defaults toTrue.print (bool) – If
True, the command’s standard output will be logged at DEBUG level and standard error at WARNING level. Defaults toTrue.return_code (list) – A list of acceptable return codes for the command. If
checkisTrueand 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.runfunction.
- Raises:
subprocess.CalledProcessError – If
checkisTrueand the command’s return code is not among the expectedreturn_codevalues.- Returns:
An object representing the completed process, including stdout, stderr, and return code.
- Return type:
Modules
Implementation of CLI commands for SCAutolib. |
|
This module defines the |
|
This module defines various enumeration classes used throughout the SCAutolib library. |
|
Exceptions that are used in the SCAutolib library. |
|
This module provides a utility function, |
|
This module serves as the package initializer for |
|
This module provides a collection of utility and helper functions utilized across the SCAutolib library. |