leapp.utils package
Subpackages
- leapp.utils.audit package
- Module contents
ActorConfigActorConfigDataAuditDataSourceDialogEntityExecutionHostMessageMessageDataMetadataStorablecheckpoint()create_audit_entry()create_connection()dict_factory()get_audit_entry()get_checkpoints()get_connection()get_errors()get_messages()store_actor_metadata()store_dialog()store_workflow_metadata()
- Module contents
Submodules
leapp.utils.actorapi module
- exception leapp.utils.actorapi.RequestException(*args: Any, **kwargs: Any)
Bases:
OSErrorThere was an ambiguous exception that occurred while handling your request.
Initialize RequestException with request and response objects.
- request: Request | PreparedRequest | None
- response: Response | None
- leapp.utils.actorapi.get_actor_api()
- Returns:
An instance of the Leapp actor API session that is using
requests.Sessionover a UNIX domain socket
leapp.utils.clicmd module
- class leapp.utils.clicmd.Command(name, target=None, help='', description=None)
Bases:
objectCommand implements a convenient command-based argument parsing the framework.
- Parameters:
name (str) – Name of the sub command
target (Callable) – Function called when the command is invoked
help (str) – Shows a help message
description (str) – Extended description of the command (the default is help)
- add_argument(name, value_type=None, help='', wrapped=None)
- Parameters:
name –
value_type –
help –
wrapped –
- Returns:
- add_option(name, short_name='', help='', is_flag=False, inherit=False, value_type=<class 'str'>, wrapped=None, action=None, metavar=None, choices=None, default=None, aliases=None, dest=None)
Add an option
- Parameters:
name (str) – Name of the option
short_name (str) – Short name of the option (one letter)
help (str) – Help string for the option
is_flag (bool) – Decides if it is a flag
inherit (bool) – Decides if this option should be inherited by sub commands
value_type – Type of the value by default string
wrapped (Callable) – Function that is wrapped (aka the target)
action (str) – ArgumentParser actions to take (e.g. store)
metavar (str) – Changes the display name of arguments in generated help messages. It has no influence on the attribute name from the generated arguments namespace.
choices (list) – range of values that the argument is allowed to take
default (any) – default value of the argument if nothing is specified
aliases (list[str]) – Aliases for the option, appended after short_name and name in help output
dest (str) – The name of the attribute to be added to the parsed args object
- Returns:
self
- add_sub(cmd)
Adds a sub command to this command
- Parameters:
cmd (
leapp.utils.clicmd.Command) – The sub command object- Returns:
self
- apply_parser(sparser, parent=None, parser=None)
- Parameters:
sparser (_SubParserActionOverride) – ArgumentParser.add_subparsers
parent (_Command) – Instance of
_Commandparser (argparse.ArgumentParser) – ArgumentParser instance usually received from sparser.add_parser
- Returns:
None
- called(args)
The actual call is dispatched through this method. It ensures that the parent is also called to allow generic handling of some flags (especially inherited flags).
- Parameters:
args (
argparse.Namespace) – Arguments object that is a result of the argparse commandline parser- Returns:
None
- execute(version)
Entry point to the command execution. It is used for the main entry function of an application.
- Parameters:
version (str) – Version string to display for –version calls
- Returns:
None
- get_inheritable_options()
- Returns:
Returns all options that are marked as ‘inherit’
- leapp.utils.clicmd.command(name, help='', description=None, parent=None)
Decorator to mark a function as a sub command
- Parameters:
name (str) – Sub command name
help (str) – Help string for the sub command
description (str) – Extended description for the sub command defaults to help if it is not set
parent (Command) – Instance to the parent command if it is a sub-command
- leapp.utils.clicmd.command_arg(name, value_type=None, help='')
Decorator wrapping functions to add command line arguments to the sub command to be invoked
- Parameters:
name – Name of the argument
value_type – Type of the argument
help – Help string for the argument
- leapp.utils.clicmd.command_aware_wraps(f)
Decorator passing the command attribute of the wrapped function to the wrapper
This needs to be used by decorators that are trying to wrap clicmd decorated command functions.
- leapp.utils.clicmd.command_opt(name, **kwargs)
Decorator wrapping functions to add command line options to the sub command to be invoked
- Parameters:
name – Name of the option
kwargs – parameters as specified in
leapp.utils.clicmd.Command.add_option()
leapp.utils.meta module
- leapp.utils.meta.get_flattened_subclasses(cls)
Returns all the given subclasses and their subclasses recursively for the given class :param cls: Class to check :type cls: Type :return: Flattened list of subclasses and their subclasses
- leapp.utils.meta.with_metaclass(meta_class, base_class=<class 'object'>)
- Parameters:
meta_class – The desired metaclass to use
base_class (Type) – The desired base class to use, the default one is object
- Returns:
Metaclass type to inherit from
- Example:
class MyMetaClass(type): def __new__(mcs, name, bases, attrs): klass = super(MyMetaClass, mcs).__new__(mcs, name, bases, attrs) klass.added = "Added field" return klass class MyClass(with_metaclass(MyMetaClass)): pass # This is equivalent to python 2: class MyClass(object): __metaclass__ = MyMetaClass # Or python 3 class MyClass(object, metaclass=MyMetaClass): pass
leapp.utils.repository module
- leapp.utils.repository.add_repository_link(path, repo_id)
Add a link from another repository to the current repository.
- Parameters:
path – Path within the leapp repository to modify
repo_id – UUIDv4 string identifier for the repository to link
repo_id – str
- Returns:
None
- leapp.utils.repository.find_repos(path)
Finds repositories within the given path.
- Parameters:
path – Path to search for repositories.
- Returns:
List of strings with found repository paths.
- leapp.utils.repository.find_repository_basedir(path)
Tries to find the .leapp directory recursively ascending until it hits the root directory
- Parameters:
path – Path to start from (can be relative)
- Returns:
None if the base directory was not found, otherwise the absolute path to the base directory
- leapp.utils.repository.get_global_repositories_data()
Returns the data of all system wide available repositories.
- Returns:
Repository information
- leapp.utils.repository.get_repository_id(path)
Retrieves the repository name from the repository metadata from within the given path. (it can be anywhere within the repository it will use
find_repository_dir()to find the repository base directory) :param path: Path within the leapp repository :return: ID of the repository :raises: KeyError if no name was found (e.g. not a valid repository path)
- leapp.utils.repository.get_repository_links(path)
Retrieves a list of repository ids that are linked to given repository.
- Parameters:
path – Path within the leapp repository
- Returns:
List of repository ids this repository is linked to
- leapp.utils.repository.get_repository_metadata(path)
Gets the parsed metadata file as a dictionary
- Parameters:
path – Path to start loading the metadata from (it can be anywhere within the repository it will use
find_repository_dir()to find the repository base directory)- Returns:
Dictionary with the metadata or an empty dictionary
- leapp.utils.repository.get_repository_name(path)
Retrieves the repository name from the repository metadata from within the given path. (it can be anywhere within the repository it will use
find_repositoryt_dir()to find the repository base directory) :param path: Path within the leapp repository :return: Name of the repository :raises: KeyError if no name was found (e.g. not a valid repository path)
- leapp.utils.repository.get_user_config_path()
Returns the path to the user configuration directory and creates it if it does not exist already.
- Returns:
Path to the configuration directory of leapp.
- leapp.utils.repository.get_user_config_repo_data()
Returns the user config repository data.
- Returns:
Data for user configurations.
- leapp.utils.repository.get_user_config_repos()
Returns the path to the user config file for repositories.
- Returns:
Path to the repos.json configuration file.
- leapp.utils.repository.make_class_name(name)
Converts a snake_case_name to an UpperCaseName
- Parameters:
name – Name to convert
- Returns:
Converted class name
- leapp.utils.repository.make_name(name)
Converts a given name to a lower snake case
- Parameters:
name – Name to convert
- Returns:
Lower snake case
- leapp.utils.repository.requires_repository(f)
Decorator for snactor commands that require to be run in a repository directory.
- leapp.utils.repository.to_snake_case(name)
Converts an UpperCaseName to a snake_case_name
- Parameters:
name – Name to convert
- Returns:
converted snake case name
Module contents
- leapp.utils.get_api_models(actor, what)
Used to retrieve the full list of models including the ones defined by WorkflowAPIs used by the actor.
- Parameters:
what (str) – A string which either is ‘consumes’ or ‘produces’
actor (leapp.actors.Actor or ActorDefinition) – type/instance or ActorDefinition instance to retrieve the information from
- Returns:
Tuple of all produced or consumed models as specified by actor and APIs used by the actor.
- leapp.utils.reboot_system()