
    x[hl              
           % S r SSKrSSKrSSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  \R                   " \5      rS	S
/\S/S.r\\S'   SrS rS rS\S\	S\S\SS4
S jrg)z<Snap: Install, configure and manage snapd and snap packages.    N)subputil)Cloud)Config)
MetaSchema)PER_INSTANCE)prepend_base_commandcc_snapubuntusnap)iddistros	frequencyactivate_by_schema_keysmetac                    U (       d  g[         R                  S5        [        U [        5      (       a  U R	                  5       n O-[        U [
        5      (       d  [        SR                  U S95      e[        SU/nSR                  U 5      nU  H+  n[         R                  SUR                  S5      SS	 5        M-     [        R                  " XR                  S
5      5        [        R                  " USS9  g)a	  Import list of assertions.

Import assertions by concatenating each assertion into a
string separated by a '\n'.  Write this string to a instance file and
then invoke `snap ack /path/to/file` and check for errors.
If snap exits 0, then all assertions are imported.
Nz'Importing user-provided snap assertionsz8assertion parameter was not a list or dict: {assertions})
assertionsack
zSnap acking: %sr      zutf-8T)capture)LOGdebug
isinstancedictvalueslist	TypeErrorformatSNAP_CMDjoinsplitr   
write_fileencoder   )r   assertions_filesnap_cmdcombinedasrts        :/usr/lib/python3/dist-packages/cloudinit/config/cc_snap.pyadd_assertionsr*      s     II78*d##&&(

D))FMM% N 
 	
 %1Hyy$H		#TZZ%5a%:;  	OOO__W%=>IIh%    c                    U (       d  g[         R                  S5        [        U [        5      (       a.  [	        U R                  5       5       VVs/ s H  u  pUPM	     n nnO-[        U [        5      (       d  [        SR                  U S95      e[        SU 5      n/ nU H(  n[        U[        5      n [        R                  " XVS9  M*     U(       a5  SR                  US9n[        R                  " [         U5        [!        U5      egs  snnf ! [        R                   a%  nUR                  [        U5      5         SnAM  SnAff = f)	a4  Run the provided commands provided in snap:commands configuration.

Commands are run individually. Any errors are collected and reported
after attempting all commands.

@param commands: A list or dict containing commands to run. Keys of a
    dict will be used to order the commands provided as dict values.
Nz#Running user-provided snap commandsz5commands parameter was not a list or dict: {commands})commandsr   )shellz.Failures running snap commands:
{cmd_failures})cmd_failures)r   r   r   r   sorteditemsr   r   r   r	   strr   ProcessExecutionErrorappendr   logexcRuntimeError)	r-   _vfixed_snap_commandsr/   commandr.   emsgs	            r)   run_commandsr=   ;   s&    II34(D!!"()9":;":$!A":;$''CJJ! K 
 	
 /vx@L&7C(	(IIg+ ' ?FF% G 
 	C3 # < )) 	(A''	(s   D2DE!EEnamecfgcloudargsreturnc                 j   UR                  S0 5      nU(       d  [        R                  SU 5        g [        R                  " U5        [        UR                  S/ 5      [        R                  R                  UR                  R                  5       S5      5        [        UR                  S/ 5      5        g )Nr   z8Skipping module named %s, no 'snap' key in configurationr   zsnapd.assertionsr-   )getr   r   r   wait_for_snap_seededr*   ospathr!   pathsget_ipath_curr=   )r>   r?   r@   rA   cfgins        r)   handlerK   b   s    GGFBE		F	
 	e$		,#
U[[..02DE :r*+r+   )__doc__loggingrF   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr   cloudinit.subpr	   	getLogger__name__r   r   __annotations__r    r*   r=   r2   r   rK    r+   r)   <module>rX      s   
 C  	   ! # . + /! z &x	j  &<$ N, ,6 ,% ,t , ,r+   