a &c*0@sddlmZddlmZddlmZmZddlmZddlZddl Zddl Zddl Zddl Zddl ZddlZddlZddlZddlZejjGdddejjZdS))absolute_import)unicode_literals)_logger) OptionParserNcseZdZdgZedZfddZeddZddZ d d Z d d Z d dZ ddZ ddZddZd ddZd!ddZeddZddZddZZS)"DownloadCommandZdownloadz%Download package to current directorycs tt||d|_d|_dSN)superr__init__optsparser)selfcli __class__8/usr/lib/python3.9/site-packages/dnf-plugins/download.pyr +szDownloadCommand.__init__c Cs|jddtdd|jddtdd|jd dtd d|jd dtd d|jd ddgtjdtdd|jddtdd|jddtdd|jddddtdd|jddgdgtdd dS)!Npackages+zpackages to download)nargshelpz--source store_truezdownload the src.rpm instead)actionrz --debuginfoz'download the -debuginfo package insteadz --debugsourcez)download the -debugsource package insteadz--archz --archlistarchesz[arch]z5limit the query to packages of given architectures.)destdefaultrmetavarrz --resolvez(resolve and download needed dependenciesz --alldepsz^when running with --resolve, download all dependencies (do not exclude already installed ones)z--urlz--urlsurlzJprint list of urls where the rpms can be downloaded instead of downloading)rrrz--urlprotocolsappend)httphttpsrsyncftpz4when running with --url, limit to specific protocols)rchoicesrr) add_argumentrrZ_SplitCallback)r rrr set_argparser0s<  zDownloadCommand.set_argparsercCs|jj}d|_d|_|jjr*|jjr*d|_|jjr>|j j |jj sN|jj rZ|j j |jjrr|jj|j j_ntjt|j j_dS)NTF)rdemandsZsack_activationZavailable_reposr resolveZalldepsZload_system_reposourcebaseZreposZenable_source_repos debuginfo debugsourceZenable_debug_reposdestdirconfdnfi18nucdosgetcwd)r r&rrr configureKs  zDownloadCommand.configurecCs|jjs(|jjs(|jjs(||jj}nXg}|jjrH|||jj|jjrd|||jj|jjr|| |jj|jj r|D]\}|j t j kr|j|jjd}|rt|qtd|j}|jjjrtj|t|qdS||dS)zExecute the util action here.)schemesz$Failed to get mirror for package: %sN)r r(r*r+_get_pkg_objs_rpmsrextend_get_pkg_objs_source_get_pkg_objs_debuginfo_get_pkg_objs_debugsourcerrepoidhawkeyCMDLINE_REPO_NAMEZremote_locationZ urlprotocolsprintrnamer)r-strictr. exceptionsErrorrZwarning _do_downloads)r pkgspkgrmsgrrrrun^s2     zDownloadCommand.runc Cs i}|D]}|t|g|qg}g}|D]D}dd|D}|rZ||dq4|jddd||dq4|r|j||jjj|r|D]V}| }t j |jj jt j |} t j | rt j || rqt||jj jqtdd||D} | S)z= Perform the download for a list of packages cSsg|]}|jtjkr|qSr)r:r;r<.0rDrrr s z1DownloadCommand._do_downloads..rcSs|jj|jjfSr)ZrepopriorityZcost)xrrrz/DownloadCommand._do_downloads..)keycSsg|] }|qSr)localPkgrGrrrrIrM) setdefaultstrrvaluessortr)Zdownload_packagesoutputprogressrOr1pathjoinr-r,basenameexistssamefileshutilcopysorted) r rCZpkg_dictrDZ to_downloadZcmdlineZpkg_listZ pkgs_cmdlinesrcdstZ locationsrrrrBs. zDownloadCommand._do_downloadscCs"|jjr||}n ||}|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_specsrCrrrr5s  z"DownloadCommand._get_pkg_objs_rpmscCs*||}||}t|j|dd}|S)zj Return a list of dnf.Package objects that represent the source rpms to download. T)r()r5_get_source_packagessetra)r rbrC source_pkgsrrrr7s  z$DownloadCommand._get_pkg_objs_sourcec Cszt}|jj}||D]T}|j|jfD]B}|j|t |j |j |j |j d}|sZq0|D]}||q^q q0q |S)zm Return a list of dnf.Package objects that represent the debuginfo rpms to download. r>epochversionreleasearch)rdr)sackquery availableraZ debug_nameZsource_debug_namefilterintrgrhrirjadd)r rbdbg_pkgsqrDZdbg_name dbg_availableprrrr8s" z'DownloadCommand._get_pkg_objs_debuginfocCs`t}|jj}||D]:}|j|jt|j |j |j |j d}|D]}| |qJq |S)zo Return a list of dnf.Package objects that represent the debugsource rpms to download. rf)rdr)rkrlrmrarnZdebugsource_namerorgrhrirjrp)r rbrqrrrDrsrtrrrr9sz)DownloadCommand._get_pkg_objs_debugsourceFc Cs|r |jn|j}g}|D]v}z|||Wqtjjy}zBttj ||j j j rxtt dtj|WYd}~qd}~00qttj|}|S)z Get packages matching pkg_specs.zExiting due to strict setting.N)_get_query_source _get_queryrr.r@PackageNotFoundErrorrerrorr/r0r)r-r?rrAlist itertoolschain)r rbr(funcZqueriespkg_specerCrrrras $zDownloadCommand._get_packagesc Cs||}t|}|D]}t|jj}|||}|r\|| || qt dg}t d|dd|Dt tj|tjq|S)z-Get packages matching pkg_specs and the deps.zError in resolve of packages:z cSsg|] }t|qSr)rQrGrrrrIrMz;DownloadCommand._get_packages_with_deps..)rardr;ZGoalr)rkinstallrFupdateZ list_installsZ list_upgradesrrrxrWr.utilZ_format_resolve_problemsZ problem_rulesr@rA) r rbr(rCZpkg_setrDZgoalrcrErrrr`s    z'DownloadCommand._get_packages_with_depscCsvt}|D]b}|jr6||jtdt||jq |jdkrX|d|j|jfq t t dt|q t |S)z4Get list of source rpm names for a list of packages.z --> Package : %s Source : %sr^z %s-%s.src.rpmzNo source rpm defined for %s) rdZ sourcerpmrprdebugrQrjr>Zevrinforry)rCrerDrrrrc s   z$DownloadCommand._get_source_packagescCstjj|d}|o|dv}|s8|drdtj|rd|jj|g|jj j d}|jj j |dStj|}|j|jj |jjd}|}|j dd}|jjr|j|jjd }t|dkrtd |}tj||S) z#Return a query to match a pkg_spec.r)rr"filer z.rpm)rU)rD)Zwith_srcT)Zlatest_per_arch_by_priority)rjNo package %s available.)r.Zpycompurlparseendswithr1rVisfiler)Zadd_remote_rpmsrTrUrkrlZfiltermsubjectSubjectZget_best_queryr r(rmrrnlenrFrr@rw)r r}r4Zis_urlrCsubjrrrErrrrvs     zDownloadCommand._get_querycCsd|dd}tj|}|D]&}||jj}|r |Sq t d|}tj |dS)z/Return a query to match a source rpm file name.Nr) r.rrZget_nevra_possibilitiesZto_queryr)rkrmZlatestrr@rw)r r}rZ nevra_objZ tmp_queryrErrrru,s    z!DownloadCommand._get_query_source)F)F)__name__ __module__ __qualname__aliasesrZsummaryr staticmethodr%r3rFrBr5r7r8r9rar`rcrvru __classcell__rrrrr%s$  #!     r)Z __future__rrZdnfpluginscorerrZdnf.cli.option_parserrr.Zdnf.cliZdnf.exceptionsZdnf.i18nZ dnf.subjectZdnf.utilr;rzr1r[ZpluginZregister_commandrZCommandrrrrrs