o >f @sddlZddlZddlZddlZddlZddlmZmZm Z ddl m Z m Z m Z mZmZmZmZdZgdZdZdZdZd Ze ZeeeZed d efd efd efdefdefgZde fddZ!de fddZ"   d0de ede ede ee#ddfddZ$ d1dede ee#ddfddZ%dede efddZ&deefd d!Z'd"d#Z(d$e j)fd%d&Z*  'd2d(ede ed)e fd*d+Z+d(efd,d-Z,d(edefd.d/Z-dS)3N)List NamedTupleOptional)apiapt event_logger exceptionsmessagessystemutilz /usr/bin/snap)g?g?g@z proxy.httpz proxy.httpsz/run/snapd.socketz /v2/snaps/{} SnapPackagenameversionrevisionchannel publisherreturncCs dtvS)z(Returns whether or not snap is installedsnapd)rget_installed_packages_namesrr//usr/lib/python3/dist-packages/uaclient/snap.pyis_snapd_installed!s rcCstddtDS)z3Returns whether or not snapd is installed as a snapcss|]}|jdkVqdS)rNr ).0snaprrr (sz/is_snapd_installed_as_a_snap..)anyget_installed_snapsrrrris_snapd_installed_as_a_snap&sr http_proxy https_proxy retry_sleepscCsxts tddS|s|rttjjdd|r(tj dddd|g|d|r:tj dddd |g|ddSdS) 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)servicesetr z proxy.http={}r!zproxy.https={}) rLOGdebugeventinfor SETTING_SERVICE_PROXYformatr subp)rr r!rrrconfigure_snap_proxy+s   r, protocol_typecCs4ts tddStjdddd|g|ddS)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.Nrunsetr zproxy.{}r$)rr%r&r r+r*)r-r!rrrunconfigure_snap_proxyPs  r/keycCs8ztddd|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 rgetr N)r r+striprProcessExecutionError)r0out_rrrget_config_option_valuees  r6cCsRtgd\}}|}|dd}g}|D]}|d}|t|q|S)N)rlistz--colorneverz --unicoder8r)r r+ splitlinessplitappend get_snap_info)r4r5appssnapslinerrrrrrs  rc Csttjjddz ttWntj y.}zt dt |WYd}~nd}~wwz t jgdtjdWdStjyHtw)Nzstandard Ubunturzsz$   &