HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/timer/__pycache__/update_messaging.cpython-310.pyc
o

nHJeD�@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZ
ddlmZddlmZddlmZmZdd	lmZd
ZdZe�e
�e��Zdefd
d�Zdedefdd�Zdd�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)�_is_attached)�UAConfig)�ESMAppsEntitlement�ESMInfraEntitlement)�ApplicationStatuszmotd-contract-statusz6/usr/lib/update-notifier/update-motd-updates-available�cfgcCs�|j}|�dd�}|�di��di��dd�}t�|�}|�||�}|�di��di��dd�}|durJ||jjkrL||ddd<|j�|�dSdSdS)N�machineToken��machineTokenInfo�contractInfo�id�effectiveTo)�
machine_token�getr�UAContractClient�get_contract_machine�machine_token_file�contract_expiry_datetime�write)r�
orig_tokenr�contract_id�contract_client�resp�resp_expiry�r!�A/usr/lib/python3/dist-packages/uaclient/timer/update_messaging.py�update_contract_expirys*
�

�
���r#�returncCs�t|�jsdSt�d�tj�|jdt�}t	�
|�\}}|t	jjt	jj
t	jjfvr4t|�t	�
|�\}}|t	jjt	jjfvrEt�|�dS|t	jjkr]t�|tj�|�j|d�d�dS|t	jj
kr�tj|}|jj}|dursd}n|�d�}t�|tj�|�j||d	�d�dS|t	jjkr�d
}d}t��r�t |��!�\}	}
|	t"j#kr�d}t$|�j%j&}nt�'�r�t(|��!�\}}
|t"j#kr�d
}t$|�j%j)}|dkr�t�|tj*d�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/arz	esm-infrazesm-apps)�pkg_num�serviceT),r	�is_attached�LOG�debug�os�path�join�data_dir�MOTD_CONTRACT_STATUS_FILE_NAMEr�get_contract_expiry_status�ContractExpiryStatus�ACTIVE_EXPIRED_SOON�EXPIRED_GRACE_PERIOD�EXPIREDr#�ACTIVE�NONEr�ensure_file_absent�
write_filer�CONTRACT_EXPIRES_SOON�	pluralize�formatr�!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSrr�strftime�CONTRACT_EXPIRED_GRACE_PERIOD�is_current_series_active_esmr�application_statusr
�ENABLED�api_u_pro_packages_updates_v1�summary�num_esm_infra_updates�is_current_series_ltsr�num_esm_apps_updates�CONTRACT_EXPIRED�CONTRACT_EXPIRED_WITH_PKGS)r�motd_contract_status_msg_path�
expiry_statusr%�grace_period_remaining�exp_dt�
exp_dt_strr)r(�esm_infra_status�_�esm_apps_statusr!r!r"�update_motd_messages6s�

����
>����<��
����,�
���
�������	rSc
CsRtt�r'z
t�tdg�WdSty&}zt�|�WYd}~dSd}~wwdS)Nz--force)r�UPDATE_NOTIFIER_MOTD_SCRIPTr�subp�	Exceptionr+�	exception)�excr!r!r"�refresh_motd�s���rY)!�__doc__�loggingr-�os.pathr�uaclientrrrrr�&uaclient.api.u.pro.packages.updates.v1rrD�(uaclient.api.u.pro.status.is_attached.v1r	�uaclient.configr
�uaclient.entitlementsrr�(uaclient.entitlements.entitlement_statusr
r1rT�	getLogger�replace_top_level_logger_name�__name__r+r#�boolrSrYr!r!r!r"�<module>s"�_