
][\T                 @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l Td d l m Z d d	 l m Z Gd
 d   d e  Z d S)zwdistutils.command.bdist_rpm

Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions).    N)Command)DEBUG)get_platform)
write_file)*)get_python_version)logc            +   @   s  e  Z d  Z d Z df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d d d d d d d d d d d d d d d g) Z d4 d9 d= d2 dU g Z i d4 d7 6d9 d; 6d= d? 6Z dX dY   Z dZ d[   Z d\ d]   Z	 d^ d_   Z
 d` da   Z db dc   Z dd de   Z d S)	bdist_rpmzcreate an RPM distributionbdist-base=N/base directory for creating built distributions	rpm-base=dbase directory for creating RPMs (defaults to "rpm" under --bdist-base; must be specified for RPM 2)	dist-dir=dDdirectory to put final RPM files in (and .spec files if --spec-only)python=Mpath to Python interpreter to hard-code in the .spec file (default: "python")
fix-pythonLhard-code the exact path to the current Python interpreter in the .spec file	spec-onlyonly regenerate spec filesource-onlyonly generate source RPMbinary-onlyonly generate binary RPM	use-bzip27use bzip2 instead of gzip to create source distributiondistribution-name=gname of the (Linux) distribution to which this RPM applies (*not* the name of the module distribution!)group=9package classification [default: "Development/Libraries"]release=RPM release numberserial=RPM serial numbervendor=aRPM "vendor" (eg. "Joe Blow <joe@example.com>") [default: maintainer or author from setup script]	packager=ARPM packager (eg. "Jane Doe <jane@example.net>")[default: vendor]
doc-files=6list of documentation files (space or comma-separated)
changelog=RPM changelogicon=name of icon file	provides=%capabilities provided by this package	requires=%capabilities required by this package
conflicts=-capabilities which conflict with this packagebuild-requires=+capabilities required to build this package
obsoletes=*capabilities made obsolete by this package
no-autoreq+do not automatically calculate dependencies	keep-tempk"don't clean up RPM build directoryno-keep-temp&clean up RPM build directory [default]use-rpm-opt-flags8compile with RPM_OPT_FLAGS when building from source RPMno-rpm-opt-flags&do not pass any RPM CFLAGS to compiler	rpm3-mode"RPM 3 compatibility mode (default)	rpm2-modeRPM 2 compatibility modeprep-script=3Specify a script for the PREP phase of RPM buildingbuild-script=4Specify a script for the BUILD phase of RPM buildingpre-install=:Specify a script for the pre-INSTALL phase of RPM buildinginstall-script=6Specify a script for the INSTALL phase of RPM buildingpost-install=;Specify a script for the post-INSTALL phase of RPM buildingpre-uninstall=<Specify a script for the pre-UNINSTALL phase of RPM buildingpost-uninstall==Specify a script for the post-UNINSTALL phase of RPM buildingclean-script=4Specify a script for the CLEAN phase of RPM buildingverify-script=6Specify a script for the VERIFY phase of the RPM buildforce-arch=0Force an architecture onto the RPM build processquietq3Run the INSTALL phase of RPM building in quiet modec             C   sc  d  |  _  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _  d |  _! d |  _" d |  _# d |  _$ d  |  _% d |  _& d  S)Nr      )'
bdist_baserpm_basedist_dirpython
fix_python	spec_onlybinary_onlysource_only	use_bzip2distribution_namegroupreleaseserialvendorpackager	doc_files	changelogiconprep_scriptbuild_scriptinstall_scriptclean_scriptverify_scriptpre_installpost_installpre_uninstallpost_uninstallprepprovidesrequires	conflictsbuild_requires	obsoletes	keep_tempuse_rpm_opt_flags	rpm3_mode
no_autoreq
force_archr\   )self r   1/usr/lib/python3.4/distutils/command/bdist_rpm.pyinitialize_options   sN    																																						zbdist_rpm.initialize_optionsc             C   s  |  j  d d  |  j d  k rU |  j s7 t d   n  t j j |  j d  |  _ n  |  j d  k r |  j	 r| t
 j |  _ q d |  _ n |  j	 r t d   n  t j d k r t d t j   n  |  j r |  j r t d	   n  |  j j   sd
 |  _ n  |  j  d d  |  j   d  S)NZbdistr`   z)you must specify --rpm-base in RPM 2 moderpmZpython3z8--python and --fix-python are mutually exclusive optionsposixz9don't know how to create RPM distributions on platform %sz6cannot supply both '--source-only' and '--binary-only'r   rb   )
bdist_baser   )dist_dirr   )Zset_undefined_optionsra   r   ZDistutilsOptionErrorospathjoinr`   rc   rd   sys
executablenameZDistutilsPlatformErrorrf   rg   distributionhas_ext_modulesr   finalize_package_data)r   r   r   r   finalize_options   s.    			zbdist_rpm.finalize_optionsc             C   s  |  j  d d  |  j  d d |  j j   |  j j   f  |  j  d  |  j d  t |  j t  r xE d D]: } t j	 j
 |  ro | |  j k ro |  j j |  qo qo Wn  |  j  d	 d
  |  j  d  |  j  d  |  j  d  |  j |  j  |  _ |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j d  |  j  d  d  S)Nrj   zDevelopment/Librariesrm   z%s <%s>rn   ro   README
README.txtrk   1rl   ri   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r|   r}   r~   r   r   r   )r   r   )Zensure_stringr   Zget_contactZget_contact_emailZensure_string_list
isinstancero   listr   r   existsappend_format_changelogrp   Zensure_filename)r   Zreadmer   r   r   r      s>    	!zbdist_rpm.finalize_package_datac             C   sT  t  rS t d  t d |  j  t d |  j  t d |  j  t d |  j  n  |  j ru |  j } |  j |  nN i  } x; d) D]3 } t	 j
 j |  j |  | | <|  j | |  q W| d } t	 j
 j | d |  j j    } |  j t | |  j   f d |  |  j rd  S|  j j d  d   } |  j d  } |  j rRd g | _ n d g | _ |  j d  | |  j _ | j   d } | d } |  j | |  |  j rt	 j
 j |  j  r|  j |  j |  qt d |  j   n  t j d  d g }	 t	 j
 j d  s%t	 j
 j d  r1d g }	 n  |  j rJ|	 j d  n& |  j  rc|	 j d  n |	 j d  |	 j! d d |  j" g  |  j# r|	 j! d d t	 j
 j$ |  j  g  n  |  j% s|	 j d  n  |  j& r|	 j d  n  |	 j |  d }
 |
 d  } d! |
 d" } d# | | | f } t	 j' |  } z g  } d  } xm | j(   } | scPn  | j)   j*   } t+ |  d$ k st,  | j | d%  | d  k rM| d } qMqM| j-   } | rt. d& t/ |    n  Wd  | j-   X|  j0 |	  |  j1 sP|  j j2   r%t3   } n d' } |  j  st	 j
 j | d
 |  } t	 j
 j |  set,  |  j4 | |  j  t	 j
 j |  j |  } |  j j j d( | | f  n  |  j sPx | D] } t	 j
 j | d	 |  } t	 j
 j |  r|  j4 | |  j  t	 j
 j |  j t	 j
 j5 |   } |  j j j d( | | f  qqWqPn  d  S)*Nzbefore _get_package_data():zvendor =z
packager =zdoc_files =zchangelog =SOURCESSPECSBUILDRPMSSRPMSz%s.speczwriting '%s'sdistZbztarZgztarr   zicon file '%s' does not existzbuilding RPMsr   z/usr/bin/rpmbuildz/bin/rpmbuildZrpmbuildz-bsz-bbz-baz--definez__python %sz
_topdir %sz--cleanz--quietz%{name}-%{version}-%{release}z.src.rpmz%{arch}/z.%{arch}.rpmz%rpm -q --qf '%s %s\n' --specfile '%s'   r_   zFailed to execute: %sanyr	   )r   r   r   r   r   )6r   printrm   rn   ro   rp   re   rb   Zmkpathr   r   r   ra   r   get_nameZexecuter   _make_spec_fileZ
dist_filesZreinitialize_commandrh   ZformatsZrun_commandZget_archive_filesZ	copy_filerq   r   ZDistutilsFileErrorr   inforg   r   rf   extendrc   r   abspathr   r\   popenreadlinestripsplitlenAssertionErrorcloseZDistutilsExecErrorreprZspawnZdry_runr   r   Z	move_filebasename)r   Zspec_dirZrpm_dirr   Z	spec_pathZsaved_dist_filesr   sourceZ
source_dirZrpm_cmdZ
nvr_stringZsrc_rpmZnon_src_rpmZq_cmdoutZbinary_rpmsZ
source_rpmlinelZstatusZ	pyversionZsrpmfilenamer   r   r   r   run  s    
		
			
						 		
			zbdist_rpm.runc             C   s"   t  j j |  j t  j j |   S)N)r   r   r   rb   r   )r   r   r   r   r   
_dist_path  s    zbdist_rpm._dist_pathc             C   so  d |  j  j   d |  j  j   j d d  d |  j  j   d |  j j d d  d d |  j  j   g } t j d	  } d
 j d d   | j	   D  } d } d } | j | |  } | | k r | j
 d  | j
 d | d
  n  | j d d d g  |  j r| j
 d  n | j
 d  | j d |  j  j   d |  j d d g  |  j s|  j  j   s| j
 d  qn | j
 d |  j  x{ dK D]s } t |  | j    } t | t  r| j
 d" | d# j |  f  q| d$ k	 r| j
 d" | | f  qqW|  j  j   d% k rC| j
 d& |  j  j    n  |  j rc| j
 d' |  j  n  |  j r| j
 d( d# j |  j   n  |  j r| j
 d) t j j |  j   n  |  j r| j
 d*  n  | j d d+ |  j  j   g  d, |  j t j j t j  d-  f } d. | }	 |  j! r6d/ |	 }	 n  d0 | }
 dL d4 d5 |	 f d6 d7 |
 f dM dN dO dP dQ dR g	 } x | D] \ } } } t |  |  } | s| rz| j d dE | g  | r| j t" | dF  j#   j$ d
   q| j
 |  qzqzW| j d dG dH g  |  j% r<| j
 dI d# j |  j%   n  |  j& rk| j d dJ g  | j |  j&  n  | S)SziGenerate the text of an RPM spec file and return it as a
        list of strings (one per line).
        z%define name z%define version -_z%define unmangled_version z%define release  z	Summary: zrpm --eval %{__os_install_post}
c             S   s    g  |  ] } d  | j     q S)z  %s \)r   ).0r   r   r   r   
<listcomp>  s   	z-bdist_rpm._make_spec_file.<locals>.<listcomp>zbrp-python-bytecompile \
z%brp-python-bytecompile %{__python} \
z2# Workaround for http://bugs.python.org/issue14443z%define __os_install_post zName: %{name}zVersion: %{version}zRelease: %{release}z-Source0: %{name}-%{unmangled_version}.tar.bz2z,Source0: %{name}-%{unmangled_version}.tar.gzz	License: zGroup: z>BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildrootzPrefix: %{_prefix}zBuildArch: noarchzBuildArch: %sVendorPackagerProvidesRequires	Conflicts	Obsoletesz%s: %s NZUNKNOWNzUrl: zDistribution: zBuildRequires: zIcon: z
AutoReq: 0z%descriptionz%s %sr   z%s buildzenv CFLAGS="$RPM_OPT_FLAGS" z>%s install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILESr{   rr   &%setup -n %{name}-%{unmangled_version}Zbuildrs   Zinstallrt   cleanru   rm -rf $RPM_BUILD_ROOTverifyscriptrv   prerw   postrx   preunry   postunrz   %rz%files -f INSTALLED_FILESz%defattr(-,root,root)z%doc z
%changelog)r   r   r   r   r   r   )zprepzprep_scriptr   )r   zclean_scriptr   )r   zverify_scriptN)r   zpre_installN)r   zpost_installN)r   zpre_uninstallN)r   zpost_uninstallN)'r   r   Zget_versionreplacerk   Zget_description
subprocessZ	getoutputr   
splitlinesr   r   rh   Zget_licenserj   r   r   getattrlowerr   r   Zget_urlri   r   rq   r   r   r   r   Zget_long_descriptionrc   r   argvr   openreadr   ro   rp   )r   Z	spec_fileZvendor_hookZproblemZfixedZ
fixed_hookZfieldvalZdef_setup_callZ	def_buildZinstall_cmdZscript_optionsZrpm_optattrdefaultr   r   r   r     s    	
	

	    
#				#	&
		(
	 	
zbdist_rpm._make_spec_filec             C   s   | s
 | Sg  } x | j    j d  D]i } | j    } | d d k r^ | j d | g  q& | d d k r~ | j |  q& | j d |  q& W| d s | d =n  | S)zKFormat the changelog correctly and convert it to a list of strings
        r   r   r   r   r   z  )r   r   r   r   )r   rp   Znew_changelogr   r   r   r   r   3  s    

zbdist_rpm._format_changelog)r
   Nr   )r   Nr   )r   r   r   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr   )r   Nr    )r!   Nr"   )r#   Nr$   )r%   Nr&   )r'   Nr(   )r)   Nr*   )r+   Nr,   )r-   Nr.   )r/   Nr0   )r1   Nr2   )r3   Nr4   )r5   Nr6   )r7   Nr8   )r9   Nr:   )r;   r<   r=   )r>   Nr?   )r@   NrA   )rB   NrC   )rD   NrE   )rF   NrG   )rH   NrI   )rJ   NrK   )rL   NrM   )rN   NrO   )rP   NrQ   )rR   NrS   )rT   NrU   )rV   NrW   )rX   NrY   )rZ   Nr[   )zquietr]   r^   )__name__
__module____qualname__ZdescriptionZuser_optionsZboolean_optionsZnegative_optr   r   r   r   r   r   r   r   r   r   r   r	      s                                            		

--r	   )__doc__r   r   r   Zdistutils.corer   Zdistutils.debugr   Zdistutils.utilr   Zdistutils.file_utilr   Zdistutils.errorsZdistutils.sysconfigr   Z	distutilsr   r	   r   r   r   r   <module>   s   $
