HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/cloudinit/reporting/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/reporting/__pycache__/events.cpython-312.pyc
�

�f�#����dZddlZddlZddlZddlmZddlmZm	Z	ddl
mZdZdZ
dZGd	�d
e�Zed�ZGd�d
�ZGd�de�Zdd�Zej*dfd�Zd�ZGd�d�Zd�Zy)z�
events for reporting.

The events here are designed to be used with reporting.
They can be published to registered handlers with report_event.
�N)�List)�available_handlers�instantiated_handler_registry)�ReportingHandler�finish�start�	cloudinitc��eZdZd�Zy)�_namesetc�*�||vr|Std|z��)Nz%s not a valid value)�AttributeError)�self�names  �</usr/lib/python3/dist-packages/cloudinit/reporting/events.py�__getattr__z_nameset.__getattr__s���4�<��K��3�d�:�;�;�N)�__name__�
__module__�__qualname__r�rrrrs��<rr)�SUCCESS�WARN�FAILc�(�eZdZdZedfd�Zd�Zd�Zy)�ReportingEventz"Encapsulation of event formatting.Nc�v�||_||_||_||_|�t	j�}||_y�N)�
event_typer�description�origin�time�	timestamp)rrrrr r"s      r�__init__zReportingEvent.__init__)s9��%�����	�&���������	�	��I�"��rc�d�dj|j|j|j�S)z"The event represented as a string.z
{0}: {1}: {2})�formatrrr�rs r�	as_stringzReportingEvent.as_string9s*���%�%��O�O�T�Y�Y��(8�(8�
�	
rc�v�|j|j|j|j|jd�S)z&The event represented as a dictionary.�rrrr r"r)r&s r�as_dictzReportingEvent.as_dict?s3���I�I��+�+��/�/��k�k����
�	
r)rrr�__doc__�DEFAULT_EVENT_ORIGINr#r'r*rrrrr&s��,�$��
#� 
�
rrc�H��eZdZejdf�fd�	Zd�Z�fd�Z�xZS)�FinishReportingEventNc���tt|�t||�||_|�g}||_|tvrtd|z��y)NzInvalid result: %s)�superr.r#�FINISH_EVENT_TYPE�result�
post_files�status�
ValueError)rrrr2r3�	__class__s     �rr#zFinishReportingEvent.__init__KsU���	�"�D�2��t�[�	
�������J�$�������1�F�:�;�;� rc�z�dj|j|j|j|j�S)Nz{0}: {1}: {2}: {3})r%rrr2rr&s rr'zFinishReportingEvent.as_stringXs0��#�*�*��O�O�T�Y�Y����T�5E�5E�
�	
rc���tt|��}|j|d<|jrt|j�|d<|S)z'The event represented as json friendly.r2�files)r0r.r*r2r3�_collect_file_info)r�datar6s  �rr*zFinishReportingEvent.as_dict]s>����)�4�8�:������X���?�?�.�t���?�D��M��r)	rrrr4rr#r'r*�
__classcell__)r6s@rr.r.Js ���(.���4�<�
�
�rr.c��|si}tjj�D��chc]\}}||vr|��
}}}ttjj��}|D]!}t
|�|vr�|j|��#ycc}}w)a�Report an event to all registered event handlers
    except those whose type is in excluded_handler_types.

    This should generally be called via one of the other functions in
    the reporting module.

    :param excluded_handler_types:
         List of handlers types to exclude from reporting the event to.
    :param event_type:
        The type of the event; this should be a constant from the
        reporting module.
    N)r�registered_items�items�listr�values�type�
publish_event)�event�excluded_handler_types�	hndl_type�hndl_cls�excluded_handler_classes�handlers�handlers       r�report_eventrKfs���"�!#��$6�#F�#F�#L�#L�#N� ��I�x��.�.�	� �� �(,�%�6�6�=�=�?�(�H��%����=�4�4�����e�$�%�� s�Bc�6�t||||��}t|�S)zVReport a "finish" event.

    See :py:func:`.report_event` for parameter details.
    �r3)r.rK)�
event_name�event_descriptionr2r3rDs     r�report_finish_eventrP�s%��
!��%�v�*�
�E����rc�:�tt||�}t|�S)a'Report a "start" event.

    :param event_name:
        The name of the event; this should be a topic which events would
        share (e.g. it will be the same for start and finish events).

    :param event_description:
        A human-readable description of the event that has occurred.
    )r�START_EVENT_TYPErK)rNrOrDs   r�report_start_eventrS�s��
�+�Z�9J�K�E����rc��eZdZdZdddej
dfd�Zd�Zd�Zd�Z	e
d��Zejd��Ze
d	��Z
e
jd
��Z
d�Zd�Zy)
�ReportEventStackaKContext Manager for using :py:func:`report_event`

    This enables calling :py:func:`report_start_event` and
    :py:func:`report_finish_event` through a context manager.

    :param name:
        the name of the event

    :param description:
        the event's description, passed on to :py:func:`report_start_event`

    :param message:
        the description to use for the finish event. defaults to
        :param:description.

    :param parent:
    :type parent: :py:class:ReportEventStack or None
        The parent of this event.  The parent is populated with
        results of all its children.  The name used in reporting
        is <parent.name>/<name>

    :param reporting_enabled:
        Indicates if reporting events should be generated.
        If not provided, defaults to the parent's value, or True if no parent
        is provided.

    :param result_on_exception:
        The result value to set if an exception is caught. default
        value is FAIL.

    :param post_files:
        Can hold filepaths of files that are to get posted/created
        regarding a given event. Something like success or failure information
        in a given log file. For each filepath, if it's a valid regular file
        it will get: read & encoded as base64 at the close of the event.
        Default value, if None, is an empty list.
    Nc�F�||_||_||_||_||_t
j|_|�g}||_|�|r
|j}nd}||_	|r*dj|j|f�|_i|_y|j|_i|_y)NT�/)
�parentrr�message�result_on_exceptionr4rr2r3�reporting_enabled�join�fullname�children)rrrrYrXr[rZr3s        rr#zReportEventStack.__init__�s��������	�&������#6�� ��n�n������J�$����$��$*�$<�$<�!�$(�!�!2�����H�H��O�O����D�M���
�!�I�I�D�M���
rc�V�d|j�d|j�d|j�d�S)NzReportEventStack(z, z, reporting_enabled=�))rrr[r&s r�__repr__zReportEventStack.__repr__�s%���I�I�����"�"�
�	
rc���tj|_|jr t	|j
|j�|jr#d|jj|j<|S)N)NN)
r4rr2r[rSr]rrXr^rr&s r�	__enter__zReportEventStack.__enter__�sN���n�n����!�!��t�}�}�d�.>�.>�?��;�;�.:�D�K�K� � ����+��rc���tjtjfD]>}|jj	�D]\}\}}||k(s�||j
fccS�@|j|j
fSr)r4rrr^r?rYr2)r�cand_result�_name�value�_msgs     r�_childrens_finish_infoz'ReportEventStack._childrens_finish_info�so��"�K�K����5�	1�K�(,�
�
�(;�(;�(=�
1�$��}��t��K�'�!�4�<�<�0�0�
1�	1����T�\�\�*�*rc��|jSr)�_resultr&s rr2zReportEventStack.results���|�|�rc�>�|tvrtd|z��||_y)Nz'%s' not a valid result)r4r5rk�rrgs  rr2zReportEventStack.results"������6��>�?�?���rc�J�|j�|jS|jSr)�_messagerr&s rrYzReportEventStack.messages"���=�=�$��=�=� ����rc��||_yr)rorms  rrYzReportEventStack.messages	����
rc�V�|r|j|jfS|j�Sr)rZrYri)r�excs  r�_finish_infozReportEventStack._finish_infos)����,�,�d�l�l�;�;��*�*�,�,rc���|j|�\}}|jr%||f|jj|j<|jr$t|j|||j��yy)NrM)rsrXr^rr[rPr]r3)r�exc_type�	exc_value�	tracebackr2�msgs      r�__exit__zReportEventStack.__exit__s`���)�)�)�4�
����;�;�/5�s�m�D�K�K� � ����+��!�!���
�
�s�F�t���
�"r)rrrr+r4rr#rarcri�propertyr2�setterrYrsryrrrrUrU�s���$�T���"�K�K��%�N
��+������]�]����
� �� �

�^�^����-�rrUc�0�|syg}|D]}tjj|�sd}nFt|d�5}t	j
|j
��j�}ddd�|j|dd����|S#1swY�"xYw)N�rb�base64)�path�content�encoding)	�osr�isfile�openr~�	b64encode�read�decode�append)r9�ret�fnamer��fps     rr:r:(s�����
�C��N���w�w�~�~�e�$��G��e�T�"�
?�b� �*�*�2�7�7�9�5�<�<�>��
?��
�
�E�g�8�L�M�
N��J�
?�
?�s�2B�B	r)r+r~�os.pathr�r!�typingr�cloudinit.reportingrr�cloudinit.reporting.handlersrr1rRr,�setrr4rr.rKrrPrSrUr:rrr�<module>r�s���
������:�����"��<�s�<�
�-�	.��!
�!
�H�>��8%�@+1�.�.�T�
��E�E�Pr