3 šgt`*0ã@s¤ddlmZddlmZddlmZmZddlmZddlZddl Zddl Zddl Zddl Zddl ZddlZddlZddlZddlZejjGdd„dejjƒƒZdS)é)Úabsolute_import)Úunicode_literals)Ú_Úlogger)Ú OptionParserNcsžeZdZdgZedƒZ‡fdd„Zedd„ƒZdd„Z d d „Z d d „Z d d„Z dd„Z dd„Zdd„Zd dd„Zd!dd„Zedd„ƒZdd„Zdd„Z‡ZS)"ÚDownloadCommandZdownloadz%Download package to current directorycs tt|ƒj|ƒd|_d|_dS)N)ÚsuperrÚ__init__ÚoptsÚparser)ÚselfÚcli)Ú __class__©ú/usr/lib/python3.6/download.pyr +szDownloadCommand.__init__c CsÒ|jddtdƒd�|jddtdƒd�|jd dtd ƒd�|jd dtd ƒd�|jd ddgtjdtdƒd�|jddtdƒd�|jddtdƒd�|jddddtdƒd�|jddddd d!ggtd"ƒd#�dS)$NÚpackagesú+zpackages to download)ÚnargsÚhelpz--sourceÚ store_truezdownload the src.rpm instead)Úactionrz --debuginfoz'download the -debuginfo package insteadz --debugsourcez)download the -debugsource package insteadz--archz --archlistÚarchesz[arch]z5limit the query to packages of given architectures.)ÚdestÚdefaultrÚmetavarrz --resolvez(resolve and download needed dependenciesz --alldepsz^when running with --resolve, download all dependencies (do not exclude already installed ones)z--urlz--urlsÚurlzJprint list of urls where the rpms can be downloaded instead of downloading)rrrz--urlprotocolsÚappendÚhttpÚhttpsZrsyncÚftpz4when running with --url, limit to specific protocols)rÚchoicesrr)Ú add_argumentrrZ_SplitCallback)r rrrÚ set_argparser0s*           zDownloadCommand.set_argparsercCsŒ|jj}d|_d|_|jjr*|jjr*d|_|jjr>|j j j ƒ|jj sN|jj rZ|j j jƒ|jjrr|jj|j j_ntjjtjƒƒ|j j_dS)NTF)r ÚdemandsZsack_activationZavailable_reposr ÚresolveZalldepsZload_system_repoÚsourceÚbaseZreposZenable_source_reposÚ debuginfoÚ debugsourceZenable_debug_reposÚdestdirÚconfÚdnfÚi18nÚucdÚosÚgetcwd)r r#rrrÚ configureKs  zDownloadCommand.configurecCs|jj r.|jj r.|jj r.|j|jjƒ}nXg}|jjrN|j|j|jjƒƒ|jjrj|j|j|jjƒƒ|jjr†|j|j |jjƒƒ|jj røxd|D]\}|j t j kr”|j|jjd�}|rÂt|ƒq”tdƒ|j}|jjjrætjj|ƒ‚tj|ƒq”WdS|j|ƒdS)zExecute the util action here.)Úschemesz$Failed to get mirror for package: %sN)r r%r'r(Ú_get_pkg_objs_rpmsrÚextendÚ_get_pkg_objs_sourceÚ_get_pkg_objs_debuginfoÚ_get_pkg_objs_debugsourcerÚrepoidÚhawkeyÚCMDLINE_REPO_NAMEZremote_locationZ urlprotocolsÚprintrÚnamer&r*Ústrictr+Ú exceptionsÚErrorrZwarningÚ _do_downloads)r ÚpkgsÚpkgrÚmsgrrrÚrun^s.        zDownloadCommand.runc Csi}x"|D]}|jt|ƒgƒj|ƒq Wg}g}xP|jƒD]D}dd„|Dƒ}|r`|j|dƒq:|jdd„d�|j|dƒq:W|rš|jj||jjjƒ|rþx^|D]V}|j ƒ}t j j |jj jt j j|ƒƒ} t j j| ƒrèt j j|| ƒrèq¤tj||jj jƒq¤Wtdd„||Dƒƒ} | S)z= Perform the download for a list of packages cSsg|]}|jtjkr|‘qSr)r7r8r9)Ú.0rArrrú Œsz1DownloadCommand._do_downloads..rcSs|jj|jjfS)N)ZrepoZpriorityZcost)ÚxrrrÚ‘sz/DownloadCommand._do_downloads..)ÚkeycSsg|] }|jƒ‘qSr)ÚlocalPkg)rDrArrrrEŸs)Ú setdefaultÚstrrÚvaluesÚsortr&Zdownload_packagesÚoutputÚprogressrIr.ÚpathÚjoinr*r)ÚbasenameÚexistsÚsamefileÚshutilÚcopyÚsorted) r r@Zpkg_dictrAZ to_downloadZcmdlineZpkg_listZ pkgs_cmdlineÚsrcÚdstZ locationsrrrr?�s.  zDownloadCommand._do_downloadscCs"|jjr|j|ƒ}n |j|ƒ}|S)zc Return a list of dnf.Package objects that represent the rpms to download. )r r$Ú_get_packages_with_depsÚ _get_packages)r Ú pkg_specsr@rrrr2¢s  z"DownloadCommand._get_pkg_objs_rpmscCs*|j|ƒ}|j|ƒ}t|j|dd�ƒ}|S)zj Return a list of dnf.Package objects that represent the source rpms to download. T)r%)r2Ú_get_source_packagesÚsetr[)r r\r@Ú source_pkgsrrrr4­s  z$DownloadCommand._get_pkg_objs_sourcec Cs„tƒ}|jjjƒjƒ}xh|j|ƒD]Z}xT|j|jgD]D}|j|t |j ƒ|j |j |j d�}|s^q4x|D]}|j|ƒqdWPq4Wq"W|S)zm Return a list of dnf.Package objects that represent the debuginfo rpms to download. )r;ÚepochÚversionÚreleaseÚarch)r^r&ÚsackÚqueryÚ availabler[Z debug_nameZsource_debug_nameÚfilterÚintr`rarbrcÚadd)r r\Údbg_pkgsÚqrAZdbg_nameÚ dbg_availableÚprrrr5·s    z'DownloadCommand._get_pkg_objs_debuginfocCshtƒ}|jjjƒjƒ}xL|j|ƒD]>}|j|jt|j ƒ|j |j |j d�}x|D]}|j |ƒqNWq"W|S)zo Return a list of dnf.Package objects that represent the debugsource rpms to download. )r;r`rarbrc)r^r&rdrerfr[rgZdebugsource_namerhr`rarbrcri)r r\rjrkrArlrmrrrr6Ós  z)DownloadCommand._get_pkg_objs_debugsourceFcCs¤|r |jn|j}g}x||D]t}y|j||ƒƒWqtjjk rŒ}zÚlistÚ itertoolsÚchain)r r\r%ÚfuncZqueriesÚpkg_specÚer@rrrr[és  "zDownloadCommand._get_packagesc Cs®|j|ƒ}t|ƒ}x–|D]Ž}tj|jjƒ}|j|ƒ|jƒ}|r^|j|j ƒƒ|j|j ƒƒqt dƒg}t j dj|dd„|Dƒƒƒt j tjj|jƒƒƒtjjƒ‚qW|S)z-Get packages matching pkg_specs and the deps.zError in resolve of packages:z cSsg|] }t|ƒ‘qSr)rK)rDrArrrrEsz;DownloadCommand._get_packages_with_deps..)r[r^r8ZGoalr&rdZinstallrCÚupdateZ list_installsZ list_upgradesrrrqrQr+ÚutilZ_format_resolve_problemsZ problem_rulesr=r>) r r\r%r@Zpkg_setrAZgoalZrcrBrrrrZùs    z'DownloadCommand._get_packages_with_depscCsztƒ}xj|D]b}|jr8|j|jƒtjdt|ƒ|jƒq |jdkrZ|jd|j|jfƒq tj t dƒt|ƒƒq Wt |ƒS)z4Get list of source rpm names for a list of packages.z --> Package : %s Source : %srXz %s-%s.src.rpmzNo source rpm defined for %s) r^Z sourcerpmrirÚdebugrKrcr;ZevrÚinforrr)r@r_rArrrr] s   z$DownloadCommand._get_source_packagescCsÞtjjj|ƒd}|o|dk}|s8|jdƒrdtjj|ƒrd|jj|g|jj j d�}|jj j ƒj |d�Stjj|ƒ}|j|jj |jjd �}|jƒ}|j d d �}|jjr²|j|jjd �}t|jƒƒdkrÚtd ƒ|}tjj|ƒ‚|S)z#Return a query to match a pkg_spec.rrrÚfilerz.rpm)rO)rA)Zwith_srcT)Zlatest_per_arch_by_priority)rczNo package %s available.)rrr|r)r+ZpycompZurlparseÚendswithr.rPÚisfiler&Zadd_remote_rpmsrNrOrdreZfiltermÚsubjectÚSubjectZget_best_queryr r%rfrrgÚlenrCrr=rp)r rvr1Zis_urlr@ÚsubjrkrBrrrros     zDownloadCommand._get_querycCsd|dd…}tjj|ƒ}x.|jƒD]"}|j|jjƒjƒ}|r"|jƒSq"Wt dƒ|}tj j |ƒ‚dS)z/Return a query to match a source rpm file name.NézNo package %s available.éüÿÿÿ) r+rr€Zget_nevra_possibilitiesZto_queryr&rdrfZlatestrr=rp)r rvr‚Z nevra_objZ tmp_queryrBrrrrn,s    z!DownloadCommand._get_query_source)F)F)Ú__name__Ú __module__Ú __qualname__ÚaliasesrZsummaryr Ú staticmethodr"r0rCr?r2r4r5r6r[rZr]rornÚ __classcell__rr)rrr%s   #!     r)Z __future__rrZdnfpluginscorerrZdnf.cli.option_parserrr+Zdnf.cliZdnf.exceptionsZdnf.i18nZ dnf.subjectZdnf.utilr8rsr.rUZpluginZregister_commandr ZCommandrrrrrÚs