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

��g�	��ddlZddlZddlmZmZmZddlmZmZm	Z	m
Z
mZmZm
Z
mZdZgd�ZdZdZdZd	Ze	j*�Zej.ej0e��Zed
defdefd
efdefdefg�Zdefd�Zdefd�Z			d$deedeedeee ddfd�Z!	d%dedeee ddfd�Z"dedeefd�Z#deefd�Z$d�Z%dejLfd�Z'		d&dedeed efd!�Z(defd"�Z)dedefd#�Z*y)'�N)�List�
NamedTuple�Optional)�api�apt�event_logger�
exceptions�http�messages�system�utilz
/usr/bin/snap)g�?g�?g@z
proxy.httpzproxy.httpsz/run/snapd.socketz/v2/snaps/{}�SnapPackage�name�version�revision�channel�	publisher�returnc�.�dtj�vS)z(Returns whether or not snap is installed�snapd)r�get_installed_packages_names���//usr/lib/python3/dist-packages/uaclient/snap.py�is_snapd_installedr's���c�6�6�8�8�8rc�6�td�t�D��S)z3Returns whether or not snapd is installed as a snapc3�:K�|]}|jdk(���y�w)rN�r)�.0�snaps  r�	<genexpr>z/is_snapd_installed_as_a_snap.<locals>.<genexpr>.s����G���	�	�W�$�G�s�)�any�get_installed_snapsrrr�is_snapd_installed_as_a_snapr$,s���G�1D�1F�G�H�Hr�
http_proxy�https_proxy�retry_sleepsc�d�t�stjd�y|s|r3tj	t
jjd���|r*tjddddj|�g|��|r+tjdddd	j|�g|��yy)
a
    Configure snap to use http and https proxies.

    :param http_proxy: http proxy to be used by snap. If None, it will
                       not be configured
    :param https_proxy: https proxy to be used by snap. If None, it will
                        not be configured
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    z6Skipping configure snap proxy. snapd is not installed.Nr )�service�setrz
proxy.http={}�r'zproxy.https={})
r�LOG�debug�event�infor�SETTING_SERVICE_PROXY�formatr�subp)r%r&r's   r�configure_snap_proxyr31s���"���	�	�J�K���[�
�
�
�8�1�1�8�8��8�H�I�����
�U�H�o�&<�&<�Z�&H�I�%�	
�
����
�U�H�&6�&=�&=�k�&J�K�%�	
�r�
protocol_typec��t�stjd�ytjddddj|�g|��y)a�
    Unset snap configuration settings for http and https proxies.

    :param protocol_type: String either http or https
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    z8Skipping unconfigure snap proxy. snapd is not installed.Nr �unsetrzproxy.{}r+)rr,r-rr2r1)r4r's  r�unconfigure_snap_proxyr7Vs@�����	�	�L�M��
�K�K�	��(�J�$5�$5�m�$D�E�!�r�keyc��	tjddd|g�\}}|j�S#tj$rYywxYw)z�
    Gets the config value from snap.
    :param protocol: can be any valid snap config option
    :return: the value of the snap config option, or None if not set
    r �getrN)rr2�stripr	�ProcessExecutionError)r8�out�_s   r�get_config_option_valuer?ksF������f�e�X�s�;�<���Q��y�y�{����+�+����s�+.�A�Ac���tjgd��\}}|j�}|dd}g}|D]/}|j�d}|j	t|���1|S)N)r �listz--color�neverz	--unicoderB�r)rr2�
splitlines�split�append�
get_snap_info)r=r>�apps�snaps�liner s      rr#r#xsk��
�[�[�B��F�C���>�>��D����8�D��E��*���z�z�|�A���
���]�4�(�)�*��Lrc���tjtjj	d���	tjtj��	tjgd�t
j��y#tj$r)}tjdt|��Yd}~�`d}~wwxYw#tj $rtj"��wxYw)Nzstandard Ubunturz<Trying to install snapd. Ignoring apt-get update failure: %s)zapt-get�installz--assume-yesrr+)r.r/r�APT_UPDATING_LISTr1r�update_sources_list�get_system_sources_filer	�UbuntuProErrorr,r-�strrr2�APT_RETRIESr<�CannotInstallSnapdError)�es r�
install_snapdrU�s���	�J�J�x�)�)�0�0�6G�0�H�I�
����� ;� ;� =�>�3����;����	
��
�$�$�
��	�	�J���F�	
�	
��
���+�+�3��0�0�2�2�3�s#�'B�'C�C�B<�<C�(C,�progressc�L�	tjtdddgd��y#tj$rn}tjdt|�j��r6tjd�|jdtj�n�Yd}~yd}~wwxYw)	N�waitrzseed.loadedT��capturezunknown command .*waitz9Detected version of snapd that does not have wait commandr/)rr2�SNAP_CMDr	r<�re�searchrQ�lowerr,�warning�emitr�SNAPD_DOES_NOT_HAVE_WAIT_CMD)rVrTs  r�run_snapd_wait_cmdrb�s{��	����X�v�x��?��N���+�+��
�9�9�.��A�����?��K�K�K�
�
�M�M�&�(�"G�"G�H��
I���s�"�B#�A$B�B#r �classic_confinement_supportc��td|g}|r|dgz
}|r|dj|�gz
}tj|dt��y)NrLz	--classicz--channel={}T)rZr')r[r1rr2�SNAP_INSTALL_RETRIES)r rrc�cmds    r�install_snaprg�sO��
�Y��
%�C�"���}������%�%�g�.�/�/��
�K�K���)�rc�@�tjtd|gd��y)N�refreshTrY)rr2r[�r s r�refresh_snaprk�s��
�K�K��9�d�+�T�:rc
��tj|�}	tjtd|�}|j
dk7r�|j
dk(rD|jjdi�jd�dk(rtj|���|jjdi�jd�}tj|�	��	|jjdi�}t|jd
d�|jdd�|jd
d�|jdd�|jdi�jdd���S#t$rtj��wxYw)N�GET��i��result�kindzsnap-not-foundrj�message)�errorr�rrrr�username)rrrrr)�SNAPD_SNAPS_APIr1r
�unix_socket_request�SNAPD_SOCKET_PATH�code�	json_dictr:r	�SnapNotInstalledError�UnexpectedSnapdAPIError�ConnectionRefusedError�SnapdAPIConnectionRefusedr)r �url�resp�	error_msg�	snap_infos     rrGrG�sM��
�
 �
 ��
&�C�5��'�'�(9�5�#�F���9�9����	�	�S� ��N�N�&�&�x��4�8�8��@�#�$�!�6�6�D�A�A� �N�N�.�.�x��<�@�@��K�	� �8�8�y�I�I�����"�"�8�R�0�I��
�]�]�6�2�
&��
�
�i��,����z�2�.��
�
�i��,��-�-��R�0�4�4�Z��D����	"�5��2�2�4�4�5�s�B>E"�"F)NNN)N)NF)+�loggingr\�typingrrr�uaclientrrrr	r
rrr
r[re�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONrwru�get_event_loggerr.�	getLogger�replace_top_level_logger_name�__name__r,rQr�boolrr$�floatr3r7r?r#rU�ProgressWrapperrbrgrkrGrrr�<module>r�s����	�-�-�	�	�	���&�� ��"��'�� ��%��%�%�'���g���:��:�:�8�D�E����	��
�	�C��	�S��	�C��	�c���	��9�D�9�
I�d�I�!%�!%�*.�"
���
�"
��#��"
��4��;�'�"
�
�	"
�L?C����&.�t�E�{�&;��	��*
��
��#��
��T�+�.��3�$
��!4�!4�
�"�(-��

��
�c�]��"&��(;�s�;�����r