
    x[h              
           U d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dg d	ed
gdZeed<    ej                   e      Zd Zd Zd Zd Zd Zdede	dededdf
dZy)z6zypper_add_repo: Add zypper repositories to the system    N)util)Cloud)Config)
MetaSchema)
PER_ALWAYScc_zypper_add_repo)opensusezopensuse-microoszopensuse-tumbleweedzopensuse-leapsle_hpcz	sle-microsleszypper)iddistros	frequencyactivate_by_schema_keysmetac                 *    | j                  dd      } | S )N _)replace)repo_ids    E/usr/lib/python3/dist-packages/cloudinit/config/cc_zypper_add_repo.py_canonicalize_idr   %   s    ooc3'GN    c                     t        | t              r| rdS dS t        | t        t        f      r(dj	                  | D cg c]  }t        |       c}      S t        | t              st        |       S | S c c}w )N   r   z
    )
isinstanceboollisttuplejoin_format_repo_valuestr)valvs     r   r!   r!   *   se    #tqQ#e}%}}SA03ABBc33xJ Bs   A2c                     t        j                         }i || <   |j                         D ]  \  }}t        |      ||    |<    |j	                         }dj                  |      S )N
)	configobj	ConfigObjitemsr!   writer    )r   repo_configto_bekr$   liness         r   _format_repository_configr/   5   sf    !EE'N!!# 21 /q1gq2 KKME99Ur   c                    | syi }t        |       D ]  \  }}t        ddg      j                  t        |            }|r't        j	                  d|dj                  |             U|j                  d      }t        |      }t        j                  j                  |d|z        }t        j                  j                  |      rt        j                  d||       ||v rt        j                  d||       t        d	 |j                         D              }	d
D ]  }
|
|	vsd|	|
<    ||	f||<   ! |j                         D ]-  \  }}t        ||d         }t        j                   |d   |       / y)zWrite the user-provided repo definition files
    @param repos: A list of repo dictionary objects provided by the user's
        cloud config.
    @param repo_base_path: The directory path to which repo definitions are
        written.
    Nr   baseurlz;Repo config at index %d is missing required config keys: %s,z%s.repoz)Skipping repo %s, file %s already exists!z*Skipping repo %s, file %s already pending!c              3      K   | ]>  \  }}|r7|d k7  r2|j                         j                         j                  dd      |f @ yw)r   -r   N)lowerstripr   ).0r-   r$   s      r   	<genexpr>z_write_repos.<locals>.<genexpr>i   sD      
1Q$Y WWY__&&sC0!4
s   AA)enabledautorefresh1r   )	enumerateset
differenceLOGwarningr    getr   ospathexistsinfodictr)   r/   r   
write_file)reposrepo_base_pathvalid_reposindexuser_repo_configmissing_keysr   canon_repo_idrepo_fn_pthr+   field	repo_data	repo_blobs                r   _write_reposrT   A   s    K#,U#3 (:D),-88=M9NOKKM&
 "&&t,(1ggll>93NO77>>+&HH;
 #HH<
   
(..0
 
 0 	)EK'%(E"	) !,[9GQ(:T *//1 1-gy}E		!i01r   c                 Z   | syd}t        j                  |      }dg}| j                         D ]@  \  }}|dk(  rd}|dz  }t        j	                  |       (|s+|j                  |d|       B t        |      dkD  r|d	j                  |      z   }n|}t        j                  ||       y)
z@Write to the default zypp configuration file /etc/zypp/zypp.confNz/etc/zypp/zypp.confz# Added via cloud.cfg	configdirz5Changing the location of the zypper configuration is z+not supported, skipping "configdir" setting=r   r&   )	r   load_text_filer)   r@   rA   appendlenr    rH   )zypper_configzypp_configzypp_conf_contentnew_settingssettingvaluemsg
new_configs           r   _write_zypp_configrc   {   s    'K++K8+,L'--/ <k!IC@@CKK7E :;< <1&<)@@
&
OOK,r   namecfgcloudargsreturnc                 "   |j                  d      }|st        j                  d|        y |j                  d      }|st        j                  d|        y |j                  di       }|j                  dd      }t        |       t	        ||       y )Nr   zBSkipping module named %s, no 'zypper' relevant configuration foundrI   z8Skipping module named %s, no 'repos' configuration foundconfigreposdirz/etc/zypp/repos.d/)rB   r@   debugrc   rT   )rd   re   rf   rg   zypper_sectionrI   r[   rJ   s           r   handlern      s    WWX&N		8	

 	w'E		F	
 	"&&x4M"&&z3GHN}%'r   )__doc__loggingrC   r'   	cloudinitr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr   r   __annotations__	getLogger__name__r@   r   r!   r/   rT   rc   r"   r   rn    r   r   <module>rz      s    =  	   ! # . )   (zj  g!
	71t-,( (6 (% (t ( (r   