
    
_dU                         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mZmZmZ ddlmZ dd	lmZ  G d
 de      Zy)zwdistutils.command.bdist_rpm

Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions).    N   )Command)DEBUG)
write_file)DistutilsOptionErrorDistutilsPlatformErrorDistutilsFileErrorDistutilsExecError)get_python_version)logc                   V    e Zd ZdZg dZg dZddddZd Zd	 Zd
 Z	d Z
d Zd Zd Zy)	bdist_rpmzcreate an RPM distribution)))zbdist-base=Nz/base directory for creating built distributions)z	rpm-base=Nzdbase directory for creating RPMs (defaults to "rpm" under --bdist-base; must be specified for RPM 2))z	dist-dir=dzDdirectory to put final RPM files in (and .spec files if --spec-only))zpython=NzMpath to Python interpreter to hard-code in the .spec file (default: "python"))z
fix-pythonNzLhard-code the exact path to the current Python interpreter in the .spec file)z	spec-onlyNzonly regenerate spec file)zsource-onlyNzonly generate source RPM)zbinary-onlyNzonly generate binary RPM)z	use-bzip2Nz7use bzip2 instead of gzip to create source distribution)zdistribution-name=Nzgname of the (Linux) distribution to which this RPM applies (*not* the name of the module distribution!))zgroup=Nz9package classification [default: "Development/Libraries"])zrelease=NzRPM release number)zserial=NzRPM serial number)zvendor=NzaRPM "vendor" (eg. "Joe Blow <joe@example.com>") [default: maintainer or author from setup script])z	packager=NzBRPM packager (eg. "Jane Doe <jane@example.net>") [default: vendor])z
doc-files=Nz6list of documentation files (space or comma-separated))z
changelog=NzRPM changelog)zicon=Nzname of icon file)z	provides=Nz%capabilities provided by this package)z	requires=Nz%capabilities required by this package)z
conflicts=Nz-capabilities which conflict with this package)zbuild-requires=Nz+capabilities required to build this package)z
obsoletes=Nz*capabilities made obsolete by this package)
no-autoreqNz+do not automatically calculate dependencies)	keep-tempkz"don't clean up RPM build directory)no-keep-tempNz&clean up RPM build directory [default])use-rpm-opt-flagsNz8compile with RPM_OPT_FLAGS when building from source RPM)no-rpm-opt-flagsNz&do not pass any RPM CFLAGS to compiler)	rpm3-modeNz"RPM 3 compatibility mode (default))	rpm2-modeNzRPM 2 compatibility mode)zprep-script=Nz3Specify a script for the PREP phase of RPM building)zbuild-script=Nz4Specify a script for the BUILD phase of RPM building)zpre-install=Nz:Specify a script for the pre-INSTALL phase of RPM building)zinstall-script=Nz6Specify a script for the INSTALL phase of RPM building)zpost-install=Nz;Specify a script for the post-INSTALL phase of RPM building)zpre-uninstall=Nz<Specify a script for the pre-UNINSTALL phase of RPM building)zpost-uninstall=Nz=Specify a script for the post-UNINSTALL phase of RPM building)zclean-script=Nz4Specify a script for the CLEAN phase of RPM building)zverify-script=Nz6Specify a script for the VERIFY phase of the RPM build)zforce-arch=Nz0Force an architecture onto the RPM build process)quietqz3Run the INSTALL phase of RPM building in quiet mode)r   r   r   r   r   r   r   r   )r   r   r   c                 &   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| _&        y )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   selfs    I/usr/lib/python3/dist-packages/setuptools/_distutils/command/bdist_rpm.pyinitialize_optionszbdist_rpm.initialize_options   s!   !%
	 " ! !"	"!"
    c                    | j                  dd       | j                  F| j                  st        d      t        j
                  j                  | j                  d      | _        | j                  *| j                  rt        j                  | _        nd| _        n| j                  rt        d      t        j                  dk7  rt        dt        j                  z        | j                  r| j                  rt        d	      | j                   j#                         sd
| _        | j                  dd       | j'                          y )Nbdist)r   r   z)you must specify --rpm-base in RPM 2 moderpm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   )r   r   )set_undefined_optionsr   r?   r   ospathjoinr   r   r    sys
executablenamer   r"   r#   distributionhas_ext_modulesr>   finalize_package_datarB   s    rD   finalize_optionszbdist_rpm.finalize_options   s
   ""7,HI== >>*+VWWGGLL%@DM;;!nn'__&J  77g(NQSQXQXX   0 0&H 
   002%&D"""7,DE""$rF   c                    | j                  dd       | j                  d| j                  j                         d| j                  j                         d       | j                  d       | j	                  d       t        | j                  t              rQdD ]L  }t        j                  j                  |      s#|| j                  vs2| j                  j                  |       N | 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       y )Nr&   zDevelopment/Librariesr)   z <>r*   r+   )READMEz
README.txtr'   1r(   r%   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r8   r9   r:   r;   r<   rA   )ensure_stringrS   get_contactget_contact_emailensure_string_list
isinstancer+   listrM   rN   existsappend_format_changelogr,   ensure_filename)rC   readmes     rD   rU   zbdist_rpm.finalize_package_data   s   7$;<  ,,.0A0A0S0S0UW	

 	:&,dnnd+2 277>>&)fDNN.JNN))&12 	9c*8$./;'//?V$]+^,-.^,_-]+^,_--. 	
+
+, 01,<(rF   c                 v   t         rct        d       t        d| j                         t        d| j                         t        d| j                         t        d| j
                         | j                  r| j                  }| j                  |       nOi }dD ]C  }t        j                  j                  | j                  |      ||<   | j                  ||          E |d   }t        j                  j                  |d| j                  j                         z        }| j                  t         || j#                         fd	|z         | j                  ry | j                  j$                  d d  }| j'                  d
      }| j(                  r	dg|_        ndg|_        | j-                  d
       || j                  _        |j/                         d   }d   }| j1                  ||       | j2                  r^t        j                  j5                  | j2                        r| j1                  | j2                  |       nt7        d| j2                  z        t9        j:                  d       dg}	| j<                  r|	j?                  d       n/| j@                  r|	j?                  d       n|	j?                  d       |	jC                  dd| jD                  z  g       | jF                  r=|	jC                  ddt        j                  jI                  | j                        z  g       | jJ                  s|	j?                  d       | jL                  r|	j?                  d       |	j?                  |       d}
|
dz   }d|
z   dz   }djO                  |||      }t        jP                  |      }	 g }d }	 |jS                         }|snJ|jU                         jW                         }tY        |      dk(  sJ |j?                  |d           ||d   }]|j[                         }|rt]        d!t_        |      z        	 |j[                          | ja                  |	       | jb                  s| j                  je                         rtg               }nd"}| j@                  st        j                  j                  |d#   |      }t        j                  j5                  |      sJ | ji                  || j                         t        j                  j                  | j                  |      }| j                  j$                  j?                  d$||f       | j<                  s|D ]  }t        j                  j                  |d%   |      }t        j                  j5                  |      sF| ji                  || j                         t        j                  j                  | j                  t        j                  jk                  |            }| j                  j$                  j?                  d$||f        y y y # |j[                          w xY w)&Nzbefore _get_package_data():zvendor =z
packager =zdoc_files =zchangelog =)SOURCESSPECSBUILDRPMSSRPMSrh   z%s.speczwriting '%s'sdistbztargztarr   rg   zicon file '%s' does not existzbuilding RPMsrpmbuildz-bsz-bbz-baz--definez__python %sz
_topdir %sz--cleanz--quietz%{name}-%{version}-%{release}z.src.rpmz%{arch}/z.%{arch}.rpmz%rpm -q --qf '{} {}\n' --specfile '{}'r   r   zFailed to execute: %sanyrk   r   rj   )6r   printr)   r*   r+   r,   r!   r   mkpathrM   rN   rO   r   rS   get_nameexecuter   _make_spec_file
dist_filesreinitialize_commandr$   formatsrun_commandget_archive_files	copy_filer-   ra   r	   r   infor#   rb   r"   extendr   r?   abspathr=   r   formatpopenreadlinestripsplitlencloser
   reprspawndry_runrT   r   	move_filebasename)rC   spec_dirrpm_dirr   	spec_pathsaved_dist_filesrl   source
source_dirrpm_cmd
nvr_stringsrc_rpmnon_src_rpmq_cmdoutbinary_rpms
source_rpmlineellstatus	pyversionsrpmfilenamerI   s                           rD   runzbdist_rpm.run  s   /0*dkk*,.-0-0 >>}}HKK!GC (WW\\$--;
GAJ'( w'H GGLL9t7H7H7Q7Q7S+ST	D$8$8$:;^i=W	
 >>  ,,77:))'2>>$IEM$IEM!'7$((*1-Y'
vz*99ww~~dii(tyy*5()H499)TUU 	!,NN5!NN5!NN5!
MDKK$?@A>>NNJrwwt}}7U(UVW~~NN9%::NN9%y!
 5
z) :->8??
 hhuo	KJ||~jjl((*3x1}$}""3q6*%!$QJ  YY[F()@4;)NOO  IIK

7||  002.0	!	##ww||GG$4jAww~~d+++tT]]377<<zB!!,,33[)X4VW##& C'',,wv<Cww~~c*sDMM:#%77<<rww?O?OPS?T#U))44;;()X> $ 	 IIKs   #BX& &X8c                     t         j                  j                  | j                  t         j                  j	                  |            S )N)rM   rN   rO   r   r   )rC   rN   s     rD   
_dist_pathzbdist_rpm._dist_path  s*    ww||DMM277+;+;D+ABBrF   c           	      
   d| j                   j                         z   d| j                   j                         j                  dd      z   d| j                   j                         z   d| j                  j                  dd      z   dd| j                   j                         xs d	z   g}t        j                  d
      }dj                  |j                         D cg c]  }d|j                         z   c}      }d}d}|j                  ||      }||k7  r(|j                  d       |j                  d|z   dz          |j                  g d       | j                  r|j                  d       n|j                  d       |j                  d| j                   j                         xs d	z   d| j                  z   ddg       | j                   s,| j                   j#                         s0|j                  d       n|j                  d| j                   z         dD ]  }t%        | |j'                               }t)        |t*              r1|j                  dj-                  |dj                  |                   ^|a|j                  dj-                  ||              | j                   j/                         r,|j                  d| j                   j/                         z          | j0                  r|j                  d| j0                  z          | j2                  r-|j                  d dj                  | j2                        z          | j4                  r;|j                  d!t6        j8                  j;                  | j4                        z          | j<                  r|j                  d"       |j                  dd#| j                   j?                         xs dg       d$j-                  | j@                  t6        j8                  j;                  tB        jD                  d%               }	d&|	z  }
| jF                  rd'|
z   }
d(|	z  }d)d*d+|
fd,d-|fd.d/d0d1d2d3g	}|D ]  \  }}}t%        | |      }|s|s|j                  dd4|z   g       |rCtI        |      5 }|j                  |jK                         jM                  d             ddd       s|j                  |        |j                  g d5       | jN                  r-|j                  d6dj                  | jN                        z          | jP                  r.|j                  dd7g       |j                  | jP                         |S c c}w # 1 sw Y   xY w)8ziGenerate 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: UNKNOWNzrpm --eval %{__os_install_post}
z  %s \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{}: {} NzUrl: zDistribution: zBuildRequires: zIcon: z
AutoReq: 0z%descriptionz{} {}r   z%s buildzenv CFLAGS="$RPM_OPT_FLAGS" z>%s install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES)r7   r.   z&%setup -n %{name}-%{unmangled_version}buildr/   installr0   )cleanr1   zrm -rf $RPM_BUILD_ROOT)verifyscriptr2   N)prer3   N)postr4   N)preunr5   N)postunr6   N%)r   z%files -f INSTALLED_FILESz%defattr(-,root,root)z%doc z
%changelog))rS   rs   get_versionreplacer'   get_description
subprocess	getoutputrO   
splitlinesr   rb   r}   r$   get_licenser&   rA   rT   getattrlowerr_   r`   r   get_urlr%   r;   r-   rM   rN   r   r@   get_long_descriptionr   rP   argvr>   openreadr   r+   r,   )rC   	spec_filevendor_hookr   problemfixed
fixed_hookfieldvaldef_setup_call	def_buildinstall_cmdscript_optionsrpm_optattrdefaultfs                    rD   ru   zbdist_rpm._make_spec_file  s    d//88::!2!2!>!>!@!H!Hc!RR(4+<+<+H+H+JJ!5!5c3!??4,,<<>K)L
	 !**+LM ii2=2H2H2JK$Y%K
 09 ((%8
$QR9JFMN 		
 >>LMKLt00<<>K)LDJJ&P$		
 $$446  !45_t>?
 	>E $.C#t$  !FG  !<=	> $$&Wt'8'8'@'@'BBC!!-0F0FFG.$:M:M1NNO99X(8(8(CCD??\*!!668>B	
( !RWW5E5Echhqk5RS/	!!6BI P
 Nni0(+6?3(*,.

 '5 	."GT7 $%Cg  g c ?a!(()=>? ? $$W-	.$ 		
 >>Wsxx'??@>>  T^^,E LP? ?s   U/U##U-	c                    |s|S g }|j                         j                  d      D ]\  }|j                         }|d   dk(  r|j                  d|g       /|d   dk(  r|j                  |       I|j                  d|z          ^ |d   s|d= |S )zBFormat the changelog correctly and convert it to a list of stringsr   r   *r   r   z  )r   r   r}   rb   )rC   r,   new_changelogr   s       rD   rc   zbdist_rpm._format_changelogT  s    OO%++D1 	2D::<DAw#~$$b$Z0aC$$T*$$TD[1	2 Qa rF   N)__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optrE   rV   rU   r   r   ru   rc    rF   rD   r   r      sT    .KoLbO $/ L+Z%B-)^@DCwrrF   r   )__doc__r   rP   rM   corer   debugr   	file_utilr   errorsr   r   r	   r
   	sysconfigr   distutils._logr   r   r   rF   rD   <module>r      s>   
  
 	   "  + O	 O	rF   