+
    g              	          ^ RI t ^ RIt^ RIHtHtHt ^ RIHtHtH	t	H
t
HtHtHtHt Rt. R$OtRtRtRtRt]	P*                  ! 4       t] P.                  ! ]P0                  ! ]4      4      t]! R	R
]3R]3R]3R]3R]3.4      tR R ltR R ltR%R R lltR&R R llt R R lt!R R lt"R t#R R lt$R'R R llt%R  R! lt&R" R# lt'R# )(    N)List
NamedTupleOptional)apiaptevent_logger
exceptionshttpmessagessystemutilz/usr/bin/snapz
proxy.httpzproxy.httpsz/run/snapd.socketz/v2/snaps/{}SnapPackagenameversionrevisionchannel	publisherc                $    V ^8  d   QhR\         /#    returnbool)formats   "//usr/lib/python3/dist-packages/uaclient/snap.py__annotate__r   '   s     9 9D 9    c                 2    R\         P                  ! 4       9   # )z(Returns whether or not snap is installedsnapd)r   get_installed_packages_names r   r   is_snapd_installedr"   '   s    c66888r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   ,   s     I Id Ir   c                     \         ;QJ d$    R \        4        4       F  '       g   K   R# 	  R# ! R \        4        4       4      # )z3Returns whether or not snapd is installed as a snapc              3   >   "   T F  qP                   R 8H  x  K  	  R# 5i)r   Nr   ).0snaps   & r   	<genexpr>/is_snapd_installed_as_a_snap.<locals>.<genexpr>.   s     G1F		W$1Fs   TF)anyget_installed_snapsr!   r   r   is_snapd_installed_as_a_snapr-   ,   s3    3G1D1FG33H3H3G1D1FGHHr   c                    V ^8  d   QhR\         \        ,          R\         \        ,          R\         \        \        ,          ,          RR/# )r   
http_proxyhttps_proxyretry_sleepsr   N)r   strr   float)r   s   "r   r   r   1   sA     "
 "
"
#"
 4;'"
 
	"
r   c                   \        4       '       g   \        P                  R4       R# V '       g	   V'       d4   \        P	                  \
        P                  P                  RR7      4       V '       d,   \        P                  ! RRRRP                  V 4      .VR7       V'       d.   \        P                  ! RRRR	P                  V4      .VR7       R# R# )
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={}r1   zproxy.https={})
r"   LOGdebugeventinfor   SETTING_SERVICE_PROXYr   r   subp)r/   r0   r1   s   &&&r   configure_snap_proxyr>   1   s    " 		JK[

811888HIUHo&<&<Z&HI%	

 UH&6&=&=k&JK%	
 r   c                `    V ^8  d   QhR\         R\        \        \        ,          ,          RR/# )r   protocol_typer1   r   N)r2   r   r   r3   )r   s   "r   r   r   V   s-      &.tE{&;	r   c                    \        4       '       g   \        P                  R4       R# \        P                  ! RRRRP                  V 4      .VR7       R# )ad  
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.{}r7   )r"   r8   r9   r   r=   r   )r@   r1   s   &&r   unconfigure_snap_proxyrC   V   sC     		LM
KK	(J$5$5m$DE!r   c                F    V ^8  d   QhR\         R\        \         ,          /# )r   keyr   )r2   r   )r   s   "r   r   r   k   s     
 
 
# 
r   c                     \         P                  ! RRRV .4      w  rVP                  4       #   \        P                   d     R# i ; i)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)rE   out_s   &  r   get_config_option_valuerL   k   sD    feXs;<yy{++ s   +. AAc                :    V ^8  d   QhR\         \        ,          /# r   )r   r   )r   s   "r   r   r   x   s      T+. r   c                      \         P                  ! . RO4      w  rV P                  4       pVR,          p. pV F4  pVP                  4       ^ ,          pVP	                  \        V4      4       K6  	  V# )r(   :   NN)r(   listz--colorneverz	--unicoderQ   )r   r=   
splitlinessplitappendget_snap_info)rJ   rK   appssnapsliner(   s         r   r,   r,   x   sb    [[BFC >>D8DEzz|A]4()  Lr   c                     \         P                  \        P                  P	                  R R7      4        \
        P                  ! \
        P                  ! 4       4        \        P                  ! . RO\
        P                  R7       R#   \        P                   d*   p \        P                  R\        T 4      4        Rp ? LdRp ? ii ; i  \        P                    d    \        P"                  ! 4       hi ; i)zstandard Ubuntur&   z<Trying to install snapd. Ignoring apt-get update failure: %sNr7   )zapt-getinstallz--assume-yesr   )r:   r;   r   APT_UPDATING_LISTr   r   update_sources_listget_system_sources_filer	   UbuntuProErrorr8   r9   r2   r   r=   APT_RETRIESrI   CannotInstallSnapdError)es    r   install_snapdrb      s    	JJx))006G0HI
 ; ; =>3;	
 $$ 
		JF	
 	

 ++ 300223s#   )B	 (C
 	CCC
+C5c                8    V ^8  d   QhR\         P                  /# )r   progress)r   ProgressWrapper)r   s   "r   r   r      s     
 
!4!4 
r   c                 b    \         P                  ! \        R RR.RR7       R#   \        P                   dv   p\
        P                  ! R\        T4      P                  4       4      '       d<   \        P                  R4       T P                  R\        P                  4        Rp?R# h Rp?ii ; i)	waitr   zseed.loadedTcapturezunknown command .*waitz9Detected version of snapd that does not have wait commandr;   N)r   r=   SNAP_CMDr	   rI   researchr2   lowerr8   warningemitr   SNAPD_DOES_NOT_HAVE_WAIT_CMD)rd   ra   s   & r   run_snapd_wait_cmdrq      s{    	Xvx?N++ 99.A??KKK MM&("G"GHHs    $ B.A)B)(B))B.c                R    V ^8  d   QhR\         R\        \         ,          R\        /# )r   r(   r   classic_confinement_support)r2   r   r   )r   s   "r   r   r      s*      
c] "&r   c                     \         R V .pV'       d   VR.,          pV'       d   VRP                  V4      .,          p\        P                  ! VR\        R7       R# )rZ   z	--classicz--channel={}T)ri   r1   N)rj   r   r   r=   SNAP_INSTALL_RETRIES)r(   r   rs   cmds   &&& r   install_snaprw      sO    
 Y
%C"}%%g.//
KK)r   c                $    V ^8  d   QhR\         /# )r   r(   )r2   )r   s   "r   r   r      s     ; ;s ;r   c                 D    \         P                  ! \        R V .RR7       R# )refreshTrh   N)r   r=   rj   r(   s   &r   refresh_snapr|      s    
KK9d+T:r   c                0    V ^8  d   QhR\         R\        /# )r   r(   r   )r2   r   )r   s   "r   r   r      s        r   c           
         \         P                  V 4      p \        P                  ! \        R V4      pVP
                  ^8w  d   VP
                  R8X  dH   VP                  P                  R/ 4      P                  R4      R8X  d   \        P                  ! V R7      hVP                  P                  R/ 4      P                  R4      p\        P                  ! VR7      h TP                  P                  R/ 4      p\        TP                  RR	4      TP                  R
R	4      TP                  RR	4      TP                  RR	4      TP                  R/ 4      P                  RR	4      R7      #   \         d    \        P                  ! 4       hi ; i)GETi  resultkindzsnap-not-foundr{   message)errorr    r   r   r   r   username)r   r   r   r   r   )SNAPD_SNAPS_APIr   r
   unix_socket_requestSNAPD_SOCKET_PATHcode	json_dictrG   r	   SnapNotInstalledErrorUnexpectedSnapdAPIErrorConnectionRefusedErrorSnapdAPIConnectionRefusedr   )r(   urlresp	error_msg	snap_infos   &    r   rU   rU      sM   

 
 
&C5''(95#F99		S NN&&x488@#$ !66DAA NN..x<@@K	 88yII  ""8R0I]]62&i,z2.i,--R044ZD 	 " 522445s   CE+ +!F)g      ?g      ?g      @)NNN)N)NF)(loggingrk   typingr   r   r   uaclientr   r   r   r	   r
   r   r   r   rj   ru   HTTP_PROXY_OPTIONHTTPS_PROXY_OPTIONr   r   get_event_loggerr:   	getLoggerreplace_top_level_logger_name__name__r8   r2   r   r"   r-   r>   rC   rL   r,   rb   rq   rw   r|   rU   r!   r   r   <module>r      s     	 - -	 	 	 &   " '  %%'::8DE 		C	S	C	c	9
I
"
J*
3$
(;r   