a 'Dg @sddlZddlZddlmZmZddlmZmZmZddddddd d d Zd Z d Z dZ ddZ ddZ ddZddZdddZddZedkreedS)N)datetimetimezone) atomic_helpersubputilzfinished running cloud-initz%starting search for local datasourcesz!searching for network datasourceszrunning config moduleszfinalizing moduleszrunning modules forzrunning single module )finishedz init-local init-networkinitzmodules-configz modules-finalmodulesZsinglez%Y-%m-%d %H:%M:%S,%fz%b %d %H:%M:%S.%f %Yz%b %d %H:%M:%S %YcCsddtddD}|d|vrft}d|vr4t}t|dttj|j t j d}| }n0d |vrt|t j t j d}| }nt|}t|S) NcSsg|]}tj|qS)calendarZ month_abbr).0mr r :/usr/lib/python3.9/site-packages/cloudinit/analyze/dump.py z#parse_timestamp.. r. )Ztzinfo,)rangesplit DEFAULT_FMTCLOUD_INIT_JOURNALCTL_FMTrstrptimestrZnowZyearreplacerZutc timestampCLOUD_INIT_ASCTIME_FMTparse_timestamp_from_datefloat) timestampstrZmonthsZFMTZdtrr r rparse_timestamps&   r#cCsdtddgjvS)zGNU date includes a string containing the word GNU in it in help output. Posix date does not. Use this to indicate on Linux systems without GNU date that the extended parsing is not available. ZGNUdatez--help)rstdoutr r r r has_gnu_date9sr&cCsRtstdrd}ntr$d}ntd|dtt|ddd|gjS)NZgdater$z-Unable to parse timestamp without GNU date: []z-uz+%s.%3Nz-d) rZis_Linuxrwhichr& ValueErrorr!r%strip)r"r$r r rr Bs r cCsd}dd|g}d}|D]}||vrd}q,q|s4dS||\}}|drbd|dd }d |vr|d \}}|d |d7}d|vr|d } n@|d } ||kr|}|jd d d }n|| d}d|vrLd} d|vr>|dd } | d\} } | dddd} | dkrBd} ndSt| }n(|dd\}} } || d }| d|t|d| dd}|ddkr|dd}||d d}||d<||d<|S)Nz cloud-init[z - z [CLOUDINIT] FT:rrrz,%sr)maxsplit Cloud-init v.startZrunningz at '-r r cloudinit)name descriptionrorigin event_typer8Zfinishresultr6) rendswithjoinr*lstriprstage_to_descriptionrstripr#)lineZamazon_linux_2_sepZ separatorsfoundsepZtimehostZeventstrr"Zextrahostnamer8Zstage_and_timestampZ event_name_Zevent_descriptionZ _pymodloglvleventr9Zdescr r rparse_ci_loglinePs\        rEc Csg}d}gd}t||gs$td|r2|}n|}|D]P}|D]F}||vrFz t|}Wnty|tjdYn0|rF||qFq>||fS)N)zstart:zfinish:r.z2Either cisource or rawdata parameters are requiredzSkipping invalid entry ) anyr) splitlines readlinesrEsysstderrwriteappend)cisourceZrawdataZeventsrDZCI_EVENT_MATCHESdatar?matchr r r dump_eventss$    rPcCs2ttjdkrttjd}ntj}tt|S)Nr)lenrIargvopenstdinrZ json_dumpsrP)rMr r rmainsrU__main__)NN)r rIrrr4rrrr=rrrr#r&r rErPrU__name__printr r r rs.  V