Ë
    GKÕi  ã            	       ó   — d dl Z d dlZd dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZ dZg d¢ZdZdZdZd	Z e	j*                  «       Z e j.                   ej0                  e«      «      Z ed
defdefdefdefdefg«      Zdefd„Zdefd„Z	 	 	 d$dee   dee   deee       ddfd„Z!	 d%dedeee       ddfd„Z"dedee   fd„Z#dee   fd„Z$d„ Z%dejL                  fd„Z'	 	 d&dedee   d efd!„Z(defd"„Z)dedefd#„Z*y)'é    N)ÚListÚ
NamedTupleÚOptional)ÚapiÚaptÚevent_loggerÚ
exceptionsÚhttpÚmessagesÚsystemÚutilz/usr/bin/snap)g      à?g      ð?g      @z
proxy.httpzproxy.httpsz/run/snapd.socketz/v2/snaps/{}ÚSnapPackageÚnameÚversionÚrevisionÚchannelÚ	publisherÚreturnc                  ó.   — dt        j                  «       v S )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Ð8r   c                  ó6   — t        d„ t        «       D «       «      S )z3Returns whether or not snapd is installed as a snapc              3   ó:   K  — | ]  }|j                   d k(  –— Œ y­w)r   N©r   )Ú.0Úsnaps     r   ú	<genexpr>z/is_snapd_installed_as_a_snap.<locals>.<genexpr>.   s   è ø€ ÒG¨�—	‘	˜WÕ$ÑGùs   ‚)ÚanyÚget_installed_snapsr   r   r   Úis_snapd_installed_as_a_snapr$   ,   s   € äÑGÔ1DÓ1FÔGÓHÐHr   Ú
http_proxyÚhttps_proxyÚretry_sleepsc                 ód  — t        «       st        j                  d«       y| s|r3t        j	                  t
        j                  j                  d¬«      «       | r*t        j                  ddddj                  | «      g|¬«       |r+t        j                  dddd	j                  |«      g|¬«       yy)
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'   zproxy.https={})
r   ÚLOGÚdebugÚeventÚinfor   ÚSETTING_SERVICE_PROXYÚformatr   Úsubp)r%   r&   r'   s      r   Úconfigure_snap_proxyr3   1   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        «       st        j                  d«       yt        j                  ddddj                  | «      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   zproxy.{}r+   )r   r,   r-   r   r2   r1   )r4   r'   s     r   Úunconfigure_snap_proxyr7   V   s@   € ô ÔÜ�	‰	ÐLÔMØÜ
‡K�KØ	�˜( J×$5Ñ$5°mÓ$DÐEØ!ör   Úkeyc                 óŽ   — 	 t        j                  ddd| g«      \  }}|j                  «       S # t        j                  $ r Y yw xY w)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?   k   sF   € ðÜ—‘˜f e¨X°sÐ;Ó<‰ˆˆQØ�y‰y‹{ÐøÜ×+Ñ+ò Ùðús   ‚+. ®AÁAc                  óÐ   — t        j                  g d¢«      \  } }| j                  «       }|dd  }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         r   r#   r#   x   sk   € Ü�[‰[ÚBó�F€Cˆð �>‰>Ó€DØ��ˆ8€DØ€EØò *ˆØ�z‰z‹|˜A‰ˆØ�‰”] 4Ó(Õ)ð*ð €Lr   c                  óÞ  — t         j                  t        j                  j	                  d¬«      «       	 t        j                  t        j                  «       «       	 t        j                  g d¢t
        j                  ¬«       y # t        j                  $ r)} t        j                  dt        | «      «       Y d } ~ Œ`d } ~ ww xY w# t        j                   $ r t        j"                  «       ‚w xY w)Nzstandard Ubuntur   z<Trying to install snapd. Ignoring apt-get update failure: %s)zapt-getÚinstallz--assume-yesr   r+   )r.   r/   r   ÚAPT_UPDATING_LISTr1   r   Ú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  — 	 t        j                  t        dddgd¬«       y # t        j                  $ rn}t        j                  dt        |«      j                  «       «      r6t        j                  d«       | j                  dt        j                  «       n‚ Y d }~y d }~ww xY w)	NÚwaitr   zseed.loadedT©Úcapturezunknown 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)rV   rT   s     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                 óŒ   — t         d| g}|r|dgz  }|r|dj                  |«      gz  }t        j                  |dt        ¬«       y )NrL   z	--classicz--channel={}T)rZ   r'   )r[   r1   r   r2   ÚSNAP_INSTALL_RETRIES)r    r   rc   Úcmds       r   Úinstall_snaprg   ¥   sO   € ô
 �Y Ð
%€Cá"Ø�ˆ}ÑˆáØ�×%Ñ% gÓ.Ð/Ñ/ˆä
‡K�KØØÜ)ör   c                 ó@   — t        j                  t        d| gd¬«       y )NÚrefreshTrY   )r   r2   r[   ©r    s    r   Úrefresh_snaprk   ¹   s   € Ü
‡K�K”˜9 dÐ+°TÖ:r   c           
      ó  — t         j                  | «      }	 t        j                  t        d|«      }|j
                  dk7  r”|j
                  dk(  rD|j                  j                  di «      j                  d«      dk(  rt        j                  | ¬«      ‚|j                  j                  di «      j                  d«      }t        j                  |¬	«      ‚	 |j                  j                  di «      }t        |j                  d
d«      |j                  dd«      |j                  dd«      |j                  dd«      |j                  di «      j                  dd«      ¬«      S # t        $ r t        j                  «       ‚w xY w)NÚGETéÈ   i”  ÚresultÚkindzsnap-not-foundrj   Úmessage)Úerrorr   Ú r   r   r   r   Úusername)r   r   r   r   r   )ÚSNAPD_SNAPS_APIr1   r
   Úunix_socket_requestÚSNAPD_SOCKET_PATHÚcodeÚ	json_dictr:   r	   ÚSnapNotInstalledErrorÚUnexpectedSnapdAPIErrorÚConnectionRefusedErrorÚSnapdAPIConnectionRefusedr   )r    ÚurlÚrespÚ	error_msgÚ	snap_infos        r   rG   rG   ½   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\   Útypingr   r   r   Úuaclientr   r   r   r	   r
   r   r   r   r[   re   ÚHTTP_PROXY_OPTIONÚHTTPS_PROXY_OPTIONrw   ru   Úget_event_loggerr.   Ú	getLoggerÚreplace_top_level_logger_nameÚ__name__r,   rQ   r   Úboolr   r$   Úfloatr3   r7   r?   r#   rU   ÚProgressWrapperrb   rg   rk   rG   r   r   r   ú<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   