%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/__pycache__/event_logger.cpython-312.pyc

�

!V1fA ���dZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlmZdZ
ee
eeeeffZdad�Zej$Gd�dej&��Zd	eeefd
eeeffd�ZGd�d
�Zy)a$
This module is responsible for handling all events
that must be raised to the user somehow. The main idea
behind this module is to centralize all events that happens
during the execution of Pro commands and allows us to report
those events in real time or through a machine-readable format.
�N)�Any�Dict�List�Optional�Set�Union)�	safe_dumpz0.1c�.�t�
t�atS�N)�
_event_logger�EventLogger���7/usr/lib/python3/dist-packages/uaclient/event_logger.py�get_event_loggerrs����#�
�
��rc�:�eZdZdZe�Ze�Ze�Zy)�EventLoggerModea
    Defines event logger supported modes.
    Currently, we only support the cli and machine-readable mode. On cli mode,
    we will print to stdout/stderr any event that we receive. Otherwise, we
    will store those events and parse them for the specified format.
    N)�__name__�
__module__�__qualname__�__doc__�object�CLI�JSON�YAMLrrrrrs����(�C��8�D��8�Drr�status�returnc�.�ddlm}t|�j��D��cgc]
\}}||d���c}}|d<|j	dd�|jdg�|j
dg�D]}d|vs�|j	d��|Scc}}w)	Nr)�get_pro_environment)�name�value�environment_vars�origin��services�variants)�
uaclient.utilr�sorted�items�pop�
setdefault�get)rrr r!�services     r�format_machine_readable_outputr.,s���1�"�"5�"7�"=�"=�"?�@�"��D�%���&�"�F����J�J�x������j�"�%�
�:�:�j�"�-�$���� ��K�K�
�#�$��M��'"s�Bc�^�eZdZd�Zd�Zdefd�Zdefd�Zde	fd�Z
d$d
edeefd�Z			d%d
edeede
e	eefdeedeedee	eeffd�Z				d&dedeedeedeedee	eeff
d�Zd'dedeefd�Zdefd�Zde
efd�Zdefd�Zdefd�Zd �Zd!�Zd"�Zd(d#�Zy	))r
c��g|_g|_t�|_t�|_d|_d|_i|_tj|_
y)NFr$��
_error_events�_warning_events�set�_processed_services�_failed_services�
_needs_reboot�_command�_output_contentrr�_event_logger_mode��selfs r�__init__zEventLogger.__init__FsM�����!���#&�5�� � #����"�����
�!���#2�"5�"5��rc��g|_g|_t�|_t�|_d|_d|_i|_tj|_
y)z/Reset the state of the event logger attributes.Fr$Nr1r;s r�resetzEventLogger.resetSsK�����!���#&�5�� � #����"�����
�!���"1�"5�"5��r�
event_modec��||_y)z_Set the event logger mode.

        We currently support the CLI, JSON and YAML modes.
        N)r:)r<r@s  r�set_event_modezEventLogger.set_event_mode^s��
#-��r�commandc��||_y)z�Set the event logger command.

        The command will tell the process_events method which output method
        to use.
        N)r8)r<rCs  r�set_commandzEventLogger.set_commandes�� ��
r�output_contentc��||_y)z�Set the event logger output content.

        The command will tell the process_events method which content
        to use.
        N)r9)r<rFs  r�set_output_contentzEventLogger.set_output_contentms�� .��rN�info_msg�endc��|stj}|jtjk(rt|||��yy)zL
        Print the info message if the event logger is on CLI mode.
        )�filerJN)�sys�stdoutr:rr�print)r<rI�	file_typerJs    r�infozEventLogger.infous5����
�
�I��"�"�o�&9�&9�9��(���4�:r�msgr-�
event_dict�code�
event_type�additional_infoc�R�|�|rdnd}||||d�}|r||d<|j|�y)Nr-�system)�typer-�message�message_coderV)�append)r<rRr-rSrTrUrV�event_entrys        r�_record_dict_eventzEventLogger._record_dict_eventsF����&-��8�J���� �	
���-<�K�)�*����+�&r�	error_msg�
error_code�
error_typec��|jtjk7r"|j|||j|||��yy)z�
        Store an error in the event logger.

        However, the error will only be stored if the event logger
        is not on CLI mode.
        )rRr-rSrTrUrVN)r:rrr^r2)r<r_r`r-rarVs      r�errorzEventLogger.error�sH���"�"�o�&9�&9�9��#�#����-�-��%� /�

$�
�:r�warning_msgc�|�|jtjk7r|j|||j��yy)z�
        Store a warning in the event logger.

        However, the warning will only be stored if the event logger
        is not on CLI mode.
        )rRr-rSN)r:rrr^r3)r<rdr-s   r�warningzEventLogger.warning�s?���"�"�o�&9�&9�9��#�#����/�/�
$�
�:rc�:�|jj|�yr)r5�add�r<r-s  r�service_processedzEventLogger.service_processed�s��� � �$�$�W�-rr%c�:�|jj|�yr)r6�update)r<r%s  r�services_failedzEventLogger.services_failed�s�����$�$�X�.rc�:�|jj|�yr)r6rhris  r�service_failedzEventLogger.service_failed�s�����!�!�'�*r�reboot_requiredc��||_yr)r7)r<rps  r�needs_rebootzEventLogger.needs_reboot�s
��,��rc��|jD�chc]}|dr|d��}}ttj|j|��Scc}w)Nr-)r2�listr4�unionr6)r<rc�services_with_errors   r�_generate_failed_servicesz%EventLogger._generate_failed_services�sY���+�+�
���Y��
�)��
��
�
�C�I�I�d�3�3�5H�I�J�J��
s�Ac��t|jsdndt|j�t|j	��|j|j
|jd�}ddlm}ttj||d���y)N�success�failure)�_schema_version�result�processed_services�failed_services�errors�warningsrrr��DatetimeAwareJSONEncoderT��cls�	sort_keys)�JSON_SCHEMA_VERSIONr2r(r5rwr3r7r'r�rO�json�dumps)r<�responser�s   r�_process_events_servicesz$EventLogger._process_events_services�sq��2�'+�'9�'9�i�y�"(��)A�)A�"B�%�d�&D�&D�&F�G��(�(��,�,� �.�.�
��	;�
��J�J�x�%=��N�	
rc��t|j�}|jsdnd|d<|j|d<|j|d<|jt
jk(r(ddlm}ttj||d�	��y|jt
jk(rtt|d
���yy)Nryrzr|rr�rr�Tr�F)�default_flow_style)r.r9r2r3r:rrr'r�rOr�r�rr	)r<�outputr�s   r�_process_events_statusz"EventLogger._process_events_status�s���/��0D�0D�E��,0�,>�,>�9�I��x���-�-��x��!�1�1��z���"�"�o�&:�&:�:�>���
�
�� 8�D��
�
�
$�
$��(<�(<�
<��)�F�u�=�>�=rc��|jtjk7r1|jdk(r|j	�y|j�yy)z�
        Creates a json response based on all of the
        events stored in the event logger.

        The json response will only be created if the event logger
        is not on CLI mode.
        rN)r:rrr8r�r�r;s r�process_eventszEventLogger.process_events�sA���"�"�o�&9�&9�9��}�}��(��+�+�-��-�-�/�	:r)NN)NNN)NNNNr)rN)rrrr=r?rrB�strrErrHrrQr�EventFieldErrorTyper^rcrfrjrmro�boolrrrwr�r�r�rrrr
r
Esv��6�	6�-��-� �3� �.��.�5�S�5�x��}�5�#�$(�48�'�
�'��#��'���c�#6�6�7�8�	'�
�s�m�'��S�M�
'�"�$�s�C�x�.�1�'�6%)�!%�$(�48�
����S�M���#��	�
�S�M��"�$�s�C�x�.�1�
�0�3���#���.��.�/��S�	�/�+�c�+�-�D�-�K�
�"?�"0rr
)r�enumr�rM�typingrrrrrr�
uaclient.yamlr	r�r�r�rr�unique�Enumrr.r
rrr�<module>r�s������
�8�8�#����u�S�$�s�C�x�.�%8�9�:���
�����
�d�i�i�
�
�
��4��S��>��d�3��8�n��2z0�z0r

Zerion Mini Shell 1.0