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-rpmsz{}-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   