Current File : //usr/lib/python3/dist-packages/uaclient/timer/__pycache__/update_messaging.cpython-312.pyc
�

Uٵg�����dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZ
ddlmZddlmZmZddlmZdd	lmZmZd
ZdZej4e
j6e��Zdefd
�Zdedefd�Z d�Z!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)�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�cfgc���tj|�}|j}|jdi�jdi�jdd�}tj|�}|j|jdd�|�}|jdi�jdi�jdd�}|�-||jk7r||ddd<|j|�yyy)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_expirys       �A/usr/lib/python3/dist-packages/uaclient/timer/update_messaging.py�update_contract_expiryr% s���&�=�=�c�B��#�1�1�J����)�2�.�	��^�R�	 �	��T�4���
�/�/��4�O��/�/����~�r�*�K��D�	
���#�R�(�	��^�R�	 �	��]�D�	!��	���-�F�F�F�
�	�%�&�~�6��	
�	� � ��,�
G�	 ��returnc��t|�}|jsytjd�tj
j
|jdt�}|j}|j}tj|�}|tjjtj jtj"jfvr.t%|�t|�}|j}|j}|tj&jtj(jfvrCt+j,t*j.j0�t3j4|�y|tjjk(rtt+j,t*j.j0�t3j6|t8j:j=|�j?|��dz�y|tj jk(r�t+j,t*j.j0�t@jB|z}|jD}|�d}n|jGd�}t3j6|t8jHj=|�j?||��dz�y|tj"jk(�rDt+jJt*j.j0�d	}	d
}
tM|�jND�chc]}|jP��}}t3jR�r&d|vr[d}	tU|�jVjX}
n9t3jZ�r%d|vr!d}	tU|�jVj\}
|
d
k(r(t3j6|t8j0dz�yt3j6|t8j^j=|
�j?|
|	�
�dz�ycc}w)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

�Unknownz%d %b %Y)�expired_dater)zn/arz	esm-infrazesm-apps)�pkg_num�serviceT)0r�is_attached�LOG�info�os�path�join�data_dir�MOTD_CONTRACT_STATUS_FILE_NAME�contract_status�contract_remaining_daysrrr�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�name�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,�s�enabled_services_namess
             r$�update_motd_messagesr[;s���$�C�(���'�'���H�H�
5�6�$&�G�G�L�L����j�"@�%�!�%�4�4�M�%�=�=�N�&�=�=�c�B����0�0�6�6��1�1�7�7��$�$�*�*���
	�s�#�'��,��(�8�8�
�)�A�A����#�#�)�)��!�!�'�'���	���w�~�~�6�6�7��!�!�"?�@�F�E
�.�B�B�H�H�	H����w�~�~�6�6�7����)��*�*�4�4�^�D�K�K�-�
L�
��
�	
�@�s
�.�C�C�I�I�	I����w�~�~�6�6�7��6�6��G�	�$�<�<���>�"�J�����4�J����)��2�2�<�<��
��f�'�5����

�		
�^�K
�.�6�6�<�<�	<����G�N�N�3�3�4�����.�c�2�C�C�"
��A�F�F�"
��"
��.�.�0��4�4�%��7����'�/�/���
)�
)�
+��3�3�$��7����'�.�.���a�<����-��)�)�F�2�
��
���-��3�3�=�=�g�F�M�M�#�#�N���	�
���?"
s�>P;c��tt�r	tjtdg�yy#t$r}t
j
|�Yd}~yd}~wwxYw)Nz--force)r�UPDATE_NOTIFIER_MOTD_SCRIPTr�subp�	Exceptionr/�	exception)�excs r$�refresh_motdrb�sJ���)�*�	��K�K�4�i�@�A�+���	��M�M�#����	�s�.�	A�A�A)"�__doc__�loggingr1�os.pathr�uaclientrrrrr�&uaclient.api.u.pro.packages.updates.v1r	rM�-uaclient.api.u.pro.status.enabled_services.v1r
�(uaclient.api.u.pro.status.is_attached.v1rr�uaclient.configr
�uaclient.filesrrr5r]�	getLogger�replace_top_level_logger_name�__name__r/r%�boolr[rb�r&r$�<module>rqs�����	��?�?��L��%�1�!7��<���g���:��:�:�8�D�E��-��-�6f�h�f�4�f�R
r&