<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
f$                 @   s   d dl mZ d dl mZ d dlmZmZ d dlZd dlZd dlZd dl	Zd dl
Zd dlZd dlZd dlZd dlZd dlZd dlZejjG dd dejjZdS )    )absolute_import)unicode_literals)_loggerNc                   s   e Zd ZdZdZeeZedZ fddZdd Z	d	d
 Z
edd Zdd Zdd Zdd Zedd Zdd Zdd Zdd Zdd Z  ZS )BuildDepCommandbuilddep	build-depz3Install build dependencies for package or spec filez[PACKAGE|PACKAGE.spec]c                s(   t t| j| tjjj | _g | _d S )N)	superr   __init__dnfrpmZtransactionZinitReadOnlyTransaction_rpm_tstempdirs)selfcli)	__class__ /usr/lib/python3.6/builddep.pyr
   /   s    zBuildDepCommand.__init__c             C   s   x| j D ]}tj| qW d S )N)r   shutilZrmtree)r   temp_dirr   r   r   __del__4   s    zBuildDepCommand.__del__c             C   s   t jjj|}|d dkr |jS tjj }tjdd}t	jj
|t	jj|}| jj| t|d}zFy|j| jjj||j  W n$ tk
r } z W Y dd}~X nX W d|j  X |S )	z
        In case pkgspec is a remote URL, download it to a temporary location
        and use the temporary file instead.
        r   file Zdnf_builddep_)prefixzwb+N)r   r   )r   ZpycompZurlparsepathlibdnfZrepoZ
DownloadertempfileZmkdtemposjoinbasenamer   appendopenZdownloadURLbaseZconfZ_configfilenoRuntimeErrorclose)r   pkgspeclocationZ
downloaderr   Z	temp_fileZtemp_foexr   r   r   _download_remote_file8   s    


z%BuildDepCommand._download_remote_filec          	   C   s   dd }| j dddtdd | j dd	d
g d|tdd | j dddtdd | j }|j ddtdd |j ddtdd d S )Nc             S   s:   | r| j d dng }t|dk r6td|  }tj||S )N      z&'%s' is not of the format 'MACRO EXPR')splitlenr   argparseZArgumentTypeError)argZarglistmsgr   r   r   	macro_defR   s
    
z0BuildDepCommand.set_argparser.<locals>.macro_defpackages+packagez"packages with builddeps to install)nargsmetavarhelpz-Dz--definer    z'MACRO EXPR'z$define a macro for spec file parsing)actiondefaultr6   typer7   z--skip-unavailable
store_trueFz5skip build dependencies not available in repositories)r8   r9   r7   z--specz)treat commandline arguments as spec files)r8   r7   z--srpmz)treat commandline arguments as source rpm)add_argumentr   Zadd_mutually_exclusive_group)parserr1   Zptyper   r   r   set_argparserP   s    

zBuildDepCommand.set_argparserc             C   s   | j jsd| j _d S )Nerror)optsZrpmverbosity)r   r   r   r   pre_configuref   s    zBuildDepCommand.pre_configurec             C   sr   | j j}d|_d|_d|_d|_| jjp.| jjsnx<| jj	D ]0}|j
dpZ|j
dpZ|j
ds:| jjj  P q:W d S )NTz.src.rpmz
.nosrc.rpmz.spec)r   demandsZavailable_reposZ	resolvingZ	root_userZsack_activationr@   specsrpmr2   endswithr"   ZreposZenable_source_repos)r   rB   r&   r   r   r   	configurej   s    


zBuildDepCommand.configurec             C   s\  t jjj| j}x$| jjD ]}tj|d |d  qW d}x| jj	D ]}| j
|}yl| jjrh| j| nT| jjr|| j| n@|jds|jdr| j| n |jdr| j| n
| j| W qD t jjk
r } z:x$|j D ]}tjtdj| qW tj| d}W Y d d }~X qDX qDW x | jjD ]}tj|d  q*W |rXt jjtd	d S )
Nr   r*   Fz.src.rpmz	nosrc.rpmz.speczRPM: {}Tz!Some packages could not be found.)r   ZyumZrpmtransZRPMTransactionr"   r@   definer   ZaddMacror2   r)   rD   	_src_depsrC   
_spec_depsrE   _remote_deps
exceptionsErrorZmessagesr   r?   r   formatZdelMacro)r   ZrpmlogZmacroZ
pkg_errorsr&   eliner   r   r   runz   s2    


zBuildDepCommand.runc             C   s   | j  dd  S )Nr+   )ZDNEVR)Zrpm_depr   r   r   _rpm_dep2reldep_str   s    z#BuildDepCommand._rpm_dep2reldep_strc             C   s   t jj| jj}|j|d |j }| rX|jdrXt jj| jj}|j|d |j }| r|jd rtd}t	j
|| | jjdkS |r| jj|}|rx|D ]}t jj| qW | jjj|dd dS )	N)Zprovides/)r   (z$No matching package to install: '%s'TF)ZselectZoptional)r   ZselectorZSelectorr"   sacksetZmatches
startswithr   r   warningr@   Zskip_unavailableZ_sltr_matches_installedZ_msg_installedZ_goalZinstall)r   
reldep_strZsltrfoundr0   Zalready_instr4   r   r   r   _install   s$    
zBuildDepCommand._installc       
      C   s   t j|t j}y| jj|}W nR tjk
rp } z4t|dkrJtd| }t j	| t
jj|W Y d d }~X nX t j	| |jd}d}x0|D ](}| j|}|jdrq|| j|M }qW |std}	t
jj|	| jjrtjtd d S )Nzerror reading package headerz2Failed to open: '%s', not a valid source rpm file.ZrequirenameTzrpmlib(zNot all dependencies satisfiedzJWarning: -D or --define arguments have no meaning for source rpm packages.)r   r!   O_RDONLYr   ZhdrFromFdnor   r?   strr   r%   r   rK   rL   ZdsFromHeaderrQ   rV   rZ   r@   rG   r   rW   )
r   Zsrc_fnfdhrN   dsdonedeprX   errr   r   r   rH      s*    





zBuildDepCommand._src_depsc       	      C   s   yt j|}W n> tk
rL } z"td||f }tjj|W Y d d }~X nX d}x.t j|jdD ]}| j	|}|| j
|M }qbW |std}tjj|d S )Nz/Failed to open: '%s', not a valid spec file: %sTrequireszNot all dependencies satisfied)r   rC   
ValueErrorr   r   rK   rL   r_   ZsourceHeaderrQ   rZ   )	r   Zspec_fnrC   r(   r0   r`   ra   rX   rb   r   r   r   rI      s    

zBuildDepCommand._spec_depsc       	      C   s   t jj|j| jjjdd}tdd |D }| jjj j	 j||g ddj
 j }|spt jjtd| d}x.|D ]&}x |jD ]}|| jt|M }qW qzW |std}t jj|d S )	Nsrc)Z	arch__neqc             S   s   h | ]
}|j qS r   )Zsource_name).0pkgr   r   r   	<setcomp>   s    z/BuildDepCommand._remote_deps.<locals>.<setcomp>)nameZarchzno package matched: %sTzNot all dependencies satisfied)r   ZsubjectZSubjectZget_best_queryr"   rT   filterlistZquery	availableZlatestrP   rK   rL   r   rc   rZ   r\   )	r   r4   rl   ZsourcenamesZpkgsr`   rg   Zreqrb   r   r   r   rJ      s    
zBuildDepCommand._remote_deps)r   r   )__name__
__module____qualname__aliasesr0   r   ZsummaryZusager
   r   r)   staticmethodr>   rA   rF   rP   rQ   rZ   rH   rI   rJ   __classcell__r   r   )r   r   r   '   s    !r   )Z
__future__r   r   Zdnfpluginscorer   r   r.   r   Zdnf.cliZdnf.exceptionsZdnf.rpm.transactionZdnf.yum.rpmtransZlibdnf.repor   r   r   r   r   ZpluginZregister_commandr   ZCommandr   r   r   r   r   <module>   s   