HEX
Server: LiteSpeed
System: Linux oxygen.shetabanhost.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: rasapedi (1695)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/leapp/actors/__pycache__/__init__.cpython-36.pyc
3

�S4b�H�@sddlZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZddlmZmZdd	lmZdd
lmZddlmZGdd
�d
e�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&d$dd�Z'd d!�Z(d"d#�Z)dS)%�N)�string_types)�Dialog)�MissingActorAttributeError�RequestStopAfterPhase�StopActorExecution�StopActorExecutionError�WorkflowConfigNotAvailable�WrongAttributeTypeError)�DialogModel�Model)�
ErrorSeverity)�Tag)�get_api_models�path)�install_translation_for_actor)�get_flattened_subclasses)�WorkflowAPIc@s&eZdZdZdZeZdZdZfZfZ	fZ
fZfZdZ
dd�Zd6dd�Zdd	�Zd
d�Zedd
��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z d(d)�Z!d*d+�Z"d,d-�Z#d.d/�Z$d0d1�Z%d2d3�Z&ej'dfd4d5�Z(dS)7�Actorz�
    The Actor class represents the smallest step in the workflow. It defines what kind
    of data it expects, it consumes (processes) the given data, and it produces data for other
    actors in the workflow.
    Nc	Csp|jtjjtjt|�jj�t|�j	|j
p2t|�jdd�|jD�dd�|j
D�dd�|jD�dd�|jD�d�S)z?
        :return: Serialized information for the actor
        cSsg|]
}|j�qS�)�__name__)�.0�crr�,/root/tmp_leapp_py3/leapp/actors/__init__.py�
<listcomp>Xsz#Actor.serialize.<locals>.<listcomp>cSsg|]
}|j�qSr)r)r�prrrrYscSsg|]
}|j�qSr)r)r�trrrrZscSsg|]}|j��qSr)�	serialize)r�drrrr[s)�namer�
class_name�description�consumes�produces�tags�dialogs)r�osr�dirname�sys�modules�type�
__module__�__file__rr �__doc__r!r"r#r$)�selfrrrrOszActor.serializeFcCspd|_|t_tt|��||_|p*tjd�j|j	�|_
||_|rRt|j
|�d�|_t|_tt|�d�t|�_dS)Nzleapp.actorsr")�_configurationr�current_instancerr)�
_messaging�logging�	getLogger�getChildr�log�skip_dialogs�next�consumer�_pathrr")r-Z	messaging�loggerZconfig_modelr5rrr�__init__^szActor.__init__cCs>|jj||�|t|�jkr:|jr.|jj|�S|jj|�SdS)z�
        Gets the answers for a dialog. The dialog needs be predefined in :py:attr:`dialogs`.

        :param dialog: Dialog instance to show
        :return: dictionary with the requested answers, None if not a defined dialog
        N)r0Zregister_dialogr)r$r5�get_answersZrequest_answers)r-�dialogrrrr;uszActor.get_answerscCs|jj|�dS)z�
        Display a message in user interterface currently in use (CLI, GUI).

        It uses one of the dialog renderers in :py:mod:`leapp.dialogs.renderer`.

        :param message: Message to show
        :type message: str
        N)r0�show_message)r-�messagerrrr=�s	zActor.show_messagecCs|jst|j��|jS)z]
        Returns the config model generated by specific workflow configuration actor
        )r.rr)r-rrr�
configuration�s
zActor.configurationcCstjdd�jd�S)z~
        Returns the file paths that are bundled with the actor. (Path to the content of the actor's file directory).
        ZLEAPP_FILES��:)r%�getenv�split)r-rrr�actor_files_paths�szActor.actor_files_pathscCs|j|jS)zQ Returns all actor file paths related to the actor and common actors file paths. )rD�common_files_paths)r-rrr�files_paths�szActor.files_pathscCstjdd�jd�S)z+ Returns all common repository file paths. ZLEAPP_COMMON_FILESr@rA)r%rBrC)r-rrrrE�szActor.common_files_pathscCstjdd�jd�S)z
        Returns the tool paths that are bundled with the actor. (Path to the content of the actor's tools directory).
        ZLEAPP_TOOLSr@rA)r%rBrC)r-rrr�actor_tools_paths�szActor.actor_tools_pathscCstjdd�jd�S)z+ Returns all common repository tool paths. ZLEAPP_COMMON_TOOLSr@rA)r%rBrC)r-rrr�common_tools_paths�szActor.common_tools_pathscCs|j|jS)zS Returns all actor tools paths related to the actor and common actors tools paths. )rGrH)r-rrr�tools_paths�szActor.tools_pathscCs|jj|j|�S)z�
        Finds the first matching folder path within :py:attr:`files_paths`.

        :param name: Name of the folder
        :type name: str
        :return: Found folder path
        :rtype: str or None
        )r8�get_folder_pathrF)r-rrrrrJ�s	zActor.get_folder_pathcCs|jj|j|�S)z�
        Finds the first matching folder path within :py:attr:`common_files_paths`.

        :param name: Name of the folder
        :type name: str
        :return: Found folder path
        :rtype: str or None
        )r8rJrE)r-rrrr�get_common_folder_path�s	zActor.get_common_folder_pathcCs|jj|j|�S)z�
        Finds the first matching folder path within :py:attr:`actor_files_paths`.

        :param name: Name of the folder
        :type name: str
        :return: Found folder path
        :rtype: str or None
        )r8rJrD)r-rrrr�get_actor_folder_path�s	zActor.get_actor_folder_pathcCs|jj|j|�S)z�
        Finds the first matching file path within :py:attr:`files_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8�
get_file_pathrF)r-rrrrrM�s	zActor.get_file_pathcCs|jj|j|�S)z�
        Finds the first matching file path within :py:attr:`common_files_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8rMrE)r-rrrr�get_common_file_path�s	zActor.get_common_file_pathcCs|jj|j|�S)z�
        Finds the first matching file path within :py:attr:`actor_files_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8rMrD)r-rrrr�get_actor_file_path�s	zActor.get_actor_file_pathcCs|jj|j|�S)z�
        Finds the first matching executable file path within :py:attr:`tools_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8�
get_tool_pathrI)r-rrrrrP�s	zActor.get_tool_pathcCs|jj|j|�S)z�
        Finds the first matching executable file path within :py:attr:`common_tools_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8rPrH)r-rrrr�get_common_tool_paths	zActor.get_common_tool_pathcCs|jj|j|�S)z�
        Finds the first matching executable file path within :py:attr:`actor_tools_paths`.

        :param name: Name of the file
        :type name: str
        :return: Found file path
        :rtype: str or None
        )r8rPrG)r-rrrr�get_actor_tool_paths	zActor.get_actor_tool_pathcGs�|jtjd<zxy|j|�Wndtk
r0YnRtk
rd}z|j|j|j|j	�WYdd}~Xnt
k
r�|jj�YnXWdtjj
dd�XdS)z7 Runs the actor calling the method :py:func:`process`. �LEAPP_CURRENT_ACTORN)rr%�environ�processrr�report_errorr>�severity�detailsrr0Zrequest_stop_after_phase�pop)r-�args�errrrr�runs$z	Actor.runcOs
t��dS)zj Main processing method. In inherited actors, the function needs to be defined to be able to be processed.N)�NotImplementedError)r-rZ�kwargsrrrrU,sz
Actor.processcGsN|jrJxB|D]:}t|t|�j�r0|jj||�q|jjdjt|���qWdS)aN
        By calling produce, model instances are stored as messages. Those messages can be then consumed by other actors.

        :param models: Messages to be sent (those model types have to be specified in :py:attr:`produces`
        :type models: Variable number of the derived classes from :py:class:`leapp.models.Model`
        z�Actor is trying to produce a message of type "{}" without mentioning it explicitely in the actor's "produces" tuple. The message will be ignoredN)r0�
isinstancer)r"�producer4�warning�format)r-�models�modelrrrr`0s

z
Actor.producecGs|jr|jj|f|��SfS)a�
        Retrieve messages specified in the actors :py:attr:`consumes` attribute, and filter message types by
        models.

        :param models: Models to use as a filter for the messages to return
        :type models: Variable number of the derived classes from :py:class:`leapp.models.Model`
        :return: All messages of the specified model(s) produced by other actors
        :rtype: Iterable with messages or an empty tuple
        )r0r7)r-rcrrrr7@s
z
Actor.consumecCs<|jr8tj|�s$|jjd|�tj}|jj||||d�dS)a�
        Reports an execution error

        :param message: A message to print the possible error
        :type message: str
        :param severity: Severity of the error default :py:attr:`leapp.messaging.errors.ErrorSeverity.ERROR`
        :type severity: str with defined values from :py:attr:`leapp.messaging.errors.ErrorSeverity.ERROR`
        :param details: A dictionary where additional context information is passed along with the error
        :type details: dict
        :return: None
        zJreport_error: Unknown severity value %s was passed - Falling back to ERROR)r>rW�actorrXN)r0r�validater4ra�ERRORrV)r-r>rWrXrrrrVNs
zActor.report_error)NNNF))rr*�__qualname__r,r/rrr r!r"r#r$�apisZtext_domainrr:r;r=�propertyr?rDrFrErGrHrIrJrKrLrMrNrOrPrQrRr\rUr`r7rgrVrrrrrsH
	rcs�fdd�}|S)Ncs t|��stdj||����|S)Nz.Actor {} attribute {} should be of the type {})r_r	rb)rer�value)�
value_typerrrffs

z_is_type.<locals>.validater)rlrfr)rlr�_is_typeesrmcs�fdd�}|S)NcsRtt�|||�|s&tdj||����t�fdd�|D��sNtdj||����|S)NzEActor {} attribute {} should contain at least one item of the type {}csg|]}t|���qSr)r_)r�item)rlrrrtsz2_is_tuple_of.<locals>.validate.<locals>.<listcomp>z?Actor {} attribute {} should contain only values of the type {})rm�tupler	rb�all)rerrk)rlrrrfosz_is_tuple_of.<locals>.validater)rlrfr)rlr�_is_tuple_ofns	rqcCsLt|di�}|j|d�sHd||d<t|d|�tjd�jd|||�dS)N�	_warnings�_tupleTzleapp.linterz)Actor %s field %s should be a tuple of %s)�getattr�get�setattrr1r2ra)rer�	type_name�warningsrrr�
_lint_warn{s
rycCsbt|t�r&t|t�r&t||d�|f}tt�|||�tdgdd�|D��s^tdj	||���|S)NZModelsTcSs g|]}t|t�ot|t��qSr)r_r)�
issubclassr)rrnrrrr�sz#_is_model_tuple.<locals>.<listcomp>z0Actor {} attribute {} should contain only Models)
r_r)rzrryrmrorpr	rb)rerrkrrr�_is_model_tuple�sr{cCsXt|t�rt||d�|f}tt�|||�tdgdd�|D��sTtdj||���|S)NZDialogsTcSsg|]}t|t��qSr)r_r)rrnrrrr�sz$_is_dialog_tuple.<locals>.<listcomp>z1Actor {} attribute {} should contain only Dialogs)r_rryrmrorpr	rb)rerrkrrr�_is_dialog_tuple�s
r|cCsbt|t�r&t|t�r&t||d�|f}tt�|||�tdgdd�|D��s^tdj	||���|S)NZTagsTcSs g|]}t|t�ot|t��qSr)r_r)rzr
)rrnrrrr�sz!_is_tag_tuple.<locals>.<listcomp>z.Actor {} attribute {} should contain only Tags)
r_r)rzr
ryrmrorpr	rb)rerrkrrr�
_is_tag_tuple�sr}cCsbt|t�r&t|t�r&t||d�|f}tt�|||�tdgdd�|D��s^tdj	||���|S)NZApisTcSs g|]}t|t�ot|t��qSr)r_r)rzr)rrnrrrr�sz!_is_api_tuple.<locals>.<listcomp>z6Actor {} attribute {} should contain only WorkflowAPIs)
r_r)rzrryrmrorpr	rb)rerrkrrr�
_is_api_tuple�sr~Fr@cCsf|r|||�}nt||d�}|r8|r8tdj|||���|s@|rL||||�}|r^|dk	r^|}||fS)Nz#Actor {} is missing attribute {}.{})rtrrb)rerZ	validator�required�
default_value�additional_info�resolverkrrr�_get_attribute�s
r�cCs�d}td|jfdtjjtjjtj|jj	��ft
|dtt�dd�t
|dt
d|d�t
|d	td
ftd�t
|dtd
ftd�t
|d
td
fd�t
|dtt�d
|jp�dd�t
|dtd
fd�g	�S)a
    Creates Actor's metadata dictionary

    :param actor: Actor whose metadata are needed
    :type actor: derived class from :py:class:`leapp.actors.Actor`
    :return: Dictionary with the name, tags, consumes, produces, and description of the actor
    zD At least one tag is required for actors. Please fill the tags fieldrrrT)rr#)rr�r!F)rr�r�r"r$)rr�r z6There has been no description provided for this actor.ri)�dictrr%rr&�realpathr'r(r*r+r�rmrr}r{rr|r,r~)reZadditional_tag_inforrr�get_actor_metadata�s r�cCs"tt�}x|D]}t|�qW|S)z<
    :return: All registered actors with their metadata
    )rrr�)Zactorsrerrr�
get_actors�s
r�)FNr@N)*r1r%r'�leapp.compatrZ
leapp.dialogsr�leapp.exceptionsrrrrrr	�leapp.modelsr
r�leapp.models.error_severityrZ
leapp.tagsr
Zleapp.utilsrrZleapp.utils.i18nr�leapp.utils.metarZleapp.workflows.apir�objectrrmrqryr{r|r}r~r�r�r�rrrr�<module>s2 U