o
    th
                  
   @   s   U d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ eZd
egeg dZeed< eeZdZdede	dededdf
ddZdS )z@Final Message: Output final message when cloud-init has finished    N)	templaterutilversion)Cloud)Config)
MetaSchema)ALL_DISTROS)log_util)
PER_ALWAYScc_final_message)iddistros	frequencyactivate_by_schema_keysmetazy## template: jinja
Cloud-init v. {{version}} finished at {{timestamp}}. Datasource {{datasource}}.  Up {{uptime}} secondsnamecfgcloudargsreturnc              
   C   sv  d}|rt |d }nt|dd}| }|st}t }t }t }z)|||t |j	d}|
tdd | D  tjdt|| dd	td
 W n* tjyk }	 zttdt |	 W Y d }	~	nd }	~	w tyy   ttd Y nw |jj}
zd|||f }tj|
|dd W n ty   ttd|
 Y nw |j	jdkr|j	jddgkrtd d S d S d S )N r   final_message)uptime	timestampr   
datasourcec                 S   s   g | ]
\}}|  |fqS  )upper).0kvr   r   C/usr/lib/python3/dist-packages/cloudinit/config/cc_final_message.py
<listcomp><   s    zhandle.<locals>.<listcomp>z%s
FT)consolestderrlogz,Failed to render templated final message: %sz'Failed to render final message templatez%s - %s - v. %s
)ensure_dir_existsz%Failed to write boot finished file %sNonedatasource_listzUsed fallback datasource)strr   get_cfg_option_strstripFINAL_MESSAGE_DEFr   time_rfc2822r   version_stringr   updatedictitemsr	   	multi_logr   render_stringLOGJinjaSyntaxParsingExceptionlogexc	Exceptionpathsboot_finished
write_filedsnamesys_cfggetwarning)r   r   r   r   msg_inr   tscversubseboot_fin_fncontentsr   r   r    handle&   sV   

rE   )__doc__logging	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.logr	   cloudinit.settingsr
   r   r   __annotations__	getLogger__name__r3   r+   r(   listrE   r   r   r   r    <module>   s&   
"