ó
è¾bc           @   s¼   d  Z  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 m Z m Z m Z m Z d d	 l m Z d
 e f d „  ƒ  YZ d S(   sw   distutils.command.bdist_rpm

Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions).s   $Id$iÿÿÿÿN(   t   Command(   t   DEBUG(   t
   write_file(   t   get_python_version(   t   DistutilsOptionErrort   DistutilsPlatformErrort   DistutilsFileErrort   DistutilsExecError(   t   logt	   bdist_rpmc        +   B   sþ   e  Z d  Z d^ d_ d` da db dc dd de 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† g) Z d2 d7 d; d0 dS g Z i d2 d5 6d7 d9 6d; d= 6Z dV „  Z dW „  Z dX „  Z	 dY „  Z
 dZ „  Z d[ „  Z d\ „  Z RS(‡   s   create an RPM distributions   bdist-base=s/   base directory for creating built distributionss	   rpm-base=sd   base directory for creating RPMs (defaults to "rpm" under --bdist-base; must be specified for RPM 2)s	   dist-dir=t   dsD   directory to put final RPM files in (and .spec files if --spec-only)s   python=sM   path to Python interpreter to hard-code in the .spec file (default: "python")s
   fix-pythonsL   hard-code the exact path to the current Python interpreter in the .spec files	   spec-onlys   only regenerate spec files   source-onlys   only generate source RPMs   binary-onlys   only generate binary RPMs	   use-bzip2s7   use bzip2 instead of gzip to create source distributions   distribution-name=sg   name of the (Linux) distribution to which this RPM applies (*not* the name of the module distribution!)s   group=s9   package classification [default: "Development/Libraries"]s   release=s   RPM release numbers   serial=s   RPM serial numbers   vendor=sa   RPM "vendor" (eg. "Joe Blow <joe@example.com>") [default: maintainer or author from setup script]s	   packager=sB   RPM packager (eg. "Jane Doe <jane@example.net>") [default: vendor]s
   doc-files=s6   list of documentation files (space or comma-separated)s
   changelog=s   RPM changelogs   icon=s   name of icon files	   provides=s%   capabilities provided by this packages	   requires=s%   capabilities required by this packages
   conflicts=s-   capabilities which conflict with this packages   build-requires=s+   capabilities required to build this packages
   obsoletes=s*   capabilities made obsolete by this packages
   no-autoreqs+   do not automatically calculate dependenciess	   keep-tempt   ks"   don't clean up RPM build directorys   no-keep-temps&   clean up RPM build directory [default]s   use-rpm-opt-flagss8   compile with RPM_OPT_FLAGS when building from source RPMs   no-rpm-opt-flagss&   do not pass any RPM CFLAGS to compilers	   rpm3-modes"   RPM 3 compatibility mode (default)s	   rpm2-modes   RPM 2 compatibility modes   prep-script=s3   Specify a script for the PREP phase of RPM buildings   build-script=s4   Specify a script for the BUILD phase of RPM buildings   pre-install=s:   Specify a script for the pre-INSTALL phase of RPM buildings   install-script=s6   Specify a script for the INSTALL phase of RPM buildings   post-install=s;   Specify a script for the post-INSTALL phase of RPM buildings   pre-uninstall=s<   Specify a script for the pre-UNINSTALL phase of RPM buildings   post-uninstall=s=   Specify a script for the post-UNINSTALL phase of RPM buildings   clean-script=s4   Specify a script for the CLEAN phase of RPM buildings   verify-script=s6   Specify a script for the VERIFY phase of the RPM builds   force-arch=s0   Force an architecture onto the RPM build processt   quiett   qs3   Run 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(   Ni    i   ((   t   Nonet
   bdist_baset   rpm_baset   dist_dirt   pythont
   fix_pythont	   spec_onlyt   binary_onlyt   source_onlyt	   use_bzip2t   distribution_namet   groupt   releaset   serialt   vendort   packagert	   doc_filest	   changelogt   icont   prep_scriptt   build_scriptt   install_scriptt   clean_scriptt   verify_scriptt   pre_installt   post_installt   pre_uninstallt   post_uninstallt   prept   providest   requirest	   conflictst   build_requirest	   obsoletest	   keep_tempt   use_rpm_opt_flagst	   rpm3_modet
   no_autoreqt
   force_archR   (   t   self(    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyt   initialize_options   sN    																																						c         C   s  |  j  d d ƒ |  j d  k rR |  j s4 t d ‚ n  t j j |  j d ƒ |  _ n  |  j	 d  k r… |  j
 ry 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(   Nt   bdistR   s)   you must specify --rpm-base in RPM 2 modet   rpmR   s8   --python and --fix-python are mutually exclusive optionst   posixs9   don't know how to create RPM distributions on platform %ss6   cannot supply both '--source-only' and '--binary-only'i    R   (   R   R   (   R   R   (   t   set_undefined_optionsR   R   R2   R   t   ost   patht   joinR   R   R   t   syst
   executablet   nameR   R   R   t   distributiont   has_ext_modulesR1   t   finalize_package_data(   R5   (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyt   finalize_options½   s0    						c         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(   NR   s   Development/LibrariesR   s   %s <%s>R   R   t   READMEs
   README.txtR   t   1R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R+   R,   R-   R.   R/   R4   (   RE   s
   README.txt(   t   ensure_stringRA   t   get_contactt   get_contact_emailt   ensure_string_listt
   isinstanceR   t   listR;   R<   t   existst   appendt   _format_changelogR   t   ensure_filename(   R5   t   readme(    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyRC   ß   s>    	!c         C   s   t  r> d GHd G|  j GHd G|  j GHd G|  j GHd G|  j GHn  |  j r` |  j } |  j | ƒ nN i  } x; d( D]3 } t j	 j
 |  j | ƒ | | <|  j | | ƒ qm W| d } t j	 j
 | d |  j j ƒ  ƒ } |  j t | |  j ƒ  f d | ƒ |  j r d  S|  j j } |  j d ƒ } |  j r4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 ƒ rd g }	 n  |  j r)|	 j d ƒ n& |  j rB|	 j d ƒ n |	 j d ƒ |  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  } xt | j' ƒ  } | s(Pn  t( j) t( j* | ƒ ƒ } t+ | ƒ d# k sXt, ‚ | j | d$ ƒ | d  k r| d } qqW| j- ƒ  } | r±t. d% t/ | ƒ ƒ ‚ n  Wd  | j- ƒ  X|  j0 |	 ƒ |  j1 s|  j j2 ƒ  rñt3 ƒ  } n d& } |  j s{t j	 j
 | d
 | ƒ } t j	 j | ƒ s1t, ‚ |  j4 | |  j ƒ t j	 j
 |  j | ƒ } |  j j j d' | | f ƒ n  |  j s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‹Wqn  d  S()   Ns   before _get_package_data():s   vendor =s
   packager =s   doc_files =s   changelog =t   SOURCESt   SPECSt   BUILDt   RPMSt   SRPMSs   %s.specs   writing '%s't   sdistt   bztart   gztari    s   icon file '%s' does not exists   building RPMsR8   s   /usr/bin/rpmbuilds   /bin/rpmbuildt   rpmbuilds   -bss   -bbs   -bas   --defines
   _topdir %ss   --cleans   --quiets   %{name}-%{version}-%{release}s   .src.rpms   %{arch}/s   .%{arch}.rpms%   rpm -q --qf '%s %s\n' --specfile '%s'i   i   s   Failed to execute: %st   anyR	   (   RR   RS   RT   RU   RV   (6   R   R   R   R   R   R   R   t   mkpathR;   R<   R=   R   RA   t   get_namet   executeR   t   _make_spec_filet
   dist_filest   reinitialize_commandR   t   formatst   run_commandt   get_archive_filest	   copy_fileR    RM   R   R   t   infoR   RN   R   R2   t   extendt   abspathR0   R   t   popenR   t   readlinet   stringt   splitt   stript   lent   AssertionErrort   closeR   t   reprt   spawnt   dry_runRB   R   t	   move_filet   basename(   R5   t   spec_dirt   rpm_dirR
   t	   spec_patht   saved_dist_filesRW   t   sourcet
   source_dirt   rpm_cmdt
   nvr_stringt   src_rpmt   non_src_rpmt   q_cmdt   outt   binary_rpmst
   source_rpmt   linet   lt   statust	   pyversiont   srpmt   filenameR8   (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyt   run  sÄ    		
			
						 		
			c         C   s"   t  j j |  j t  j j | ƒ ƒ S(   N(   R;   R<   R=   R   Ru   (   R5   R<   (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyt
   _dist_path—  s    c         C   sõ  d |  j  j ƒ  d |  j  j ƒ  j d d ƒ d |  j  j ƒ  d |  j j d d ƒ d d |  j  j ƒ  g } | 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~ dB D]v } t |  t j | ƒ ƒ } t | t ƒ rj| j d | t j | ƒ f ƒ q| dC k	 r| j d | | f ƒ qqW|  j  j ƒ  d k rÆ| j d |  j  j ƒ  ƒ n  |  j ræ| j d |  j ƒ n  |  j r| j d t j |  j ƒ ƒ n  |  j r;| j d t j j |  j ƒ ƒ n  |  j rT| j d  ƒ n  | j d d! |  j  j ƒ  g ƒ d" |  j t j j t j d# ƒ f } d$ | } |  j  r¹d% | } n  d& | } dD d* d+ | f d, d- | f dE dF dG dH dI dJ g	 } xŠ | D]‚ \ } }	 }
 t |  |	 ƒ } | s'|
 rý| j d d; | g ƒ | ro| j t j! t" | d< ƒ j# ƒ  d= ƒ ƒ q| j |
 ƒ qýqýW| j d d> d? g ƒ |  j$ rÂ| j d@ t j |  j$ ƒ ƒ n  |  j% rñ| j d dA g ƒ | j |  j% ƒ n  | S(K   si   Generate the text of an RPM spec file and return it as a
        list of strings (one per line).
        s   %define name s   %define version t   -t   _s   %define unmangled_version s   %define release t    s	   Summary: s   Name: %{name}s   Version: %{version}s   Release: %{release}s-   Source0: %{name}-%{unmangled_version}.tar.bz2s,   Source0: %{name}-%{unmangled_version}.tar.gzs	   License: s   Group: s>   BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroots   Prefix: %{_prefix}s   BuildArch: noarchs   BuildArch: %st   Vendort   Packagert   Providest   Requirest	   Conflictst	   Obsoletess   %s: %st   UNKNOWNs   Url: s   Distribution: s   BuildRequires: s   Icon: s
   AutoReq: 0s   %descriptions   %s %si    s   %s builds   env CFLAGS="$RPM_OPT_FLAGS" s>   %s install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILESR*   R!   s&   %setup -n %{name}-%{unmangled_version}t   buildR"   t   installR#   t   cleanR$   s   rm -rf $RPM_BUILD_ROOTt   verifyscriptR%   t   preR&   t   postR'   t   preunR(   t   postunR)   t   %t   rs   
s   %files -f INSTALLED_FILESs   %defattr(-,root,root)s   %doc s
   %changelog(   R   R   R‘   R’   R“   R”   N(   R*   R!   s&   %setup -n %{name}-%{unmangled_version}(   R˜   R$   s   rm -rf $RPM_BUILD_ROOT(   R™   R%   N(   Rš   R&   N(   R›   R'   N(   Rœ   R(   N(   R   R)   N(&   RA   R]   t   get_versiont   replaceR   t   get_descriptionRg   R   RN   t   get_licenseR   R4   RB   t   getattrRk   t   lowerRK   RL   R=   R   t   get_urlR   R.   R    R;   R<   Ru   R3   t   get_long_descriptionR   R>   t   argvR1   Rl   t   opent   readR   R   (   R5   t	   spec_filet   fieldt   valt   def_setup_callt	   def_buildt   install_cmdt   script_optionst   rpm_optt   attrt   default(    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyR_   š  s¨    

	

	    
#				#	&
		+
	 	
c         C   s´   | s
 | Sg  } x‰ t  j t  j | ƒ d ƒ D]l } t  j | ƒ } | d d k rg | j d | g ƒ q, | d d k r‡ | j | ƒ q, | j d | ƒ q, W| d s° | d =n  | S(   sK   Format the changelog correctly and convert it to a list of strings
        s   
i    t   *RŽ   RŒ   s     (   Rk   Rl   Rm   Rg   RN   (   R5   R   t   new_changelogR„   (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyRO   5  s    "

N(   s   bdist-base=Ns/   base directory for creating built distributions(   s	   rpm-base=Nsd   base directory for creating RPMs (defaults to "rpm" under --bdist-base; must be specified for RPM 2)(   s	   dist-dir=R
   sD   directory to put final RPM files in (and .spec files if --spec-only)(   s   python=NsM   path to Python interpreter to hard-code in the .spec file (default: "python")(   s
   fix-pythonNsL   hard-code the exact path to the current Python interpreter in the .spec file(   s	   spec-onlyNs   only regenerate spec file(   s   source-onlyNs   only generate source RPM(   s   binary-onlyNs   only generate binary RPM(   s	   use-bzip2Ns7   use bzip2 instead of gzip to create source distribution(   s   distribution-name=Nsg   name of the (Linux) distribution to which this RPM applies (*not* the name of the module distribution!)(   s   group=Ns9   package classification [default: "Development/Libraries"](   s   release=Ns   RPM release number(   s   serial=Ns   RPM serial number(   s   vendor=Nsa   RPM "vendor" (eg. "Joe Blow <joe@example.com>") [default: maintainer or author from setup script](   s	   packager=NsB   RPM packager (eg. "Jane Doe <jane@example.net>") [default: vendor](   s
   doc-files=Ns6   list of documentation files (space or comma-separated)(   s
   changelog=Ns   RPM changelog(   s   icon=Ns   name of icon file(   s	   provides=Ns%   capabilities provided by this package(   s	   requires=Ns%   capabilities required by this package(   s
   conflicts=Ns-   capabilities which conflict with this package(   s   build-requires=Ns+   capabilities required to build this package(   s
   obsoletes=Ns*   capabilities made obsolete by this package(   s
   no-autoreqNs+   do not automatically calculate dependencies(   s	   keep-tempR   s"   don't clean up RPM build directory(   s   no-keep-tempNs&   clean up RPM build directory [default](   s   use-rpm-opt-flagsNs8   compile with RPM_OPT_FLAGS when building from source RPM(   s   no-rpm-opt-flagsNs&   do not pass any RPM CFLAGS to compiler(   s	   rpm3-modeNs"   RPM 3 compatibility mode (default)(   s	   rpm2-modeNs   RPM 2 compatibility mode(   s   prep-script=Ns3   Specify a script for the PREP phase of RPM building(   s   build-script=Ns4   Specify a script for the BUILD phase of RPM building(   s   pre-install=Ns:   Specify a script for the pre-INSTALL phase of RPM building(   s   install-script=Ns6   Specify a script for the INSTALL phase of RPM building(   s   post-install=Ns;   Specify a script for the post-INSTALL phase of RPM building(   s   pre-uninstall=Ns<   Specify a script for the pre-UNINSTALL phase of RPM building(   s   post-uninstall=Ns=   Specify a script for the post-UNINSTALL phase of RPM building(   s   clean-script=Ns4   Specify a script for the CLEAN phase of RPM building(   s   verify-script=Ns6   Specify a script for the VERIFY phase of the RPM build(   s   force-arch=Ns0   Force an architecture onto the RPM build process(   R   R   s3   Run the INSTALL phase of RPM building in quiet mode(   t   __name__t
   __module__t   descriptionR   t   user_optionst   boolean_optionst   negative_optR6   RD   RC   RŠ   R‹   R_   RO   (    (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyR	      s¾                                            		

	0	"	/	‰		›(   t   __doc__t   __revision__R>   R;   Rk   t   distutils.coreR    t   distutils.debugR   t   distutils.file_utilR   t   distutils.sysconfigR   t   distutils.errorsR   R   R   R   t	   distutilsR   R	   (    (    (    s1   /usr/lib/python2.7/distutils/command/bdist_rpm.pyt   <module>   s   "