Current File : //lib/python2.7/site-packages/cloudinit/reporting/events.pyo
�
oB�]c@s�dZddlZddlZddlZddlmZdZdZdZ	de
fd	��YZed�Zd
e
fd��YZdefd��YZd�Zejdd�Zd�Zde
fd��YZd�ZdS(s�
events for reporting.

The events here are designed to be used with reporting.
They can be published to registered handlers with report_event.
i����Ni(tinstantiated_handler_registrytfinishtstartt	cloudinitt_namesetcBseZd�ZRS(cCs$||kr|Std|��dS(Ns%s not a valid value(tAttributeError(tselftname((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__getattr__s(t__name__t
__module__R(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRstSUCCESStWARNtFAILtReportingEventcBs/eZdZedd�Zd�Zd�ZRS(s"Encapsulation of event formatting.cCsL||_||_||_||_|dkr?tj�}n||_dS(N(t
event_typeRtdescriptiontorigintNonettimet	timestamp(RRRRRR((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__init__$s				cCsdj|j|j|j�S(s"The event represented as a string.s
{0}: {1}: {2}(tformatRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt	as_string.scCs6i|jd6|jd6|jd6|jd6|jd6S(s&The event represented as a dictionary.RRRRR(RRRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytas_dict3sN(R	R
t__doc__tDEFAULT_EVENT_ORIGINRRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR!s		tFinishReportingEventcBs,eZejdd�Zd�Zd�ZRS(cCsftt|�jt||�||_|dkr:g}n||_|tkrbtd|��ndS(NsInvalid result: %s(	tsuperRRtFINISH_EVENT_TYPEtresultRt
post_fileststatust
ValueError(RRRRR((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR<s
			cCs"dj|j|j|j|j�S(Ns{0}: {1}: {2}: {3}(RRRRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRGscCsEtt|�j�}|j|d<|jrAt|j�|d<n|S(s'The event represented as json friendly.Rtfiles(RRRRRt_collect_file_info(Rtdata((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyRKs

	N(R	R
R RRRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR:s
	cCs1x*tjj�D]\}}|j|�qWdS(sReport an event to all registered event handlers.

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

    :param event_type:
        The type of the event; this should be a constant from the
        reporting module.
    N(Rtregistered_itemstitemst
publish_event(teventt_thandler((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytreport_eventTs
cCs"t|||d|�}t|�S(sVReport a "finish" event.

    See :py:func:`.report_event` for parameter details.
    R(RR+(t
event_nametevent_descriptionRRR(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytreport_finish_eventbs	cCstt||�}t|�S(s'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.
    (RtSTART_EVENT_TYPER+(R,R-R(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pytreport_start_eventms
tReportEventStackcBs�eZdZdddejdd�Zd�Zd�Zd�Z	e
d��Zejd��Ze
d��Z
e
jd��Z
d	�Zd
�ZRS(s�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.
    cCs�||_||_||_||_||_tj|_|dkrNg}n||_	|dkr~|ru|j
}q~t}n||_
|r�dj|j
|f�|_
n|j|_
i|_dS(Nt/(tparentRRtmessagetresult_on_exceptionR RRRRtreporting_enabledtTruetjointfullnametchildren(RRRR4R3R6R5R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR�s$									cCsd|j|j|jfS(Ns.ReportEventStack(%s, %s, reporting_enabled=%s)(RRR6(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__repr__�scCsNtj|_|jr+t|j|j�n|jrJd|jj	|j
<n|S(N(NN(R RRR6R0R9RR3RR:R(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt	__enter__�s		cCslxYtjtjfD]E}x<|jj�D]+\}\}}||kr)||jfSq)WqW|j|jfS(N(R R
RR:R&R4R(Rtcand_resultt_nametvaluet_msg((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt_childrens_finish_info�s
"cCs|jS(N(t_result(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR�scCs,|tkrtd|��n||_dS(Ns'%s' not a valid result(R R!RB(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR�scCs|jdk	r|jS|jS(N(t_messageRR(R((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4�scCs
||_dS(N(RC(RR?((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR4�scCs |r|j|jfS|j�S(N(R5R4RA(Rtexc((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt_finish_info�scCsf|j|�\}}|jr:||f|jj|j<n|jrbt|j||d|j�ndS(NR(RER3R:RR6R.R9R(Rtexc_typet	exc_valuet	tracebackRtmsg((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt__exit__�s		N(R	R
RRR R
RR;R<RAtpropertyRtsetterR4RERJ(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR1{s					cCs�|s
dSg}x~|D]v}tjj|�s8d}n3t|d��"}tj|j��j�}WdQX|j	i|d6|d6dd6�qW|S(Ntrbtpathtcontenttbase64tencoding(
RtosRNtisfiletopenRPt	b64encodetreadtdecodetappend(R"trettfnameROtfp((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyR#�s
	!(sSUCCESSsWARNsFAIL(RRPtos.pathRRRtRRR/RtsetRR tobjectRRR+RRR.R0R1R#(((s>/usr/lib/python2.7/site-packages/cloudinit/reporting/events.pyt<module>
s 	
	p