
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÅÀf89  ã               @   s    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d dlmZm	Z	 d dl
mZ d dlZd dlZdd„ ZG dd	„ d	ejjƒZejjG d
d„ dejjƒƒZdS )é    )Úabsolute_import)Úunicode_literalsN)Ú_Úlogger)ÚOptionParserc             C   s(   t jjtjƒ ƒ}tjjtjj|| |ƒƒS )N)ÚdnfZi18nZucdÚosÚgetcwdÚpathÚrealpathÚjoin)ZintermediateÚtargetÚcwd© r   ú/usr/lib/python3.6/reposync.pyÚ_pkgdir#   s    r   c                   s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚRPMPayloadLocationc                s$   t t| ƒj||ƒ tjj|ƒ| _d S )N)Úsuperr   Ú__init__r   r
   ÚdirnameÚpackage_dir)ÚselfÚpkgÚprogressZpkg_location)Ú	__class__r   r   r   )   s    zRPMPayloadLocation.__init__c                s*   t t| ƒjƒ }tjj| jƒ | j|d< |S )NÚdest)r   r   Ú_target_paramsr   ÚutilÚ
ensure_dirr   )r   Útp)r   r   r   r   -   s    
z!RPMPayloadLocation._target_params)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   )r   r   r   (   s   r   c                   s”   e Zd ZdZedƒZ‡ fdd„Zedd„ ƒZdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS ) ÚRepoSyncCommandÚreposyncz&download all packages from remote repoc                s   t t| ƒj|ƒ d S )N)r   r$   r   )r   Úcli)r   r   r   r   9   s    zRepoSyncCommand.__init__c          	   C   s  | j dddg tjdtdƒd� | j ddd	td
ƒd� | j ddd	tdƒd� | j dddd	tdƒd� | j dddd	tdƒd� | j dtdƒd� | j dddd	tdƒd� | j ddd	tdƒd� | j dddtdƒd � | j d!dd	td"ƒd� | j d#dd	td$ƒd� | j d%d&dd	td'ƒd� d S )(Nz-az--archÚarchesz[arch]z$download only packages for this ARCH)r   ÚdefaultÚactionÚmetavarÚhelpz--deleteFÚ
store_truez5delete local packages no longer present in repository)r(   r)   r+   z--download-metadatazdownload all the metadata.z-gz
--gpgcheckzBRemove packages that fail GPG signature checking after downloadingz-mz--downloadcompsz&also download and uncompress comps.xmlz--metadata-pathzXwhere to store downloaded repository metadata. Defaults to the value of --download-path.)r+   z-nz--newest-onlyz&download only newest packages per-repoz--norepopathz,Don't add the reponame to the download path.z-pz--download-pathz./z&where to store downloaded repositories)r(   r+   z--remote-timezCtry to set local timestamps of local files by the one on the serverz--sourcezdownload only source packagesz-uz--urlsz:Just list urls of what would be downloaded, don't download)Úadd_argumentr   Z_SplitCallbackr   )Úparserr   r   r   Úset_argparser<   s2    





zRepoSyncCommand.set_argparserc             C   sÞ   | j j}d|_d|_| jj}| jjr||jƒ j	ƒ  xJ| jjD ]>}y|| }W n$ t
k
rn   tj jd| ƒ‚Y nX |jƒ  q:W | jjrŒ|jƒ  tt|jƒ ƒƒdkr¸| jjr¸tj jtdƒƒ‚x |jƒ D ]}|jjƒ  d|_qÂW d S )NTzUnknown repo: '%s'.é   z1Can't use --norepopath with multiple repositoriesF)r&   ÚdemandsZavailable_reposZsack_activationÚbaseÚreposÚoptsÚrepoÚallÚdisableÚKeyErrorr   ZCliErrorÚenableÚsourceZenable_source_reposÚlenÚlistÚiter_enabledÚ
norepopathr   Ú_repoZexpireZdeltarpm)r   r1   r3   Zrepoidr5   r   r   r   Ú	configure\   s(    

zRepoSyncCommand.configurec                sô  d| j j_d}�xÈ| j jjƒ D �]¶}| jjr8|jjdƒ | jj	rš| jj
r�xP|jjƒ D ]6\}}|j|ƒ}|rtt|ƒ qTtdƒ| }tj|ƒ qTW n
| j	|ƒ | jj�r| jj
�rt|jjƒ ƒ‰ ‡ fdd„dD ƒ}|�rxB|D ]}|j|ƒ}|rÚt|ƒ P qÚW tdƒ}tj|ƒ n
| j|ƒ | j|ƒ}	| jj
�r8| j|	ƒ nŠ| j|	ƒ | jj�rÂxt|	D ]l}
| j|
ƒ}tj|fd	d
„|
ƒ|
_| j j|
ƒ\}}|dk�rRtjtdƒjtjj |ƒ|ƒƒ tj!|ƒ d}�qRW | jj"r| j#||	ƒ qW |�sðt$j%j&tdƒƒ‚d S )NTz%Failed to get mirror for metadata: %sc                s   g | ]}|ˆ krˆ | ‘qS r   r   )Ú.0Úmd_type)Úmdlr   r   ú
<listcomp>‹   s   z'RepoSyncCommand.run.<locals>.<listcomp>ÚgroupÚgroup_gzÚgroup_gz_zckz(Failed to get mirror for the group file.c             S   s   |S )Nr   )ÚsÚ
local_pathr   r   r   Ú<lambda>¥   s    z%RepoSyncCommand.run.<locals>.<lambda>r   zRemoving {}: {}FzGPG signature check failed.)rE   rF   rG   )'r2   ZconfZ	keepcacher3   r=   r4   Zremote_timer?   ZsetPreserveRemoteTimeÚdownload_metadataZurlsZgetMetadataLocationsÚremote_locationÚprintr   r   ÚwarningZdownloadcompsÚdictÚgetcompsÚget_pkglistÚ
print_urlsÚdownload_packagesZgpgcheckÚpkg_download_pathÚtypesÚ
MethodTypeZlocalPkgZpackage_signature_checkÚformatr   r
   ÚbasenameÚunlinkÚdeleteÚdelete_old_local_packagesr   Ú
exceptionsÚError)r   Zgpgcheck_okr5   rB   Zmd_locationÚurlÚmsgZgroup_locationsZgroup_locationÚpkglistr   rI   ÚresultÚerrorr   )rC   r   Úrunw   s^    


















zRepoSyncCommand.runc             C   s$   t | jjp| jj| jjs|jndƒS )NÚ )r   r4   ZdestdirZdownload_pathr>   Úid)r   r5   r   r   r   Úrepo_target±   s    zRepoSyncCommand.repo_targetc             C   s&   | j jrt| j j|jƒS | j|ƒS d S )N)r4   Zmetadata_pathr   re   rf   )r   r5   r   r   r   Úmetadata_targetµ   s    zRepoSyncCommand.metadata_targetc             C   sT   | j |jƒ}tjjtjj||jƒƒ}|jtjj|dƒƒsPtj	j
tdƒj||ƒƒ‚|S )Nrd   z6Download target '{}' is outside of download path '{}'.)rf   r5   r   r
   r   r   ÚlocationÚ
startswithr   r\   r]   r   rW   )r   r   rf   rT   r   r   r   rT   »   s    
z!RepoSyncCommand.pkg_download_pathc       	         s¸   t ‡ fdd„|D ƒƒ}xœtjˆ j|ƒƒD ]ˆ\}}}x||D ]t}tjj||ƒ}|jdƒr8tjj|ƒr8||kr8ytj|ƒ t	j
tdƒ|ƒ W q8 tk
rª   t	jtdƒ|ƒ Y q8X q8W q(W d S )Nc             3   s   | ]}ˆ j |ƒV  qd S )N)rT   )rA   r   )r   r   r   ú	<genexpr>Ê   s    z<RepoSyncCommand.delete_old_local_packages.<locals>.<genexpr>z.rpmz[DELETED] %szfailed to delete file %s)Úsetr   Úwalkrf   r
   r   ÚendswithÚisfilerY   r   Úinfor   ÚOSErrorrb   )	r   r5   r`   Zdownloaded_filesÚdirpathZdirnamesÚ	filenamesÚfilenamer
   r   )r   r   r[   È   s    

z)RepoSyncCommand.delete_old_local_packagesc             C   sZ   |j jƒ }|rV| j|ƒ}tjj|ƒ tjj|dƒ}tj	j
j||d� tjtdƒ|jƒ d S )Nz	comps.xml)r   z!comps.xml for repository %s saved)r?   Z
getCompsFnrg   r   r   r   r   r
   r   ZyumZmiscZ
decompressr   ro   r   re   )r   r5   Zcomps_fnZ	dest_pathr   r   r   r   rP   ×   s    

zRepoSyncCommand.getcompsc             C   s   | j |ƒ}|jj|ƒ dS )NT)rg   r?   ZdownloadMetadata)r   r5   rf   r   r   r   rK   à   s    
z!RepoSyncCommand.download_metadatac             C   s´  t jjs|jƒ S |jƒ  | jjjƒ }tƒ }i }i }xp|D ]h}|jƒ }|j	|ƒ |j
|jƒ i ƒj
|jƒ g ƒj|ƒ x.|D ]&}|j
|i ƒj
|jƒ g ƒj|jƒ ƒ qvW q8W |j|j|d�d�jƒ }	tƒ }
xÚ|jƒ D ]Î\}}tƒ }|jt|jƒ dd�d ƒ tƒ }x0|jƒ D ]$}x|D ]}|j	|jƒ ƒ �qW �qW x:|j|d�jƒ D ]&}dj|ƒ}|jt|| | ƒƒ �q>W x0|D ](}x || D ]}|
j	|jƒ ƒ �q|W �qnW qÌW |	j|j|
d�ƒ}	|	S )a\  
        return union of these queries:
        - the latest NEVRAs from non-modular packages
        - all packages from stream version with the latest package NEVRA
          (this should not be needed but the latest package NEVRAs might be
          part of an older module version)
        - all packages from the latest stream version
        )Znevra_strict)Zpkg__neqT)Úreverser   z3{0.name}-{0.epoch}:{0.version}-{0.release}.{0.arch})r   r2   ZWITH_MODULESZlatestZapplyZ_moduleContainerZgetModulePackagesrk   ZgetArtifactsÚupdateÚ
setdefaultZgetNameStreamZgetVersionNumÚappendÚfilterÚitemsÚaddÚsortedÚkeysÚvaluesrW   ÚmaxÚunion)r   ÚqueryZmodule_packagesZall_artifactsZmodule_dictZartifact_versionZmodule_packageZ	artifactsZartifactZlatest_queryZlatest_stream_artifactsZ
namestreamZversion_dictZversionsZstream_artifactsÚmodulesÚmoduleZ
latest_pkgZnevraÚversionr   r   r   Ú_get_latestå   sB    	





zRepoSyncCommand._get_latestc             C   sd   | j jjtjd�jƒ j|jd�}| jj	r2| j
|ƒ}| jjrH|jdd� n| jjr`|j| jjd� |S )N)Úflags)ZreponameÚsrc)Zarch)r2   Úsackr€   ÚhawkeyÚIGNORE_MODULAR_EXCLUDESZ	availableZfiltermre   r4   Znewest_onlyr„   r:   r'   )r   r5   r€   r   r   r   rQ     s    

zRepoSyncCommand.get_pkglistc                sj   ˆj }|jj‰ ˆ d kr tjjƒ ‰ tjj|jj	t
jd�jƒ ˆ dƒ}‡ ‡fdd„|D ƒ}|j||ˆ d dƒ d S )N)r…   r   c                s   g | ]}t |ˆ ˆj|ƒƒ‘qS r   )r   rT   )rA   r   )r   r   r   r   rD   0  s   z5RepoSyncCommand.download_packages.<locals>.<listcomp>F)r2   Úoutputr   r   ÚcallbackZNullDownloadProgressÚdrpmZ	DeltaInfor‡   r€   rˆ   r‰   Z	installedZ_download_remote_payloads)r   r`   r2   rŒ   Zpayloadsr   )r   r   r   rS   )  s    
z!RepoSyncCommand.download_packagesc             C   s@   x:|D ]2}|j ƒ }|r t|ƒ qtdƒ|j }tj|ƒ qW d S )Nz$Failed to get mirror for package: %s)rL   rM   r   Únamer   rN   )r   r`   r   r^   r_   r   r   r   rR   4  s    

zRepoSyncCommand.print_urls)r%   )r    r!   r"   Úaliasesr   Zsummaryr   Ústaticmethodr/   r@   rc   rf   rg   rT   r[   rP   rK   r„   rQ   rS   rR   r#   r   r   )r   r   r$   4   s     :	9r$   )Z
__future__r   r   rˆ   r   ZshutilrU   Zdnfpluginscorer   r   Zdnf.cli.option_parserr   r   Zdnf.clir   r5   Z
RPMPayloadr   ZpluginZregister_commandr&   ZCommandr$   r   r   r   r   Ú<module>   s   