Current File : //proc/self/root/kunden/lib/python3.9/site-packages/dnf-plugins/__pycache__/download.cpython-39.pyc
a

�&c*0�@s�ddlmZddlmZddlmZmZddlmZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlZddlZejjGdd�dejj��ZdS)�)�absolute_import)�unicode_literals)�_�logger)�OptionParserNcs�eZdZdgZed�Z�fdd�Zedd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zd dd�Zd!dd�Zedd��Zdd�Zdd�Z�ZS)"�DownloadCommandZdownloadz%Download package to current directorycs tt|��|�d|_d|_dS�N)�superr�__init__�opts�parser)�self�cli��	__class__��8/usr/lib/python3.9/site-packages/dnf-plugins/download.pyr
+szDownloadCommand.__init__c	Cs�|jddtd�d�|jddtd�d�|jd	dtd
�d�|jddtd�d�|jd
ddgtjdtd�d�|jddtd�d�|jddtd�d�|jddddtd�d�|jddgd�gtd�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�https�rsync�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
��|jjsN|jj
rZ|j	j
��|jjrr|jj|j	j_ntj�t���|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�|jjs(|jjs(|jjs(|�|jj�}nXg}|jjrH|�|�|jj��|jjrd|�|�|jj��|jjr�|�|�	|jj��|jj
r�|D]\}|jtj
kr�|j|jjd�}|r�t|�q�td�|j}|jjjr�tj�|��t�|�q�dS|�|�dS)zExecute the util action here.)�schemesz$Failed to get mirror for package: %sN)rr(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^s2��

zDownloadCommand.runcCsi}|D]}|�t|�g��|�qg}g}|��D]D}dd�|D�}|rZ|�|d�q4|jdd�d�|�|d�q4|r�|j�||jjj�|r�|D]V}|�	�}t
j�|jj
jt
j�|��}	t
j�|	�r�t
j�||	�r�q�t�||jj
j�q�tdd�||D��}
|
S)z=
        Perform the download for a list of packages
        cSsg|]}|jtjkr|�qSr)r:r;r<��.0rDrrr�
<listcomp>�s�z1DownloadCommand._do_downloads.<locals>.<listcomp>rcSs|jj|jjfSr)Zrepo�priorityZcost)�xrrr�<lambda>��z/DownloadCommand._do_downloads.<locals>.<lambda>)�keycSsg|]}|���qSr)�localPkgrGrrrrI�rM)�
setdefault�strr�values�sortr)Zdownload_packages�output�progressrOr1�path�joinr-r,�basename�exists�samefile�shutil�copy�sorted)r
rCZpkg_dictrDZto_downloadZcmdlineZpkg_listZpkgs_cmdline�src�dstZ	locationsrrrrB�s.zDownloadCommand._do_downloadscCs"|jjr|�|�}n
|�|�}|S)zc
        Return a list of dnf.Package objects that represent the rpms
        to download.
        )rr'�_get_packages_with_deps�
_get_packages)r
�	pkg_specsrCrrrr5�s
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_packages�setra)r
rbrC�source_pkgsrrrr7�s

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>�epoch�version�release�arch)rdr)�sack�query�	availableraZ
debug_nameZsource_debug_name�filter�intrgrhrirj�add)r
rb�dbg_pkgs�qrDZdbg_name�
dbg_available�prrrr8�s"�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
rbrqrrrDrsrtrrrr9�s�z)DownloadCommand._get_pkg_objs_debugsourceFcCs�|r
|jn|j}g}|D]v}z|�||��Wqtjjy�}zBt�tj�	|��|j
jjrxt�t
d��tj�|��WYd}~qd}~00qttj|��}|S)z Get packages matching pkg_specs.zExiting due to strict setting.N)�_get_query_source�
_get_queryrr.r@�PackageNotFoundErrorr�errorr/r0r)r-r?rrA�list�	itertools�chain)r
rbr(�funcZqueries�pkg_spec�erCrrrra�s
$zDownloadCommand._get_packagesc	Cs�|�|�}t|�}|D]�}t�|jj�}|�|�|��}|r\|�|�	��|�|�
��qtd�g}t�
d�|dd�|D���t�
tj�|����tj���q|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.<locals>.<listcomp>)rardr;ZGoalr)rk�installrF�updateZ
list_installsZ
list_upgradesrrrxrWr.�utilZ_format_resolve_problemsZ
problem_rulesr@rA)	r
rbr(rCZpkg_setrDZgoal�rcrErrrr`�s


z'DownloadCommand._get_packages_with_depscCsvt�}|D]b}|jr6|�|j�t�dt|�|j�q
|jdkrX|�d|j|jf�q
t�	t
d�t|��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	sourcerpmrpr�debugrQrjr>Zevr�inforry)rCrerDrrrrcs
�
z$DownloadCommand._get_source_packagescCs�tjj�|�d}|o|dv}|s8|�d�rdtj�|�rd|jj|g|jj	j
d�}|jj��j
|d�Stj�|�}|j|jj|jjd�}|��}|j
dd�}|jjr�|j|jjd	�}t|���dkr�td
�|}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)rj�No package %s available.)r.Zpycomp�urlparse�endswithr1rV�isfiler)Zadd_remote_rpmsrTrUrkrlZfilterm�subject�SubjectZget_best_queryrr(rmrrn�lenrFrr@rw)r
r}r4Zis_urlrC�subjrrrErrrrvszDownloadCommand._get_querycCsd|dd�}tj�|�}|��D]&}|�|jj���}|r |��Sq t	d�|}tj
�|��dS)z/Return a query to match a source rpm file name.N���r�)r.r�r�Zget_nevra_possibilitiesZto_queryr)rkrmZlatestrr@rw)r
r}r�Z	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.i18nZdnf.subjectZdnf.utilr;rzr1r[ZpluginZregister_commandrZCommandrrrrr�<module>s