o
    x[h¼  ã                
   @   sÊ   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 e¡Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdede	dededdf
dd„ZdS )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                 C   s   |   dd¡} | S )Nú Ú_)Úreplace)Úrepo_id© r   úE/usr/lib/python3/dist-packages/cloudinit/config/cc_zypper_add_repo.pyÚ_canonicalize_id%   s   r   c                 C   sN   t | tƒr| r	dS dS t | ttfƒrd dd„ | D ƒ¡S t | tƒs%t| ƒS | S )Né   r   z
    c                 S   s   g | ]}t |ƒ‘qS r   )Ú_format_repo_value)Ú.0Úvr   r   r   Ú
<listcomp>/   s    z&_format_repo_value.<locals>.<listcomp>)Ú
isinstanceÚboolÚlistÚtupleÚjoinÚstr)Úvalr   r   r   r   *   s   

r   c                 C   sD   t  ¡ }i || < | ¡ D ]\}}t|ƒ||  |< q| ¡ }d |¡S )NÚ
)Ú	configobjÚ	ConfigObjÚitemsr   Úwriter!   )r   Úrepo_configÚto_beÚkr   Úlinesr   r   r   Ú_format_repository_config5   s   
r-   c                 C   s  | sdS i }t | ƒD ]f\}}tddgƒ t|ƒ¡}|r&t d|d |¡¡ q
| d¡}t|ƒ}tj	 |d| ¡}tj	 
|¡rFt d||¡ q
||v rRt d||¡ q
td	d
„ | ¡ D ƒƒ}	dD ]
}
|
|	vrid|	|
< q_||	f||< q
| ¡ D ]\}}t||d ƒ}t |d |¡ qudS )zðWrite 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                 s   s8   � | ]\}}|r|d kr|  ¡  ¡  dd¡|fV  qdS )r   ú-r   N)ÚlowerÚstripr   )r   r+   r   r   r   r   Ú	<genexpr>i   s   € ýþýz_write_repos.<locals>.<genexpr>)ÚenabledÚautorefreshÚ1éÿÿÿÿr   )Ú	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_blobr   r   r   Ú_write_reposA   sR   ý
ýýþ€þrO   c                 C   s”   | sdS d}t  |¡}dg}|  ¡ D ]\}}|dkr&d}|d7 }t |¡ q|r1| d||f ¡ qt|ƒdkr@|d	 |¡ }n|}t  ||¡ dS )
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" settingz%s=%sr   r$   )	r   Úload_text_filer'   r;   r<   ÚappendÚlenr!   rC   )Úzypper_configÚzypp_configÚzypp_conf_contentÚnew_settingsÚsettingÚvalueÚmsgÚ
new_configr   r   r   Ú_write_zypp_config{   s$   

€r\   ÚnameÚcfgÚcloudÚargsÚreturnc                 C   sj   |  d¡}|st d| ¡ d S |  d¡}|st d| ¡ d S |  di ¡}|  dd¡}t|ƒ t||ƒ d S )Nr   zBSkipping module named %s, no 'zypper' relevant configuration foundrD   z8Skipping module named %s, no 'repos' configuration foundÚconfigÚreposdirz/etc/zypp/repos.d/)r=   r;   Údebugr\   rO   )r]   r^   r_   r`   Úzypper_sectionrD   rT   rE   r   r   r   Úhandle‘   s"   
ý
ÿrf   )Ú__doc__Úloggingr>   r%   Ú	cloudinitr   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.settingsr   r   Ú__annotations__Ú	getLoggerÚ__name__r;   r   r   r-   rO   r\   r"   r   rf   r   r   r   r   Ú<module>   s*   	ô
:"