o
    ÷¢i"  ã                
   @   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dlmZ d	g d
¢edgdœZeed< e e¡Zdedef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 )z<Yum Add Repo: Add yum repository configuration to the systemé    N)ÚConfigParser)Úutil)ÚCloud)ÚConfig)Ú
MetaSchema)ÚPER_INSTANCEÚcc_yum_add_repo)Ú	almalinuxÚ
azurelinuxÚcentosÚ
cloudlinuxÚ	eurolinuxÚfedoraÚmarinerÚ	openeulerÚOpenCloudOSÚopenmandrivaÚphotonÚrhelÚrockyÚ	TencentOSÚ	virtuozzoÚ	yum_repos)ÚidÚdistrosÚ	frequencyÚactivate_by_schema_keysÚmetaÚrepo_idÚreturnc                 C   s   |   dd¡S )af  Canonicalize repo id.

    The sole name convention for repo ids is to not contain namespaces,
    and typically the separator used is `-`. More info:
    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-setting_repository_options

    :param repo_id: Repo id to convert.
    :return: Canonical repo id.
    ú ú-)Úreplace)r   © r#   úB/usr/lib/python3/dist-packages/cloudinit/config/cc_yum_add_repo.pyÚ_canonicalize_id/   s   
r%   c                 C   sN   t | tƒrtt| ƒƒS t | ttfƒrd dd„ | D ƒ¡S t | tƒs%t| ƒS | S )NÚ
c                 S   s   g | ]}t |ƒ‘qS r#   )Ú_format_repo_value)Ú.0Úvr#   r#   r$   Ú
<listcomp>C   s    z&_format_repo_value.<locals>.<listcomp>)Ú
isinstanceÚboolÚstrÚintÚlistÚtupleÚjoin)Úvalr#   r#   r$   r'   <   s   

r'   c                 C   sv   t ƒ }| | ¡ | ¡ D ]\}}| | |t|ƒ¡ qt ¡ }| |¡ | d¡ | 	¡ }| 
ddt ¡  ¡ d |¡S )Nr   z# Created by cloud-init on %s
Ú )r   Úadd_sectionÚitemsÚsetr'   ÚioÚStringIOÚwriteÚseekÚ	readlinesÚinsertr   Útime_rfc2822r1   )r   Úrepo_configÚto_beÚkr)   Úto_be_streamÚlinesr#   r#   r$   Ú_format_repository_configK   s   



rC   ÚnameÚcfgÚcloudÚargsc                 C   s`  |  d¡}|st d| ¡ d S t |dd¡}i }i }| ¡ D ]x\}}	t|ƒ}
tj 	|d|
 ¡}tj 
|¡r=t d||¡ q|
|v rIt d||¡ q|	sMi }	i }|	 ¡ D ]\}}| ¡  ¡  dd	¡}|rg|||< qS|}	d
}g d¢}|D ]
}||	vr||d7 }qr|t|ƒkrŽt d|d 	|¡¡ q|	||
< |||
< q| ¡ D ]\}}t||  |¡ƒ}t ||¡ q›d S )Nr   z<Skipping module named %s, no 'yum_repos' configuration foundÚyum_repo_dirz/etc/yum.repos.d/z%s.repoz)Skipping repo %s, file %s already exists!z*Skipping repo %s, file %s already pending!r!   Ú_r   )ÚbaseurlÚmetalinkÚ
mirrorlisté   z_Repository %s should contain at least one of the following configuration entries: %s, skipping!z, )ÚgetÚLOGÚdebugr   Úget_cfg_option_strr5   r%   ÚosÚpathr1   ÚexistsÚinfoÚlowerÚstripr"   ÚlenÚwarningrC   Ú
write_file)rD   rE   rF   rG   ÚreposÚrepo_base_pathÚrepo_locationsÚrepo_configsr   r>   Úcanon_repo_idÚrepo_fn_pthÚn_repo_configr@   r)   Úmissing_requiredÚ
req_fieldsÚ	req_fieldÚ	c_repo_idrS   Ú	repo_blobr#   r#   r$   Úhandle[   st   
þÿýý€€ü

ÿürg   )Ú__doc__r7   ÚloggingrR   Úconfigparserr   Ú	cloudinitr   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.settingsr   r   Ú__annotations__Ú	getLoggerÚ__name__rO   r-   r%   r'   rC   r/   rg   r#   r#   r#   r$   Ú<module>   s(   ì
"