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: //lib/python3/dist-packages/uaclient/__pycache__/snap.cpython-310.pyc
o

nHJe_�	@s�ddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZdZgd�ZdZdZdZd	Ze��Ze�e�e��Zed
defdefd
efdefdefg�Zdefdd�Z defdd�Z!			d-de	ede	ede	ee"ddfdd�Z#	d.dede	ee"ddfdd�Z$dede	efdd�Z%deefd d!�Z&d"d#�Z'd$d%�Z(		&d/d'ede	ed(efd)d*�Z)d'edefd+d,�Z*dS)0�N)�List�
NamedTuple�Optional)�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�returncCsdt��vS)z(Returns whether or not snap is installed�snapd)r�get_installed_packages_names�rr�//usr/lib/python3/dist-packages/uaclient/snap.py�is_snapd_installed!srcCstdd�t�D��S)z3Returns whether or not snapd is installed as a snapcss�|]}|jdkVqdS)rN�r)�.0�snaprrr�	<genexpr>(s�z/is_snapd_installed_as_a_snap.<locals>.<genexpr>)�any�get_installed_snapsrrrr�is_snapd_installed_as_a_snap&sr�
http_proxy�https_proxy�retry_sleepscCsxt�s
t�d�dS|s|rt�tjjdd��|r(tj	dddd�|�g|d�|r:tj	dddd	�|�g|d�dSdS)
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)rrr rrr�configure_snap_proxy+s 
�
��r+�
protocol_typecCs4t�s
t�d�dStjdddd�|�g|d�dS)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	r*r))r,r rrr�unconfigure_snap_proxyPs

�r.�keycCs8zt�ddd|g�\}}|��WStjyYdSw)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	r*�stripr�ProcessExecutionError)r/�out�_rrr�get_config_option_valuees
�r5cCsRt�gd��\}}|��}|dd�}g}|D]}|��d}|�t|��q|S)N)r�listz--color�neverz	--unicoder7�r)r	r*�
splitlines�split�append�
get_snap_info)r3r4�apps�snaps�linerrrrrrs�rc
Cs�t�tjjdd��zt�d�Wntjy,}zt	�
dt|��WYd}~nd}~wwz
tj
gd�tjd�WdStjyFt���w)Nzstandard Ubunturz/etc/apt/sources.listz<Trying to install snapd. Ignoring apt-get update failure: %s)zapt-get�installz--assume-yesrr#)r&r'r�APT_UPDATING_LISTr)r�update_sources_listr�UbuntuProErrorr$r%�strr	r*�APT_RETRIESr2�CannotInstallSnapdError��errr�
install_snapd�s$�����rIc
Cstztjtdddgdd�WdStjy9}zt�dt|����r-t	�
d�t�t
j�n�WYd}~dSd}~ww)N�waitr	zseed.loadedT)�capturezunknown command .*waitz9Detected version of snapd that does not have wait command)r	r*�SNAP_CMDrr2�re�searchrD�lowerr$�warningr&r'r�SNAPD_DOES_NOT_HAVE_WAIT_CMDrGrrr�run_snapd_wait_cmd�s����rRFr�classic_confinement_supportcCs@td|g}|r|dg7}|r|d�|�g7}tj|dtd�dS)Nr@z	--classicz--channel={}T)rKr )rLr)r	r*�SNAP_INSTALL_RETRIES)rrrS�cmdrrr�install_snap�s


�rVc

Cs�t�tjtj�}|�t�tj�d�}||_t	�
|�}z~zh|�dt	�
|��|��}|�
��d�}zt�|�}Wn tjyX}ztjd|||d�tjd�
|�|d��d}~ww|jdkr�|jd	krt|�d
i��d�dkrttj|d
��|�d
i��d�}tj|d��Wnty�t���wW|��|��n	|��|��w|�d
i�}	t|	�dd�|	�dd�|	�dd�|	�dd�|	�di��dd�d�S)N�	localhost�GETzutf-8z]JSONDecodeError while parsing result of snap api call to %s, returning None. output was: "%s")�exc_infozSNAPD API {})�sourcer3��i��result�kindzsnap-not-found)r�message)�errorr�r
rrr�username)rr
rrr)�socket�AF_UNIX�SOCK_STREAM�connect�SNAPD_SOCKET_PATH�http�client�HTTPConnection�sock�SNAPD_SNAPS_APIr)�request�getresponse�read�decode�json�loads�JSONDecodeErrorr$rPr�InvalidJson�statusr0�SnapNotInstalledError�UnexpectedSnapdAPIError�ConnectionRefusedError�SnapdAPIConnectionRefused�closer)
r�	snap_sock�conn�url�responser3�datarH�	error_msg�	snap_inforrrr<�s\

�
���

�
��
�




�r<)NNN)N)NF)+�http.clientrgrp�loggingrMrb�typingrrr�uaclientrrrrr	r
rLrT�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONrfrk�get_event_loggerr&�	getLogger�replace_top_level_logger_name�__name__r$rDr�boolrr�floatr+r.r5rrIrRrVr<rrrr�<module>sx �����
�
�&��
�
�
���
�