HcfdZddlZddlZddlmZddlmZmZmZm Z m Z ddl m Z ddlmZmZddlmZddlmZmZdd lmZdd lmZd Zd Zej8e j:eZd efdZ d ede!fdZ"dZ#y)a% Update messaging text for use in MOTD and APT custom Ubuntu Pro messages. Messaging files will be emitted to /var/lib/ubuntu-advantage/message-* which will be sourced by apt-hook/hook.cc and various /etc/update-motd.d/ hooks to present updated text about Ubuntu Pro service and token state. N)exists)contractdefaultsmessagessystemutil)_updates)ContractExpiryStatus _is_attached)UAConfig)ESMAppsEntitlementESMInfraEntitlement)ApplicationStatus)noticeszmotd-contract-statusz6/usr/lib/update-notifier/update-motd-updates-availablecfgc|j}|jdd}|jdijdijdd}tj|}|j ||}|jdijdijdd}|A||j j k7r'||ddd<|j j|yyy)N machineTokenmachineTokenInfo contractInfoid effectiveTo) machine_tokengetrUAContractClientget_contract_machinemachine_token_filecontract_expiry_datetimewrite)r orig_tokenr contract_idcontract_clientresp resp_expirys A/usr/lib/python3/dist-packages/uaclient/timer/update_messaging.pyupdate_contract_expiryr&!s""JNN>26M)2. ^R T4 //4O  / / { KD #R( ^R ]D !  311JJ J  %&~6   $$Z0 K returnct|}|jsytjdtj j |jdt}|j}|j}|tjjtjjtjjfvr.t!|t|}|j}|j}|tj"jtj$jfvrCt'j(t&j*j,t/j0|y|tjjk(rtt'j(t&j*j,t/j2|t4j6j9|j;|dzy|tjjk(rt'j(t&j*j,t<j>|z}|j@jB}|d}n|jEd}t/j2|t4jFj9|j;||dzy|tjjk(rnt'jHt&j*j,d }d } t/jJrQtM|jO\} } | tPjRk(rd }tU|jVjX} ndt/jZrPt]|jO\} } | tPjRk(r!d }tU|jVj^} | d k(r(t/j2|t4j,dzyt/j2|t4j`j9| j;| | dzy)zEmit human-readable status message used by motd. Used by /etc/update.motd.d/91-contract-ua-esm-status :param cfg: UAConfig instance for this environment. Fz&Updating Ubuntu Pro messages for MOTD.r)remaining_daysz Unknownz%d %b %Y) expired_dater*zn/arz esm-infrazesm-apps)pkg_numserviceT)1r is_attachedLOGinfoospathjoindata_dirMOTD_CONTRACT_STATUS_FILE_NAMEcontract_statuscontract_remaining_daysr ACTIVE_EXPIRED_SOONvalueEXPIRED_GRACE_PERIODEXPIREDr&ACTIVENONErremoveNoticeCONTRACT_EXPIREDrensure_file_absent write_filerCONTRACT_EXPIRES_SOON pluralizeformatr!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSrrstrftimeCONTRACT_EXPIRED_GRACE_PERIODaddis_current_series_active_esmrapplication_statusrENABLEDapi_u_pro_packages_updates_v1summarynum_esm_infra_updatesis_current_series_ltsr num_esm_apps_updatesCONTRACT_EXPIRED_WITH_PKGS) ris_attached_infomotd_contract_status_msg_path expiry_statusr*grace_period_remainingexp_dt exp_dt_strr.r-esm_infra_status_esm_apps_statuss r%update_motd_messagesr]:s$C(  ' 'HH 56$&GGLL j"@%!%44M%==N00661177$$** s#',(88 )AA##))!!'' w~~667!!"?@D C .BBHH Hw~~667 )  * * 4 4^ D K K- L   ~ q .CCII Iw~~667  6 6 G ''@@ >"J4J )  2 2 < < f'5   \ I .66<< < GNN334  . . 0"5c":"M"M"O  a#4#<#<<%7'// ) ) +!3C!8!K!K!M OQ"3";";;$7'.. a<   -))F2     -33==gFMM##N   r'cttr tjtdgyy#t$r}t j |Yd}~yd}~wwxYw)Nz--force)rUPDATE_NOTIFIER_MOTD_SCRIPTrsubp Exceptionr0 exception)excs r% refresh_motdrdsJ)*  KK4i@ A +   MM#   s. AAA)$__doc__loggingr2os.pathruaclientrrrrr&uaclient.api.u.pro.packages.updates.v1r rN(uaclient.api.u.pro.status.is_attached.v1r r uaclient.configr uaclient.entitlementsr r(uaclient.entitlements.entitlement_statusruaclient.filesrr6r_ getLoggerreplace_top_level_logger_name__name__r0r&boolr]rdr'r%rts ??%IF"!7<g:::8DE112dhd4dN r'