leapp.libraries.stdlib package

Module contents

leapp.libraries.stdlib represents a location for functions that otherwise would be defined multiple times across leapp actors and at the same time, they are really useful for other actors.

exception leapp.libraries.stdlib.CalledProcessError(message, command, result)

Bases: leapp.exceptions.LeappError

Leapp Call Process Exception Error.

Raised when the result of a called process is of a none zero return code.

Initialize CalledProcessError Exception. :param message: An CalledProcessError exception message. :param command: The command that has been executed, with its arguments. :param result: A non-zero whatever result that the command returned.

args
exit_code

Retrieve the exit code. :return: An exit code.

message
pid

Retrieve the pid of the finished process. :return: The pid of the process.

signal

Retrieve the signal which the process was signalled by. :return: A signal that the process received.

stderr

Retrieve the stderr. :return: Standard Error.

stdout

Retrieve the stdout. :return: Standard Output.

leapp.libraries.stdlib.run(args, split=False, callback_raw=<function _console_logging_handler>, callback_linebuffered=<function _logfile_logging_handler>, env=None, checked=True, stdin=None, encoding='utf-8')

Run a command and return its result as a dict.

The execution of the program and it’s results are captured by the audit.

Parameters:
  • args (list or tuple) – Command to execute
  • split (bool) – Split the output on newlines
  • callback_raw ((fd: int, buffer: bytes) -> None) – Optional custom callback executed on raw data to print in console
  • env (dict) – Environment variables to use for execution of the command
  • checked (bool) – Raise an exception on a non-zero exit code, default True
  • stdin (int, str) – String or a file descriptor that will be written to stdin of the child process
Returns:

{‘stdout’ : stdout, ‘stderr’: stderr, ‘signal’: signal, ‘exit_code’: exit_code, ‘pid’: pid}

Return type:

dict

Raises:

OSError if an executable is missing or has wrong permissions

Raises:

CalledProcessError if the cmd has non-zero exit code and checked is False

Raises:

TypeError if any input parameters have an invalid type

Raises:

valueError if any of input parameters have an invalid value

This module implements a convenience API for actions that are accessible to actors.

Any code that wants use this convenience library has to be called from within the actors context. This is true for actors, actor private libraries and repository libraries.

leapp.libraries.stdlib.api.actor_files_paths()

Returns the file paths that are bundled with the actor. (Path to the content of the actor’s file directory).

leapp.libraries.stdlib.api.actor_tools_paths()

Returns the tool paths that are bundled with the actor. (Path to the content of the actor’s tools directory).

leapp.libraries.stdlib.api.common_files_paths()

Returns all common repository file paths.

leapp.libraries.stdlib.api.common_tools_paths()

Returns all common repository tool paths.

leapp.libraries.stdlib.api.consume(*models)

Retrieve messages specified in the actors consumes attribute, and filter message types by models.

Parameters:models (Variable number of the derived classes from leapp.models.Model) – Models to use as a filter for the messages to return
leapp.libraries.stdlib.api.current_actor()

Retrieve the Actor class instance of the current active actor. :return: Instance of the currently instantiated actor. :rtype: leapp.actors.Actor

leapp.libraries.stdlib.api.current_logger()

Retrieve the logger of the current active actor. :return: Logger instance for the current actor. :rtype: logging.Logger

leapp.libraries.stdlib.api.files_paths()

Returns all actor file paths related to the actor and common actors file paths.

leapp.libraries.stdlib.api.get_actor_file_path(name)

Finds the first matching file path within files_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.get_actor_folder_path(name)

Finds the first matching folder path within files_paths.

Parameters:name (str) – Name of the folder
Returns:Found folder path
Return type:str or None
leapp.libraries.stdlib.api.get_actor_tool_path(name)

Finds the first matching executable file path within actor_tools_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.get_answers(dialog)

Get the answers for a dialog from answerfile. The dialog needs be predefined in dialogs of the actor.

Parameters:dialog – Dialog instance to show
Returns:dictionary with the requested answers, None if not a defined dialog
leapp.libraries.stdlib.api.get_common_file_path(name)

Finds the first matching file path within files_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.get_common_folder_path(name)

Finds the first matching folder path within files_paths.

Parameters:name (str) – Name of the folder
Returns:Found folder path
Return type:str or None
leapp.libraries.stdlib.api.get_common_tool_path(name)

Finds the first matching executable file path within common_tools_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.get_file_path(name)

Finds the first matching file path within files_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.get_folder_path(name)

Finds the first matching folder path within files_paths.

Parameters:name (str) – Name of the folder
Returns:Found folder path
Return type:str or None
leapp.libraries.stdlib.api.get_tool_path(name)

Finds the first matching executable file path within tools_paths.

Parameters:name (str) – Name of the file
Returns:Found file path
Return type:str or None
leapp.libraries.stdlib.api.produce(*model_instances)

By calling produce, model instances are stored as messages. Those messages can be then consumed by other actors.

Parameters:model_instances (Variable number of instances of derived classes from leapp.models.Model) – Messages to be sent (those model types have to be specified in produces
leapp.libraries.stdlib.api.report_error(message, severity='error', details=None)

Reports an execution error

Parameters:
  • message (str) – A message to print the possible error
  • severity (str with defined values from leapp.messaging.errors.ErrorSeverity.ERROR) – Severity of the error default leapp.messaging.errors.ErrorSeverity.ERROR
  • details (dict) – A dictionary where additional context information is passed along with the error
Returns:

None

leapp.libraries.stdlib.api.show_message(message)

Display a message in user interterface currently in use (CLI, GUI).

It uses one of the dialog renderers in leapp.dialogs.renderer.

Parameters:message (str) – Message to show
leapp.libraries.stdlib.api.tools_paths()

Returns all actor tools paths related to the actor and common actors tools paths.