HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/timer/__pycache__/update_messaging.cpython-38.pyc
U

��Jh��@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZ
ddlmZddlmZmZddlmZdd	lmZmZd
ZdZe�e
�e��Zed�d
d�Zeed�dd�Z dd�Z!dS)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)�contract�defaults�messages�system�util)�_updates)�_enabled_services)�ContractExpiryStatus�_is_attached)�UAConfig)�
machine_token�noticeszmotd-contract-statusz6/usr/lib/update-notifier/update-motd-updates-available)�cfgcCs�t�|�}|j}|�di��di��dd�}t�|�}|�|�dd�|�}|�di��di��dd�}|dk	r�||jkr�||ddd<|�|�dS)NZmachineTokenInfoZcontractInfo�idZmachineToken�ZeffectiveTo)r
�get_machine_token_file�getrZUAContractClientZget_contract_machine�contract_expiry_datetime�write)r�machine_token_fileZ
orig_tokenZcontract_idZcontract_clientZrespZresp_expiry�r�A/usr/lib/python3/dist-packages/uaclient/timer/update_messaging.py�update_contract_expiry s@
���

�������
�r)r�returncCst|�}|jsdSt�d�tj�|jdt�}|j	}|j
}t�|�}|t
jjt
jjt
jjfkrzt|�t|�}|j	}|j
}|t
jjt
jjfkr�t�tjj�t�|��nj|t
jjkr�t�tjj�t�|tj�|�j|d�d��n,|t
jjk�rRt�tjj�t j!|}|j"}|dk�r$d}n
|�#d�}t�|tj$�|�j||d	�d�n�|t
jjk�rt�%tjj�d
}	d}
dd
�t&|�j'D�}t�(��r�d|k�r�d}	t)|�j*j+}
n$t�,��r�d|k�r�d}	t)|�j*j-}
|
dk�r�t�|tjd�n"t�|tj.�|
�j|
|	d�d�dS)z�Emit 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

NZUnknownz%d %b %Y)Zexpired_daterzn/arcSsh|]
}|j�qSr)�name)�.0�srrr�	<setcomp>�sz'update_motd_messages.<locals>.<setcomp>z	esm-infrazesm-apps)�pkg_num�serviceT)/rZis_attached�LOG�info�os�path�joinZdata_dir�MOTD_CONTRACT_STATUS_FILE_NAMEZcontract_statusZcontract_remaining_daysr
rr
ZACTIVE_EXPIRED_SOON�valueZEXPIRED_GRACE_PERIODZEXPIREDrZACTIVEZNONEr�removeZNoticeZCONTRACT_EXPIREDrZensure_file_absentZ
write_filerZCONTRACT_EXPIRES_SOONZ	pluralize�formatrZ!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSr�strftimeZCONTRACT_EXPIRED_GRACE_PERIOD�addr	Zenabled_servicesZis_current_series_active_esm�api_u_pro_packages_updates_v1ZsummaryZnum_esm_infra_updatesZis_current_series_ltsZnum_esm_apps_updatesZCONTRACT_EXPIRED_WITH_PKGS)rZis_attached_infoZmotd_contract_status_msg_pathZ
expiry_statusrrZgrace_period_remainingZexp_dtZ
exp_dt_strr!r Zenabled_services_namesrrr�update_motd_messages;s�
�
������

����
�

�


�
����	r.c
CsLtt�rHzt�tdg�Wn,tk
rF}zt�|�W5d}~XYnXdS)Nz--force)r�UPDATE_NOTIFIER_MOTD_SCRIPTrZsubp�	Exceptionr"Z	exception)�excrrr�refresh_motd�s
r2)"�__doc__Zloggingr$�os.pathrZuaclientrrrrrZ&uaclient.api.u.pro.packages.updates.v1rr-Z-uaclient.api.u.pro.status.enabled_services.v1r	Z(uaclient.api.u.pro.status.is_attached.v1r
rZuaclient.configrZuaclient.filesr
rr'r/Z	getLoggerZreplace_top_level_logger_name�__name__r"r�boolr.r2rrrr�<module>s �i