+
     gA                          R t ^ RIt^ RIt^ RIt^ RIHtHtHtHtH	t	H
t
 ^ RIHt Rt]]
]]]]3,          3,          ,          tRsR t]P$                   ! R R]P&                  4      4       tR R	 lt ! R
 R4      tR# )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_dumpz0.1c                  2    \         f   \        4       s \         # N)_event_loggerEventLogger     7/usr/lib/python3/dist-packages/uaclient/event_logger.pyget_event_loggerr      s     #r   c                   D    ] tR t^tRt]! 4       t]! 4       t]! 4       tRt	R# )EventLoggerModez
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.
r   N)
__name__
__module____qualname____firstlineno____doc__objectCLIJSONYAML__static_attributes__r   r   r   r   r      s     (C8D8Dr   r   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# )   statusreturn)r   strr   )formats   "r   __annotate__r#   ,   s*      4S> d38n r   c                 >   ^ RI Hp \        V! 4       P                  4       4       UUu. uF  w  r#RVRV/NK  	  uppV R&   V P	                  RR4       V P                  R. 4       V P                  R. 4       F  pRV9   g   K  VP	                  R4       K  	  V # u uppi )	    )get_pro_environmentnamevalueenvironment_varsorigin servicesvariants)uaclient.utilr&   sorteditemspop
setdefaultget)r   r&   r'   r(   services   &    r   format_machine_readable_outputr5   ,   s    1 ""5"7"="="?@"@KD 
w&@"F JJx j"%
 ::j"- KK
# . M'"s   Bc                   &  a  ] tR t^Et o R tR tV 3R lR ltV 3R lR ltV 3R lR ltR V 3R
 lR llt	R!V 3R lR llt
R"V 3R lR lltR#V 3R lR lltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltR tR tR tV 3R lR ltRtV tR	# )$r   c                    . V n         . V n        \        4       V n        \        4       V n        R V n        RV n        / V n        \        P                  V n
        R# )Fr+   N_error_events_warning_eventsset_processed_services_failed_services_needs_reboot_command_output_contentr   r   _event_logger_modeselfs   &r   __init__EventLogger.__init__F   sM    !#&5  #"! #2"5"5r   c                    . V n         . V n        \        4       V n        \        4       V n        RV n        RV n        / V n        \        P                  V n
        R# )z/Reset the state of the event logger attributes.Fr+   Nr8   rB   s   &r   resetEventLogger.resetS   sK    !#&5  #"!"1"5"5r   c                    < V ^8  d   QhRS[ /# )r   
event_mode)r   )r"   __classdict__s   "r   r#   EventLogger.__annotate__^   s     - - -r   c                    Wn         R# )zOSet the event logger mode.

We currently support the CLI, JSON and YAML modes.
N)rA   )rC   rJ   s   &&r   set_event_modeEventLogger.set_event_mode^   s
    
 #-r   c                    < V ^8  d   QhRS[ /# )r   commandr!   )r"   rK   s   "r   r#   rL   e   s        3  r   c                    Wn         R# )zkSet the event logger command.

The command will tell the process_events method which output method
to use.
N)r?   )rC   rQ   s   &&r   set_commandEventLogger.set_commande   s	      r   c                    < V ^8  d   QhRS[ /# )r   output_content)r   )r"   rK   s   "r   r#   rL   m   s     . . .r   c                    Wn         R# )zlSet the event logger output content.

The command will tell the process_events method which content
to use.
N)r@   )rC   rW   s   &&r   set_output_contentEventLogger.set_output_contentm   s
      .r   Nc                6   < V ^8  d   QhRS[ RS[S[ ,          /# )r   info_msgendr!   r   )r"   rK   s   "r   r#   rL   u   s     5 5S 5x} 5r   c                    V'       g   \         P                  pV P                  \        P                  8X  d   \        WVR7       R# R# )z<
Print the info message if the event logger is on CLI mode.
)filer]   N)sysstdoutrA   r   r   print)rC   r\   	file_typer]   s   &&&&r   infoEventLogger.infou   s3     

I""o&9&99(4 :r   c                   < V ^8  d   QhRS[ RS[S[ ,          RS[S[S[ S[3,          ,          RS[S[ ,          RS[S[ ,          RS[S[S[ S[ 3,          ,          /# )r   msgr4   
event_dictcode
event_typeadditional_info)r!   r   r   r   EventFieldErrorType)r"   rK   s   "r   r#   rL      sp     ' '' #' c#6678	'
 sm' SM' "$sCx.1'r   c                t    Vf   V'       d   RMRpRVRVRVRV/pV'       d   WgR&   VP                  V4       R # )Nr4   systemtypemessagemessage_coderl   )append)rC   rh   r4   ri   rj   rk   rl   event_entrys   &&&&&&& r   _record_dict_eventEventLogger._record_dict_event   sL     &-8J JwsD	
 -<)*+&r   c                   < V ^8  d   QhRS[ RS[S[ ,          RS[S[ ,          RS[S[ ,          RS[S[S[ S[ 3,          ,          /# )r   	error_msg
error_coder4   
error_typerl   )r!   r   r   )r"   rK   s   "r   r#   rL      sV       SM #	
 SM "$sCx.1r   c           	         V P                   \        P                  8w  d$   V P                  VVV P                  VVVR7       R# R# )zu
Store an error in the event logger.

However, the error will only be stored if the event logger
is not on CLI mode.
)rh   r4   ri   rj   rk   rl   N)rA   r   r   ru   r9   )rC   rx   ry   r4   rz   rl   s   &&&&&&r   errorEventLogger.error   sH     ""o&9&99##--% / $  :r   c                6   < V ^8  d   QhRS[ RS[S[ ,          /# )r   warning_msgr4   r^   )r"   rK   s   "r   r#   rL      s      3 # r   c                    V P                   \        P                  8w  d!   V P                  VVV P                  R7       R# R# )zx
Store a warning in the event logger.

However, the warning will only be stored if the event logger
is not on CLI mode.
)rh   r4   ri   N)rA   r   r   ru   r:   )rC   r   r4   s   &&&r   warningEventLogger.warning   s?     ""o&9&99##// $  :r   c                    < V ^8  d   QhRS[ /# r   r4   rR   )r"   rK   s   "r   r#   rL      s     . . .r   c                <    V P                   P                  V4       R # r
   )r<   addrC   r4   s   &&r   service_processedEventLogger.service_processed   s      $$W-r   c                0   < V ^8  d   QhRS[ S[,          /# )r   r,   )r   r!   )r"   rK   s   "r   r#   rL      s     / /S	 /r   c                <    V P                   P                  V4       R # r
   )r=   update)rC   r,   s   &&r   services_failedEventLogger.services_failed   s    $$X.r   c                    < V ^8  d   QhRS[ /# r   rR   )r"   rK   s   "r   r#   rL      s     + +c +r   c                <    V P                   P                  V4       R # r
   )r=   r   r   s   &&r   service_failedEventLogger.service_failed   s    !!'*r   c                    < V ^8  d   QhRS[ /# )r   reboot_required)bool)r"   rK   s   "r   r#   rL      s     - -D -r   c                    Wn         R # r
   )r>   )rC   r   s   &&r   needs_rebootEventLogger.needs_reboot   s    ,r   c                    V P                    Uu0 uF  pVR ,          '       g   K  VR ,          kK  	  pp\        \        P                  V P                  V4      4      # u upi )r4   )r9   listr;   unionr=   )rC   r|   services_with_errors   &  r   _generate_failed_services%EventLogger._generate_failed_services   sc     ++
+Y E)+ 	 

 CIId335HIJJ
s
   AAc                4   R \         RV P                  '       g   RMRR\        V P                  4      R\        V P	                  4       4      RV P                  RV P
                  RV P                  /p^ R	IHp \        \        P                  ! WR
R7      4       R# )_schema_versionresultsuccessfailureprocessed_servicesfailed_serviceserrorswarningsr   DatetimeAwareJSONEncoderTcls	sort_keysN)JSON_SCHEMA_VERSIONr9   r/   r<   r   r:   r>   r.   r   rc   jsondumps)rC   responser   s   &  r   _process_events_services$EventLogger._process_events_services   s    2t'9'9'9iy &)A)A"Bvd&D&D&FGd((,,D..
 	;JJxN	
r   c                   \        V P                  4      pV P                  '       g   R MRVR&   V P                  VR&   V P                  VR&   V P                  \
        P                  8X  d*   ^ RIHp \        \        P                  ! WRR7      4       R
# V P                  \
        P                  8X  d   \        \        VRR	7      4       R
# R
# )r   r   r   r   r   r   Tr   F)default_flow_styleN)r5   r@   r9   r:   rA   r   r   r.   r   rc   r   r   r   r   )rC   outputr   s   &  r   _process_events_status"EventLogger._process_events_status   s    /0D0DE,0,>,>,>9Ix--x!11z""o&:&::>

D
 $$(<(<<)Fu=> =r   c                   < V ^8  d   QhRR/# )r   r    Nr   )r"   rK   s   "r   r#   rL      s     0 0 0r   c                    V P                   \        P                  8w  d6   V P                  R8X  d   V P	                  4        R# V P                  4        R# R# )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.
r   N)rA   r   r   r?   r   r   rB   s   &r   process_eventsEventLogger.process_events   sA     ""o&9&99}}(++---/	 :r   )r?   r9   rA   r=   r>   r@   r<   r:   )NN)NNN)NNNNr
   )r   r   r   r   rD   rG   rN   rT   rY   re   ru   r|   r   r   r   r   r   r   r   r   r   r   __classdictcell__)rK   s   @r   r   r   E   s     6	6- -   . .5 5' '0 0 . ./ /+ +- -K
"?"0 0r   r   )r   enumr   ra   typingr   r   r   r   r   r   uaclient.yamlr   r   r!   rm   r   r   uniqueEnumr   r5   r   r   r   r   <module>r      s      
 8 8 # uS$sCx.%89:  
dii 
 
2z0 z0r   