3
 ag                 @   s   d dl mZmZ d dlZd dlmZmZmZ dZdddgZ	dZ
d	Zed
ddZdee ee eee  ddddZdeeee  ddddZeee dddZdS )    )ListOptionalN)aptstatusutilz/usr/bin/snapg      ?g      ?g      @z
proxy.httpzproxy.https)returnc               C   s   dt j kS )z(Returns whether or not snap is installedZsnapd)r   get_installed_packages r	   r	   //usr/lib/python3/dist-packages/uaclient/snap.pyis_installed   s    r   )
http_proxyhttps_proxyretry_sleepsr   c             C   s|   t jtstjdjt dS | s&|r8ttjjdd | rXt j	ddddj| g|d |rxt j	dddd	j|g|d dS )
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.
    z1Skipping configure snap proxy. {} does not exist.Nsnap)servicesetsystemzproxy.http={})r   zproxy.https={})
r   whichSNAP_CMDloggingdebugformatprintr   MESSAGE_SETTING_SERVICE_PROXYsubp)r   r   r   r	   r	   r
   configure_snap_proxy   s    
r   )protocol_typer   r   c             C   s>   t jtstjdjt dS t jddddj| g|d dS )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.
    z3Skipping unconfigure snap proxy. {} does not exist.Nr   Zunsetr   zproxy.{})r   )r   r   r   r   r   r   r   )r   r   r	   r	   r
   unconfigure_snap_proxy;   s    
r   )keyr   c             C   s:   yt jddd| g\}}|j S  t jk
r4   dS X dS )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   stripProcessExecutionError)r   out_r	   r	   r
   get_config_option_valueT   s
    r$   )NNN)N)typingr   r   r   uaclientr   r   r   r   ZSNAP_INSTALL_RETRIESHTTP_PROXY_OPTIONHTTPS_PROXY_OPTIONboolr   strfloatr   r   r$   r	   r	   r	   r
   <module>   s   
  &