3 ÅÀf89ã@s ddlmZddlmZddlZddlZddlZddlZddlmZm Z ddl m Z ddl Z ddl Z dd„ZGdd „d e jjƒZe jjGd d „d e jjƒƒZdS) é)Úabsolute_import)Úunicode_literalsN)Ú_Úlogger)Ú OptionParsercCs(tjjtjƒƒ}tjjtjj|||ƒƒS)N)ÚdnfZi18nZucdÚosÚgetcwdÚpathÚrealpathÚjoin)Z intermediateÚtargetÚcwd©rú/usr/lib/python3.6/reposync.pyÚ_pkgdir#srcs(eZdZ‡fdd„Z‡fdd„Z‡ZS)ÚRPMPayloadLocationcs$tt|ƒj||ƒtjj|ƒ|_dS)N)ÚsuperrÚ__init__rr ÚdirnameÚ package_dir)ÚselfÚpkgÚprogressZ pkg_location)Ú __class__rrr)szRPMPayloadLocation.__init__cs*tt|ƒjƒ}tjj|jƒ|j|d<|S)NÚdest)rrÚ_target_paramsrÚutilÚ ensure_dirr)rÚtp)rrrr-s z!RPMPayloadLocation._target_params)Ú__name__Ú __module__Ú __qualname__rrÚ __classcell__rr)rrr(s rcs”eZdZdZedƒZ‡fdd„Zedd„ƒZdd„Z d d „Z d d „Z d d„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z‡ZS) ÚRepoSyncCommandÚreposyncz&download all packages from remote repocstt|ƒj|ƒdS)N)rr$r)rÚcli)rrrr9szRepoSyncCommand.__init__c Cs|jdddgtjdtdƒd�|jddd td ƒd �|jd dd td ƒd �|jdddd tdƒd �|jdddd tdƒd �|jdtdƒd�|jdddd tdƒd �|jddd tdƒd �|jdddtdƒd �|jd!dd td"ƒd �|jd#dd td$ƒd �|jd%d&dd td'ƒd �dS)(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-metadatazdownload 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--sourcezdownload only source packagesz-uz--urlsz:Just list urls of what would be downloaded, don't download)Ú add_argumentrZ_SplitCallbackr)ÚparserrrrÚ set_argparser<s2                      zRepoSyncCommand.set_argparserc CsÞ|jj}d|_d|_|jj}|jjr||jƒj ƒxJ|jjD]>}y ||}Wn$t k rnt jj d|ƒ‚YnX|j ƒq:W|jjrŒ|jƒtt|jƒƒƒdkr¸|jjr¸t jj tdƒƒ‚x |jƒD]}|jjƒd|_qÂWdS)NTzUnknown repo: '%s'.éz1Can't use --norepopath with multiple repositoriesF)r&ÚdemandsZavailable_reposZsack_activationÚbaseÚreposÚoptsÚrepoÚallÚdisableÚKeyErrorrZCliErrorÚenableÚsourceZenable_source_reposÚlenÚlistÚ iter_enabledÚ norepopathrÚ_repoZexpireZdeltarpm)rr1r3Zrepoidr5rrrÚ configure\s(     zRepoSyncCommand.configurecsôd|jj_d}�xÈ|jjjƒD�]¶}|jjr8|jjdƒ|jj rš|jj r�xP|jj ƒD]6\}}|j |ƒ}|rtt |ƒqTtdƒ|}tj|ƒqTWn |j |ƒ|jj�r|jj �rt|jj ƒƒ‰‡fdd„dDƒ}|�rxB|D]}|j |ƒ}|rÚt |ƒPqÚWtdƒ}tj|ƒn |j|ƒ|j|ƒ} |jj �r8|j| ƒnŠ|j| ƒ|jj�rÂxt| D]l} |j| ƒ} tj| fd d „| ƒ| _|jj| ƒ\} } | d k�rRtjtd ƒjtjj | ƒ| ƒƒtj!| ƒd }�qRW|jj"r|j#|| ƒqW|�sðt$j%j&tdƒƒ‚dS)NTz%Failed to get mirror for metadata: %scsg|]}|ˆkrˆ|‘qSrr)Ú.0Úmd_type)Úmdlrrú ‹sz'RepoSyncCommand.run..ÚgroupÚgroup_gzÚ group_gz_zckz(Failed to get mirror for the group file.cSs|S)Nr)ÚsÚ local_pathrrrÚ¥sz%RepoSyncCommand.run..rzRemoving {}: {}FzGPG signature check failed.)rErFrG)'r2ZconfZ keepcacher3r=r4Z remote_timer?ZsetPreserveRemoteTimeÚdownload_metadataZurlsZgetMetadataLocationsÚremote_locationÚprintrrÚwarningZ downloadcompsÚdictÚgetcompsÚ get_pkglistÚ print_urlsÚdownload_packagesZgpgcheckÚpkg_download_pathÚtypesÚ MethodTypeZlocalPkgZpackage_signature_checkÚformatrr ÚbasenameÚunlinkÚdeleteÚdelete_old_local_packagesrÚ exceptionsÚError)rZ gpgcheck_okr5rBZ md_locationÚurlÚmsgZgroup_locationsZgroup_locationÚpkglistrrIÚresultÚerrorr)rCrÚrunws^                        zRepoSyncCommand.runcCs$t|jjp|jj|jjs|jndƒS)NÚ)rr4ZdestdirZ download_pathr>Úid)rr5rrrÚ repo_target±szRepoSyncCommand.repo_targetcCs&|jjrt|jj|jƒS|j|ƒSdS)N)r4Z metadata_pathrrerf)rr5rrrÚmetadata_targetµszRepoSyncCommand.metadata_targetcCsT|j|jƒ}tjjtjj||jƒƒ}|jtjj|dƒƒsPtj j t dƒj ||ƒƒ‚|S)Nrdz6Download target '{}' is outside of download path '{}'.) rfr5rr r r ÚlocationÚ startswithrr\r]rrW)rrrfrTrrrrT»s  z!RepoSyncCommand.pkg_download_pathc s¸t‡fdd„|Dƒƒ}xœtjˆj|ƒƒD]ˆ\}}}x||D]t}tjj||ƒ}|jdƒr8tjj|ƒr8||kr8ytj|ƒt j t dƒ|ƒWq8t k rªt j t dƒ|ƒYq8Xq8Wq(WdS)Nc3s|]}ˆj|ƒVqdS)N)rT)rAr)rrrú Êsz.z.rpmz [DELETED] %szfailed to delete file %s)ÚsetrÚwalkrfr r ÚendswithÚisfilerYrÚinforÚOSErrorrb) rr5r`Zdownloaded_filesÚdirpathZdirnamesÚ filenamesÚfilenamer r)rrr[Ès  z)RepoSyncCommand.delete_old_local_packagescCsZ|jjƒ}|rV|j|ƒ}tjj|ƒtjj|dƒ}tj j j ||d�t j tdƒ|jƒdS)Nz comps.xml)rz!comps.xml for repository %s saved)r?Z getCompsFnrgrrrrr r ZyumZmiscZ decompressrrorre)rr5Zcomps_fnZ dest_pathrrrrrP×s   zRepoSyncCommand.getcompscCs|j|ƒ}|jj|ƒdS)NT)rgr?ZdownloadMetadata)rr5rfrrrrKàs  z!RepoSyncCommand.download_metadatacCs´tjjs|jƒS|jƒ|jjjƒ}tƒ}i}i}xp|D]h}|jƒ}|j |ƒ|j |j ƒiƒj |j ƒgƒj |ƒx.|D]&}|j |iƒj |j ƒgƒj |j ƒƒqvWq8W|j|j|d�d�jƒ} tƒ} xÚ|jƒD]Î\} } tƒ} | jt| jƒdd�dƒtƒ}x0| jƒD]$}x|D]}|j |jƒƒ�qW�qWx:|j|d�jƒD]&}dj|ƒ}| jt||| ƒƒ�q>Wx0| D](}x | |D]}| j |jƒƒ�q|W�qnWqÌ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)Zpkg__neqT)Úreverserz3{0.name}-{0.epoch}:{0.version}-{0.release}.{0.arch})rr2Z WITH_MODULESZlatestZapplyZ_moduleContainerZgetModulePackagesrkZ getArtifactsÚupdateÚ setdefaultZ getNameStreamZ getVersionNumÚappendÚfilterÚitemsÚaddÚsortedÚkeysÚvaluesrWÚmaxÚunion)rÚqueryZmodule_packagesZ all_artifactsZ module_dictZartifact_versionZmodule_packageZ artifactsZartifactZ latest_queryZlatest_stream_artifactsZ namestreamZ version_dictZversionsZstream_artifactsÚmodulesÚmoduleZ latest_pkgZnevraÚversionrrrÚ _get_lateståsB         zRepoSyncCommand._get_latestcCsd|jjjtjd�jƒj|jd�}|jj r2|j |ƒ}|jj rH|jdd�n|jj r`|j|jj d�|S)N)Úflags)ZreponameÚsrc)Zarch) r2Úsackr€ÚhawkeyÚIGNORE_MODULAR_EXCLUDESZ availableZfiltermrer4Z newest_onlyr„r:r')rr5r€rrrrQs  zRepoSyncCommand.get_pkglistcsjˆj}|jj‰ˆdkr tjjƒ‰tjj|jj t j d�j ƒˆdƒ}‡‡fdd„|Dƒ}|j ||ˆddƒdS)N)r…rcsg|]}t|ˆˆj|ƒƒ‘qSr)rrT)rAr)rrrrrD0sz5RepoSyncCommand.download_packages..F)r2ÚoutputrrÚcallbackZNullDownloadProgressÚdrpmZ DeltaInfor‡r€rˆr‰Z installedZ_download_remote_payloads)rr`r2rŒZpayloadsr)rrrrS)s  z!RepoSyncCommand.download_packagescCs@x:|D]2}|jƒ}|r t|ƒqtdƒ|j}tj|ƒqWdS)Nz$Failed to get mirror for package: %s)rLrMrÚnamerrN)rr`rr^r_rrrrR4s   zRepoSyncCommand.print_urls)r%)r r!r"ÚaliasesrZsummaryrÚ staticmethodr/r@rcrfrgrTr[rPrKr„rQrSrRr#rr)rrr$4s   :  9  r$)Z __future__rrrˆrZshutilrUZdnfpluginscorerrZdnf.cli.option_parserrrZdnf.clirr5Z RPMPayloadrZpluginZregister_commandr&ZCommandr$rrrrÚs