3 f$@sddlmZddlmZddlmZmZddlZddlZddlZddl Zddl Zddl Zddl Z ddlZddlZddlZddlZejjGdddejjZdS))absolute_import)unicode_literals)_loggerNcseZdZdZdZeeZedZfddZddZ d d Z e d d Z d dZ ddZddZe ddZddZddZddZddZZS)BuildDepCommandbuilddep build-depz3Install build dependencies for package or spec filez[PACKAGE|PACKAGE.spec]cs(tt|j|tjjj|_g|_dS)N) superr__init__dnfrpmZ transactionZinitReadOnlyTransaction_rpm_tstempdirs)selfcli) __class__/usr/lib/python3.6/builddep.pyr /szBuildDepCommand.__init__cCsx|jD]}tj|qWdS)N)rshutilZrmtree)rtemp_dirrrr__del__4s zBuildDepCommand.__del__cCstjjj|}|ddkr |jStjj}tjdd}t jj |t jj |}|j j |t|d}zFy|j|jjj||jWn$tk r}zWYdd}~XnXWd|jX|S) z In case pkgspec is a remote URL, download it to a temporary location and use the temporary file instead. rfileZ dnf_builddep_)prefixzwb+N)rr)r ZpycompZurlparsepathlibdnfZrepoZ DownloadertempfileZmkdtemposjoinbasenamerappendopenZ downloadURLbaseZconfZ_configfileno RuntimeErrorclose)rpkgspeclocationZ downloaderrZ temp_fileZtemp_foexrrr_download_remote_file8s      z%BuildDepCommand._download_remote_filec Csdd}|jdddtdd|jdd d gd |td d |jdddtdd|j}|jddtdd|jddtdddS)NcSs:|r|jddng}t|dkr6td|}tj||S)Nz&'%s' is not of the format 'MACRO EXPR')splitlenrargparseZArgumentTypeError)argZarglistmsgrrr macro_defRs    z0BuildDepCommand.set_argparser..macro_defpackages+packagez"packages with builddeps to install)nargsmetavarhelpz-Dz--definer z 'MACRO EXPR'z$define a macro for spec file parsing)actiondefaultr6typer7z--skip-unavailable store_trueFz5skip build dependencies not available in repositories)r8r9r7z--specz)treat commandline arguments as spec files)r8r7z--srpmz)treat commandline arguments as source rpm) add_argumentrZadd_mutually_exclusive_group)parserr1Zptyperrr set_argparserPs       zBuildDepCommand.set_argparsercCs|jjsd|j_dS)Nerror)optsZ rpmverbosity)rrrr pre_configurefszBuildDepCommand.pre_configurecCsr|jj}d|_d|_d|_d|_|jjp.|jjsnx<|jj D]0}|j dpZ|j dpZ|j ds:|j j j Pq:WdS)NTz.src.rpmz .nosrc.rpmz.spec)rdemandsZavailable_reposZ resolvingZ root_userZsack_activationr@specsrpmr2endswithr"ZreposZenable_source_repos)rrBr&rrr configurejs    zBuildDepCommand.configurecCs\tjjj|j}x$|jjD]}tj|d|dqWd}x|jj D]}|j |}yl|jj rh|j |nT|jj r||j|n@|jds|jdr|j |n |jdr|j|n |j|WqDtjjk r}z:x$|jD]}tjtdj|qWtj|d}WYdd}~XqDXqDWx |jjD]}tj|dq*W|rXtjjtd dS) Nrr*Fz.src.rpmz nosrc.rpmz.speczRPM: {}Tz!Some packages could not be found.)r ZyumZrpmtransZRPMTransactionr"r@definer ZaddMacror2r)rD _src_depsrC _spec_depsrE _remote_deps exceptionsErrorZmessagesrr?rformatZdelMacro)rZrpmlogZmacroZ pkg_errorsr&elinerrrrunzs2       zBuildDepCommand.runcCs|jddS)Nr+)ZDNEVR)Zrpm_deprrr_rpm_dep2reldep_strsz#BuildDepCommand._rpm_dep2reldep_strcCstjj|jj}|j|d|j}| rX|jdrXtjj|jj}|j|d|j}| r|jd rtd}t j |||j j dkS|r|jj |}|rx|D]}tjj|qW|jjj|dddS) N)Zprovides/)r(z$No matching package to install: '%s'TF)ZselectZoptional)r ZselectorZSelectorr"sacksetZmatches startswithrrwarningr@Zskip_unavailableZ_sltr_matches_installedZ_msg_installedZ_goalZinstall)r reldep_strZsltrfoundr0Z already_instr4rrr_installs$      zBuildDepCommand._installc Cstj|tj}y|jj|}WnRtjk rp}z4t|dkrJtd|}tj |t j j |WYdd}~XnXtj ||j d}d}x0|D](}|j|}|jdrq||j|M}qW|std} t j j | |jjrtjtddS)Nzerror reading package headerz2Failed to open: '%s', not a valid source rpm file.Z requirenameTzrpmlib(zNot all dependencies satisfiedzJWarning: -D or --define arguments have no meaning for source rpm packages.)rr!O_RDONLYr Z hdrFromFdnor r?strrr%r rKrLZ dsFromHeaderrQrVrZr@rGrrW) rZsrc_fnfdhrNdsdonedeprXerrrrrrHs*         zBuildDepCommand._src_depsc Csytj|}Wn>tk rL}z"td||f}tjj|WYdd}~XnXd}x.tj|jdD]}|j |}||j |M}qbW|std}tjj|dS)Nz/Failed to open: '%s', not a valid spec file: %sTrequireszNot all dependencies satisfied) r rC ValueErrorrr rKrLr_Z sourceHeaderrQrZ) rZspec_fnrCr(r0r`rarXrbrrrrIs  zBuildDepCommand._spec_depsc Cstjj|j|jjjdd}tdd|D}|jjjj j||gddj j }|sptj j td|d}x.|D]&}x |jD]}||jt|M}qWqzW|std}tj j |dS) Nsrc)Z arch__neqcSsh|] }|jqSr)Z source_name).0pkgrrr sz/BuildDepCommand._remote_deps..)nameZarchzno package matched: %sTzNot all dependencies satisfied)r ZsubjectZSubjectZget_best_queryr"rTfilterlistZquery availableZlatestrPrKrLrrcrZr\) rr4rlZ sourcenamesZpkgsr`rgZreqrbrrrrJs   zBuildDepCommand._remote_deps)rr)__name__ __module__ __qualname__aliasesr0rZsummaryZusager rr) staticmethodr>rArFrPrQrZrHrIrJ __classcell__rr)rrr's   ! r)Z __future__rrZdnfpluginscorerrr.r Zdnf.cliZdnf.exceptionsZdnf.rpm.transactionZdnf.yum.rpmtransZ libdnf.reporrr rrZpluginZregister_commandrZCommandrrrrrs