a
    ©!c.  ã                   @   s`   d dl mZ d dlmZ d dlmZ d dlZd dlZ	d dl
Z
d dlZejjZG dd„ deƒZdS )é    )Úunicode_literals)ÚConfigError)Ú_Nc                       s~   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Z‡ fdd„Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚRepoDictc              
   C   sl   |j }|| v rd}t|| ƒ‚z|j ¡  W n2 ty^ } ztd |¡ƒ‚W Y d }~n
d }~0 0 || |< d S )Nz;Repository %s is listed more than once in the configurationz{0})Úidr   Z_repoZverifyÚRuntimeErrorÚformat)ÚselfÚrepoZid_ÚmsgÚe© r   ú0/usr/lib/python3.9/site-packages/dnf/repodict.pyÚadd#   s    $zRepoDict.addc                 C   s   t j |  ¡ ¡S ©N)ÚdnfÚutilÚMultiCallListÚvalues©r	   r   r   r   Úall/   s    zRepoDict.allc                 C   s   t j |  ¡ ¡ S r   )r   r   ÚemptyÚiter_enabledr   r   r   r   Ú_any_enabled3   s    zRepoDict._any_enabledc                 C   sH   |   ¡ D ]:}|  ||jƒ¡D ]$}|jst tdƒ|j¡ | ¡  qqd S )Nzenabling %s repository)r   Úget_matchingr   ÚenabledÚloggerÚinfor   Zenable)r	   Zsub_name_fnr
   Úfoundr   r   r   Ú_enable_sub_repos6   s
    zRepoDict._enable_sub_reposr   c           
         sš   ‡ fdd„}t j |ˆ ¡}|D ]2}d|vr<d tj |¡¡}| j||ƒg7  _q| ¡ D ]\}}	t	||||	ƒƒ qZ|  
|¡ t tdƒ|d |¡¡ |S )a¾  
        Creates new repo object and add it into RepoDict. Variables in provided values will be
        automatically substituted using conf.substitutions (like $releasever, ...)

        @param repoid: Repo ID - string
        @param conf: dnf Base().conf object
        @param baseurl: List of strings
        @param kwargs: keys and values that will be used to setattr on dnf.repo.Repo() object
        @return: dnf.repo.Repo() object
        c                    sp   t | tƒrtjj | ˆ j¡S t | tƒs0t | tƒrlg }| D ]2}t |tƒr^| 	tjj |ˆ j¡¡ |r8|  S q8| S r   )
Ú
isinstanceÚstrÚlibdnfÚconfZConfigParserÚ
substituteZsubstitutionsÚlistÚtupleÚappend)r   ZsubstitutedÚvalue©r#   r   r   r$   I   s    

ÿ
z)RepoDict.add_new_repo.<locals>.substitutez://z	file://{}zAdded %s repo from %sz, )r   r
   ZRepor   ÚosÚpathÚabspathÚbaseurlÚitemsÚsetattrr   r   r   r   Újoin)
r	   Zrepoidr#   r-   Úkwargsr$   r
   r+   Úkeyr(   r   r)   r   Úadd_new_repo=   s    
zRepoDict.add_new_repoc                 C   s   dd„ }|   |¡ dS )z@enable debug repos corresponding to already enabled binary reposc                 S   s&   |   d¡rd | d d… ¡S d | ¡S )Nú-rpmsz{}-debug-rpmséûÿÿÿz{}-debuginfo©Úendswithr   ©Únamer   r   r   Ú
debug_namee   s    ÿz/RepoDict.enable_debug_repos.<locals>.debug_nameN©r   )r	   r:   r   r   r   Úenable_debug_reposa   s    zRepoDict.enable_debug_reposc                 C   s   dd„ }|   |¡ dS )zAenable source repos corresponding to already enabled binary reposc                 S   s&   |   d¡rd | d d… ¡S d | ¡S )Nr4   z{}-source-rpmsr5   z	{}-sourcer6   r8   r   r   r   Úsource_nameo   s    ÿz1RepoDict.enable_source_repos.<locals>.source_nameNr;   )r	   r=   r   r   r   Úenable_source_reposk   s    zRepoDict.enable_source_reposc                    sZ   t j ˆ ¡r,‡ ‡fdd„ˆD ƒ}t j |¡S ˆ ˆ d ¡}|d u rLt j g ¡S t j |g¡S )Nc                    s    g | ]}t   |ˆ ¡rˆ| ‘qS r   )Úfnmatch)Ú.0Úk©r2   r	   r   r   Ú
<listcomp>x   ó    z)RepoDict.get_matching.<locals>.<listcomp>)r   r   Zis_glob_patternr   Úget)r	   r2   Úlr
   r   rB   r   r   u   s    zRepoDict.get_matchingc                 C   s   dd„ |   ¡ D ƒS )Nc                 s   s   | ]}|j r|V  qd S r   )r   )r@   Úrr   r   r   Ú	<genexpr>�   rD   z(RepoDict.iter_enabled.<locals>.<genexpr>)r   r   r   r   r   r      s    zRepoDict.iter_enabledc                    s$   dd„ t tt| ƒ ¡ dd„ d�D ƒS )zreturn repos sorted by priorityc                 s   s   | ]
}|V  qd S r   r   )r@   Úitemr   r   r   rH   …   rD   z!RepoDict.items.<locals>.<genexpr>c                 S   s   | d j | d jfS )Né   )ZpriorityZcost)Úxr   r   r   Ú<lambda>†   rD   z RepoDict.items.<locals>.<lambda>)r2   )ÚsortedÚsuperr   r.   r   ©Ú	__class__r   r   r.   ƒ   s    ÿzRepoDict.itemsc                 C   s   |   ¡ S r   )Úkeysr   r   r   r   Ú__iter__ˆ   s    zRepoDict.__iter__c                 C   s   dd„ |   ¡ D ƒS )Nc                 s   s   | ]\}}|V  qd S r   r   ©r@   rA   Úvr   r   r   rH   Œ   rD   z RepoDict.keys.<locals>.<genexpr>©r.   r   r   r   r   rQ   ‹   s    zRepoDict.keysc                 C   s   dd„ |   ¡ D ƒS )Nc                 s   s   | ]\}}|V  qd S r   r   rS   r   r   r   rH   �   rD   z"RepoDict.values.<locals>.<genexpr>rU   r   r   r   r   r   Ž   s    zRepoDict.values)r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r3   r<   r>   r   r   r.   rR   rQ   r   Ú__classcell__r   r   rO   r   r   !   s   
$


r   )Z
__future__r   Zdnf.exceptionsr   Zdnf.i18nr   Zdnf.utilr   Zlibdnf.confr"   r?   r*   r   r   Údictr   r   r   r   r   Ú<module>   s   