a
    ©!c‹  ã                   @   s~   d dl mZ d dl mZ d dlmZmZ d dlZd dlZ	d dl
Zd dlZd dlZd dlZd dlZe d¡ZG dd„ deƒZdS )é    )Úabsolute_import)Úunicode_literals)Ú_ÚucdNÚdnfc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
RepoReaderc                 C   s   || _ || _d S )N)ÚconfÚopts)Úselfr   r	   © r   ú1/usr/lib/python3.9/site-packages/dnf/conf/read.pyÚ__init__$   s    zRepoReader.__init__c              	   c   s°   |   | jj¡D ]
}|V  qg }| jjD ](}t tj |d¡¡D ]}| |¡ q>q&|j	dd„ d |D ]F}z|   |¡D ]
}|V  qtW qd t
jjy¨   t tdƒ|¡ Y qd0 qdd S )Nz*.repoc                 S   s   t j | d d… ¡S )Néûÿÿÿ)r   ÚutilZ
split_path)Úxr   r   r   Ú<lambda>5   ó    z%RepoReader.__iter__.<locals>.<lambda>)Úkeyz'Warning: failed loading '%s', skipping.)Ú
_get_reposr   Zconfig_file_pathÚreposdirÚglobÚosÚpathÚjoinÚappendÚsortr   Ú
exceptionsÚConfigErrorÚloggerÚwarningr   )r
   ÚrZrepo_configsr   r   Úrepofnr   r   r   Ú__iter__(   s    
ÿzRepoReader.__iter__c           	   
   C   s`  t jj || jj¡}tj |¡}|durl||krJtdƒ 	|||| |¡}ntdƒ 	||| |¡}tj
 |¡‚tj || j¡}z| |||tjj¡ W n\ tyð } zD||krÀtdƒ 	|||¡}ntdƒ 	||¡}tj
 |¡‚W Y d}~n
d}~0 0 | d¡tjjkr:||kr"tdƒ 	||¡}ntdƒ 	|¡}t |¡ t|jƒ|_|j | jj¡ ||_|S )	z)Build a repository using the parsed data.Nz&Bad id for repo: {} ({}), byte = {} {}z!Bad id for repo: {}, byte = {} {}z.Repository '{}' ({}): Error parsing config: {}z)Repository '{}': Error parsing config: {}Únamez@Repository '{}' ({}) is missing name in configuration, using id.z;Repository '{}' is missing name in configuration, using id.)Úlibdnfr   ÚConfigParserZ
substituteÚsubstitutionsr   ÚrepoZrepo_id_invalidr   Úformatr   r   ZRepoZ	_populateZPRIO_REPOCONFIGÚ
ValueErrorZ_get_priorityZPRIO_DEFAULTr   r   r   r#   Z_substitutionsÚupdateZcfg)	r
   ÚparserZid_r!   Zsubstituted_idZinvalidÚmsgr'   Úer   r   r   Ú_build_repo?   s>    þ
ÿ"
ÿ
zRepoReader._build_repoc                 c   s(  | j j}tj  ¡ }| |¡ z| |¡ W nh tyf } z$tj 	t
dƒ ||¡¡‚W Y d}~n6d}~0  ty’ } zt |¡ W Y d}~n
d}~0 0 | ¡ D ]†}|dkrªqœz|  |t|ƒ|¡}W nH tjjtjj	fy } z"t |¡ W Y d}~qœW Y d}~nd}~0 0 ||_| | j¡ |V  qœdS )z4Parse and yield all repositories from a config file.zParsing file "{}" failed: {}NÚmain)r   r&   r$   r%   ZsetSubstitutionsÚreadÚRuntimeErrorr   r   r   r   r(   ÚIOErrorr   r   ZgetDatar.   r   Z	RepoErrorZrepofileZ_configure_from_optionsr	   )r
   r!   Zsubstsr+   r-   ZsectionZthisrepor   r   r   r   h   s(    

, 
"zRepoReader._get_reposN)Ú__name__Ú
__module__Ú__qualname__r   r"   r.   r   r   r   r   r   r   #   s   )r   )Z
__future__r   r   Zdnf.i18nr   r   Zdnf.confr   Zlibdnf.confr$   Zdnf.exceptionsZdnf.repor   Zloggingr   Z	getLoggerr   Úobjectr   r   r   r   r   Ú<module>   s   
