HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/timer/__pycache__/update_messaging.cpython-310.pyc
o

��Jh��@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZ
ddlmZddlmZmZddlmZdd	lmZmZd
ZdZe�e
�e��Zdefd
d�Zdedefdd�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�}|durK||jkrM||ddd<|�|�dSdSdS)N�machineTokenInfo�contractInfo�id�machineToken��effectiveTo)r
�get_machine_token_file�getr�UAContractClient�get_contract_machine�contract_expiry_datetime�write)r�machine_token_file�
orig_token�contract_id�contract_client�resp�resp_expiry�r"�A/usr/lib/python3/dist-packages/uaclient/timer/update_messaging.py�update_contract_expiry s.

�
�
�

���r$�returncCst|�}|js	dSt�d�tj�|jdt�}|j	}|j
}t�|�}|t
jjt
jjt
jjfvr=t|�t|�}|j	}|j
}|t
jjt
jjfvrUt�tjj�t�|�dS|t
jjkrtt�tjj�t�|tj�|�j|d�d�dS|t
jjkr�t�tjj�t j!|}|j"}|dur�d}n|�#d�}t�|tj$�|�j||d	�d�dS|t
jjk�rt�%tjj�d
}	d}
dd
�t&|�j'D�}t�(�r�d|vr�d}	t)|�j*j+}
nt�,�r�d|vr�d}	t)|�j*j-}
|
dkr�t�|tjd�dSt�|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

N�Unknownz%d %b %Y)�expired_dater&zn/arcSsh|]}|j�qSr")�name)�.0�sr"r"r#�	<setcomp>�s�z'update_motd_messages.<locals>.<setcomp>z	esm-infrazesm-apps)�pkg_num�serviceT)/r�is_attached�LOG�info�os�path�join�data_dir�MOTD_CONTRACT_STATUS_FILE_NAME�contract_status�contract_remaining_daysr
rr
�ACTIVE_EXPIRED_SOON�value�EXPIRED_GRACE_PERIOD�EXPIREDr$�ACTIVE�NONEr�remove�Notice�CONTRACT_EXPIREDr�ensure_file_absent�
write_filer�CONTRACT_EXPIRES_SOON�	pluralize�formatr�!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSr�strftime�CONTRACT_EXPIRED_GRACE_PERIOD�addr	�enabled_services�is_current_series_active_esm�api_u_pro_packages_updates_v1�summary�num_esm_infra_updates�is_current_series_lts�num_esm_apps_updates�CONTRACT_EXPIRED_WITH_PKGS)r�is_attached_info�motd_contract_status_msg_path�
expiry_statusr&r�grace_period_remaining�exp_dt�
exp_dt_strr.r-�enabled_services_namesr"r"r#�update_motd_messages;s�
�
��
C����@��
����/������������	rZc
CsRtt�r'z
t�tdg�WdSty&}zt�|�WYd}~dSd}~wwdS)Nz--force)r�UPDATE_NOTIFIER_MOTD_SCRIPTr�subp�	Exceptionr0�	exception)�excr"r"r#�refresh_motd�s���r`)"�__doc__�loggingr2�os.pathr�uaclientrrrrr�&uaclient.api.u.pro.packages.updates.v1rrM�-uaclient.api.u.pro.status.enabled_services.v1r	�(uaclient.api.u.pro.status.is_attached.v1r
r�uaclient.configr�uaclient.filesr
rr6r[�	getLogger�replace_top_level_logger_name�__name__r0r$�boolrZr`r"r"r"r#�<module>s"�i