Ë
    x[h$  ã                   ó$  — d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZ dZdZd	Z ej$                  e«      Z G d
„ de«      Z ed«      Z G d„ d«      Z G d„ de«      Zdd„Zej6                  dfd„Zd„ Z G d„ d«      Zd„ Zy)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)Úperformance)Úavailable_handlersÚinstantiated_handler_registry)ÚReportingHandlerÚfinishÚstartÚ	cloudinitc                   ó   — e Zd Zd„ Zy)Ú_namesetc                 ó*   — || v r|S t        d|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   © r   r   r   r      s   „ ó<r   r   )ÚSUCCESSÚWARNÚFAILc                   ó(   — e Zd ZdZedfd„Zd„ Zd„ Zy)ÚReportingEventz"Encapsulation of event formatting.Nc                 óv   — || _         || _        || _        || _        |€t	        j                  «       }|| _        y ©N)Ú
event_typer   ÚdescriptionÚoriginÚtimeÚ	timestamp)r   r   r   r    r!   r#   s         r   Ú__init__zReportingEvent.__init__,   s9   € ð %ˆŒØˆŒ	Ø&ˆÔØˆŒØÐÜŸ	™	›ˆIØ"ˆ�r   c                 ód   — dj                  | j                  | j                  | j                  «      S )z"The event represented as a string.z{0}: {1}: {2})Úformatr   r   r    ©r   s    r   Ú	as_stringzReportingEvent.as_string<   s*   € à×%Ñ%Ø�O‰O˜TŸY™Y¨×(8Ñ(8ó
ð 	
r   c                 óv   — | j                   | j                  | j                  | j                  | j                  dœS )z&The event represented as a dictionary.©r   r    r   r!   r#   r*   r'   s    r   Úas_dictzReportingEvent.as_dictB   s3   € ð —I‘IØ×+Ñ+ØŸ/™/Ø—k‘kØŸ™ñ
ð 	
r   )r   r   r   Ú__doc__ÚDEFAULT_EVENT_ORIGINr$   r(   r+   r   r   r   r   r   )   s   „ Ù,ð $Øó#ò 
ó
r   r   c                   óH   ‡ — e Zd Zej                  dfˆ fd„	Zd„ Zˆ fd„Zˆ xZS )ÚFinishReportingEventNc                 óˆ   •— t         t        | �  t        ||«       || _        |€g }|| _        |t        vrt        d|z  «      ‚y )NzInvalid result: %s)Úsuperr/   r$   ÚFINISH_EVENT_TYPEÚresultÚ
post_filesÚstatusÚ
ValueError)r   r   r    r3   r4   Ú	__class__s        €r   r$   zFinishReportingEvent.__init__N   sU   ø€ ô 	Ô" DÑ2Ü˜t [ô	
ð ˆŒØÐØˆJØ$ˆŒØœÑÜÐ1°FÑ:Ó;Ð;ð  r   c                 óz   — dj                  | j                  | j                  | j                  | j                  «      S )Nz{0}: {1}: {2}: {3})r&   r   r   r3   r    r'   s    r   r(   zFinishReportingEvent.as_string[   s0   € Ø#×*Ñ*Ø�O‰O˜TŸY™Y¨¯©°T×5EÑ5Eó
ð 	
r   c                 ó’   •— t         t        | �  «       }| j                  |d<   | j                  rt        | j                  «      |d<   |S )z'The event represented as json friendly.r3   Úfiles)r1   r/   r+   r3   r4   Ú_collect_file_info)r   Údatar7   s     €r   r+   zFinishReportingEvent.as_dict`   s>   ø€ äÔ)¨4Ñ8Ó:ˆØŸ™ˆˆX‰Ø�?Š?Ü.¨t¯©Ó?ˆD�‰MØˆr   )	r   r   r   r5   r   r$   r(   r+   Ú__classcell__)r7   s   @r   r/   r/   M   s    ø„ à(.¯©À4õ<ò
÷
ð r   r/   c                 ó  — |si }t         j                  j                  «       D ��ch c]  \  }}||v r|’Œ }}}t        t        j                  j                  «       «      }|D ]!  }t        |«      |v rŒ|j                  | «       Œ# yc c}}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_eventrL   i   s›   € ñ "Ø!#Ðô $6×#FÑ#F×#LÑ#LÓ#N÷ áˆI�xØÐ.Ñ.ò 	ð Ðñ  ô (,Ü%×6Ñ6×=Ñ=Ó?ó(€Hð ò %ˆÜ�‹=Ð4Ñ4ØØ×Ñ˜eÕ$ñ%ùó s   ¦Bc                 ó6   — t        | |||¬«      }t        |«      S )zVReport a "finish" event.

    See :py:func:`.report_event` for parameter details.
    ©r4   )r/   rL   )Ú
event_nameÚevent_descriptionr3   r4   rE   s        r   Úreport_finish_eventrQ   ˆ   s%   € ô !ØÐ% v¸*ô€Eô ˜ÓÐr   c                 ó:   — t        t        | |«      }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_TYPErL   )rO   rP   rE   s      r   Úreport_start_eventrT   •   s   € ô Ô+¨ZÐ9JÓK€EÜ˜ÓÐr   c                   ó¼   — e Zd ZdZdddej
                  dfd„Zd„ Zd„ Zd„ Z	e
d„ «       Zej                  d„ «       Ze
d	„ «       Zej                  d
„ «       Zd„ Zd„ Zy)ÚReportEventStackaK  Context 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                  }nd}|| _	        |r*dj                  |j                  |f«      | _        i | _        y | j                  | _        i | _        y )NTú/)Úparentr   r    ÚmessageÚresult_on_exceptionr5   r   r3   r4   Úreporting_enabledÚjoinÚfullnameÚchildren)r   r   r    rZ   rY   r\   r[   r4   s           r   r$   zReportEventStack.__init__Ê   sª   € ð ˆŒØˆŒ	Ø&ˆÔØˆŒØ#6ˆÔ Ü—n‘nˆŒØÐØˆJØ$ˆŒð Ð$ÙØ$*×$<Ñ$<Ñ!à$(Ð!Ø!2ˆÔáØŸH™Hà—O‘OØðóˆDŒMð ˆ�ð !ŸI™IˆDŒMØˆ�r   c                 óV   — d| j                   ›d| j                  ›d| j                  ›d�S )NzReportEventStack(z, z, reporting_enabled=ú))r   r    r\   r'   s    r   Ú__repr__zReportEventStack.__repr__ñ   s%   � à�I‹IØ×ÓØ×"Ó"ð
ð 	
r   c                 óæ   — t         j                  | _        | j                  r t	        | j
                  | j                  «       | j                  r#d| j                  j                  | j                  <   | S )N)NN)
r5   r   r3   r\   rT   r^   r    rY   r_   r   r'   s    r   Ú	__enter__zReportEventStack.__enter__ø   sN   € Ü—n‘nˆŒØ×!Ò!Ü˜tŸ}™}¨d×.>Ñ.>Ô?Ø�;Š;Ø.:ˆD�K‰K× Ñ  §¡Ñ+Øˆr   c                 óô   — t         j                  t         j                  fD ]>  }| j                  j	                  «       D ]  \  }\  }}||k(  sŒ|| j
                  fc c S  Œ@ | j                  | j
                  fS r   )r5   r   r   r_   r@   rZ   r3   )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Ÿ\™\Ð*Ð*r   c                 ó   — | j                   S r   )Ú_resultr'   s    r   r3   zReportEventStack.result  s   € à�|‰|Ðr   c                 ó>   — |t         vrt        d|z  «      ‚|| _        y )Nz'%s' not a valid result)r5   r6   rl   ©r   rh   s     r   r3   zReportEventStack.result  s"   € àœÑÜÐ6¸Ñ>Ó?Ð?Øˆ�r   c                 óJ   — | j                   �| j                   S | j                  S r   )Ú_messager    r'   s    r   rZ   zReportEventStack.message  s"   € à�=‰=Ð$Ø—=‘=Ð Ø×ÑÐr   c                 ó   — || _         y r   )rp   rn   s     r   rZ   zReportEventStack.message  s	   € àˆ�r   c                 óV   — |r| j                   | j                  fS | j                  «       S r   )r[   rZ   rj   )r   Úexcs     r   Ú_finish_infozReportEventStack._finish_info  s)   € áØ×,Ñ,¨d¯l©lÐ;Ð;Ø×*Ñ*Ó,Ð,r   c                 óî   — | j                  |«      \  }}| j                  r%||f| j                  j                  | j                  <   | j                  r$t        | j                  ||| j                  ¬«       y y )NrN   )rt   rY   r_   r   r\   rQ   r^   r4   )r   Úexc_typeÚ	exc_valueÚ	tracebackr3   Úmsgs         r   Ú__exit__zReportEventStack.__exit__!  s`   € Ø×)Ñ)¨)Ó4‰ˆ�Ø�;Š;Ø/5°s¨mˆD�K‰K× Ñ  §¡Ñ+Ø×!Ò!ÜØ—‘˜s F°t·±öð "r   )r   r   r   r,   r5   r   r$   rb   rd   rj   Úpropertyr3   ÚsetterrZ   rt   rz   r   r   r   rV   rV   £   s”   „ ñ$ðT ØØØ"ŸK™KØó%òN
òò+ð ñó ðð ‡]�]ñó ðð
 ñ ó ð ð
 ‡^�^ñó ðò-ór   rV   c                 óŠ  — | sy g }| D ]   }t         j                  j                  |«      sd }ngt        j                  d|› �«      5  t        |d«      5 }t        j                  |j                  «       «      j                  «       }d d d «       d d d «       |j                  |ddœ«       Œ¢ |S # 1 sw Y   Œ*xY w# 1 sw Y   Œ.xY w)NzReading ÚrbÚbase64)ÚpathÚcontentÚencoding)Úosr€   Úisfiler   ÚTimedÚopenr   Ú	b64encodeÚreadÚdecodeÚappend)r:   ÚretÚfnamer�   Úfps        r   r;   r;   +  s¼   € ÙØØ
€CØò NˆÜ�w‰w�~‰~˜eÔ$Ø‰Gä×"Ñ" X¨e¨WÐ#5Ó6ñ ?¼Ø�tó9ð ?àÜ ×*Ñ*¨2¯7©7«9Ó5×<Ñ<Ó>�÷?÷ ?ð 	�
‰
˜E¨gÀ8ÑLÕMðNð €J÷?ð ?ú÷ ?ð ?ús$   ÁB9Á2B-ÂB9Â-B6Â2B9Â9C	r   ) r,   r   ÚloggingÚos.pathrƒ   r"   Útypingr   r
   r   Úcloudinit.reportingr   r   Úcloudinit.reporting.handlersr   r2   rS   r-   Ú	getLoggerr   ÚLOGÚsetr   r5   r   r/   rL   r   rQ   rT   rV   r;   r   r   r   ú<module>r–      s©   ðñ
ó Û Û Û Ý å !÷õ :àÐ ØÐ à"Ð Ø€g×Ñ˜Ó!€ô<ˆsô <ñ 
Ð-Ó	.€÷!
ñ !
ôH˜>ô ó8%ð@ +1¯.©.ÀTó
ò÷Eñ EóPr   