B
    ›³ëbŽ  ã               @   sª   d Z d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„ Zdd„ Zdd	„ Zej ee¡Zejjej d
d¡ejjddZdd„ Zdd„ ZdS )aT  SCons.Tool.rpm

Tool-specific initialization for rpm.

There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.

The rpm tool calls the rpmbuild command. The first and only argument should a
tar.gz consisting of the source file and a specfile.
z,__FILE__ __REVISION__ __DATE__ __DEVELOPER__é    Nc             C   s2   | }t j | ¡r| d }d|d |d | ¡ f S )Nr   z%s %s %sÚRPMÚRPMFLAGS)ÚSConsÚUtilZis_ListÚget_abspath)ÚsourceÚenvZtar_file_with_included_specfile© r	   ú-lib/python3.7/site-packages/SCons/Tool/rpm.pyÚget_cmd1   s
    r   c          	   C   sN  t j t j | d  ¡ ¡d¡}t j |¡r4t |¡ x dD ]}t  t j ||¡¡ q:W |j	d| d t
jt||ƒt
jt
jdd}|j tj |j ¡ ¡}W d Q R X | ¡ }|rÒtjj| d |t| d ƒd‚nnt d	¡ |¡}x\t|| ƒD ]N\}}	t j |¡}
t j |	 ¡ ¡}||
ks,td
|
|f ƒ‚t ||	 ¡ ¡ qîW t |¡ |S )Nr   Zrpmtemp)ZRPMSZSRPMSZSPECSZBUILDz--define '_topdir %s')r   T)ÚstdoutÚstderrÚshell)ZnodeZerrstrÚfilenamezWrote: (.*)zgot %s but expected %s) ÚosÚpathÚjoinÚdirnamer   ÚexistsÚshutilZrmtreeÚmakedirsZPrependÚ
subprocessÚPopenr   ÚPIPEZSTDOUTr   r   r   Zto_strÚreadÚwaitZErrorsZ
BuildErrorÚstrÚreÚcompileÚfindallÚzipÚbasenameZget_pathÚAssertionErrorÚcopy)Útargetr   r   ZtmpdirÚdZhandleÚoutputZstatusZoutput_filesÚinputZ
rpm_outputZexpectedr	   r	   r
   Ú	build_rpm8   s2    


r(   c             C   s(   y|d S  t k
r"   t||ƒS X d S )NZ	RPMCOMSTR)ÚKeyErrorr   )r$   r   r   r	   r	   r
   Ú
string_rpmc   s    r*   z$RPMCOMz
$RPMCOMSTRz
$RPMSUFFIX)ÚactionZsource_scannerÚsuffixc             C   sr   y| d d }W n$ t k
r4   t}|| d d< Y nX | jdd | jtj d¡d | jtd | jdd	 d
S )zBAdd Builders and construction variables for rpm to an Environment.ZBUILDERSZRpmzLC_ALL=C rpmbuild)r   z-ta)r   )ZRPMCOMz.rpm)Z	RPMSUFFIXN)r)   Ú
RpmBuilderZ
SetDefaultr   r   ZCLVarÚ	rpmAction)r   Zbldr	   r	   r
   Úgenerateq   s    r/   c             C   s
   |   d¡S )NZrpmbuild)ZDetect)r   r	   r	   r
   r   ~   s    r   )Ú__doc__Z__revision__r   r   r   r   ZSCons.Builderr   ZSCons.Node.FSZ
SCons.UtilZSCons.ActionZSCons.Defaultsr   r(   r*   ZActionr.   ZBuilderZDefaultsZ
DirScannerr-   r/   r   r	   r	   r	   r
   Ú<module>   s&   +