%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/__pycache__/snap.cpython-312.pyc

�

��>f��	��ddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZmZdZgd�ZdZdZdZd	Ze
j0�Zej4ej6e��Zed
defdefd
efdefdefg�Zde fd�Z!de fd�Z"			d$de	ede	ede	ee#ddfd�Z$	d%dede	ee#ddfd�Z%dede	efd�Z&deefd�Z'd�Z(dejRfd�Z*		d&dede	ed e fd!�Z+defd"�Z,dedefd#�Z-y)'�N)�List�
NamedTuple�Optional)�api�apt�event_logger�
exceptions�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�setrz
proxy.http={}�r&zproxy.https={})
r�LOG�debug�event�infor
�SETTING_SERVICE_PROXY�formatr�subp)r$r%r&s   r�configure_snap_proxyr2+s���"���	�	�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�unsetrzproxy.{}r*)rr+r,rr1r0)r3r&s  r�unconfigure_snap_proxyr6Ps@�����	�	�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�getrN)rr1�stripr	�ProcessExecutionError)r7�out�_s   r�get_config_option_valuer>esF������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	--unicoderA�r)rr1�
splitlines�split�append�
get_snap_info)r<r=�apps�snaps�liners      rr"r"rsk��
�[�[�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_LISTr0r�update_sources_list�get_system_sources_filer	�UbuntuProErrorr+r,�strrr1�APT_RETRIESr;�CannotInstallSnapdError)�es r�
install_snapdrT�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�waitrzseed.loadedT��capturezunknown command .*waitz9Detected version of snapd that does not have wait commandr.)rr1�SNAP_CMDr	r;�re�searchrP�lowerr+�warning�emitr
�SNAPD_DOES_NOT_HAVE_WAIT_CMD)rUrSs  r�run_snapd_wait_cmdra�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)NrKz	--classicz--channel={}T)rYr&)rZr0rr1�SNAP_INSTALL_RETRIES)rrrb�cmds    r�install_snaprf�sO��
�Y��
%�C�"���}������%�%�g�.�/�/��
�K�K���)�rc�@�tjtd|gd��y)N�refreshTrX)rr1rZ�rs r�refresh_snaprj�s��
�K�K��9�d�+�T�:rc
��tjtjtj�}|jt�t
jjd�}||_tj|�}	|jdtj|��|j�}|j�jd�}	tj |�}|j,dk7r�|j,d	k(r:|j/d
i�j/d�dk(rt)j0|�
��|j/d
i�j/d�}t)j2|���	|j9�|j9�|j/d
i�}	t;|	j/dd�|	j/dd�|	j/dd�|	j/dd�|	j/di�j/dd���S#tj"$rD}t$j'd|||��t)j*dj|�|���d}~wwxYw#t4$rt)j6��wxYw#|j9�|j9�wxYw)N�	localhost�GETzutf-8z]JSONDecodeError while parsing result of snap api call to %s, returning None. output was: "%s")�exc_infozSNAPD API {})�sourcer<��i��result�kindzsnap-not-foundri�message)�errorr�rrrr�username)rrrrr)�socket�AF_UNIX�SOCK_STREAM�connect�SNAPD_SOCKET_PATH�http�client�HTTPConnection�sock�SNAPD_SNAPS_APIr0�request�getresponse�read�decode�json�loads�JSONDecodeErrorr+r^r	�InvalidJson�statusr9�SnapNotInstalledError�UnexpectedSnapdAPIError�ConnectionRefusedError�SnapdAPIConnectionRefused�closer
)
r�	snap_sock�conn�url�responser<�datarS�	error_msg�	snap_infos
          rrFrF�s;���
�
�f�n�n�f�.@�.@�A�I�
���'�(��;�;�%�%�k�2�D��D�I�
�
 �
 ��
&�C�"����U�O�2�2�4�8�9��#�#�%���m�m�o�$�$�W�-��	��:�:�c�?�D��?�?�c�!����3�&��H�H�X�r�*�.�.�v�6�:J�J� �6�6�D�A�A� �H�H�X�r�2�6�6�y�A�	� �8�8�y�I�I�"�	
�
�
����������2�&�I��
�]�]�6�2�
&��
�
�i��,����z�2�.��
�
�i��,��-�-��R�0�4�4�Z��D����=�#�#�
	��K�K�3����
�
��(�(�%�,�,�S�1�s��
��
	��."�5��2�2�4�4�5��	
�
�
������s>�AI:�H �.BI:� I7�3?I2�2I7�7I:�:J�J�"J=)NNN)N)NF).�http.clientr|r��loggingr[rw�typingrrr�uaclientrrrr	r
rrrZrd�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONr{r��get_event_loggerr-�	getLogger�replace_top_level_logger_name�__name__r+rPr
�boolrr#�floatr2r6r>r"rT�ProgressWrapperrarfrjrFrrr�<module>r�s������	�
�-�-�O�O�O���&�� ��"��'�� ��%��%�%�'���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�;�3��3��3r

Zerion Mini Shell 1.0