
    ZQd!T                         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
T ddlmZ ddlmZ  G 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)
write_file)*)get_python_version)logc                   X    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dS )	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| _&        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   selfs    2/usr/lib/python3.11/distutils/command/bdist_rpm.pyinitialize_optionszbdist_rpm.initialize_options   s%   !%
	 " ! !"	"!"


    c                 b   |                      dd           | j        @| j        st          d          t          j                            | j        d          | _        | j        !| j	        rt          j        | _        nd| _        n| j	        rt          d          t          j        dk    rt          dt          j        z            | j        r| j        rt          d	          | j                                        sd
| _        |                      dd           |                                  d S )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;   DistutilsOptionErrorospathjoinr   r   r   sys
executablenameDistutilsPlatformErrorr   r   distributionhas_ext_modulesr:   finalize_package_datar>   s    r@   finalize_optionszbdist_rpm.finalize_options   sU   ""7,HIII= > C*AC C CGLL%@@DM; (!n'_ 	N&LN N N 7g( *246G*< = = = 	L 0 	L&JL L L  0022 	'%&D"""7,DEEE""$$$$$rB   c                 d   |                      dd           |                      d| j                                        d| j                                        d           |                      d           |                     d           t          | j        t                    rGdD ]D}t          j	        
                    |          r#|| j        vr| j                            |           E|                      d	d
           |                      d           |                      d           |                      d           |                     | j                  | _        |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                      d           d S )Nr"   zDevelopment/Librariesr%   z <>r&   r'   )READMEz
README.txtr#   1r$   r!   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r4   r5   r6   r7   r8   r=   )ensure_stringrQ   get_contactget_contact_emailensure_string_list
isinstancer'   listrJ   rK   existsappend_format_changelogr(   ensure_filename)r?   readmes     r@   rS   zbdist_rpm.finalize_package_data   s   7$;<<<8(,(9(E(E(G(G(G(G(,(9(K(K(M(M(M(MO	P 	P 	P 	:&&&,,,dnd++ 	22 2 27>>&)) 2fDN.J.JN))&1119c***8$$$.///;'''//??V$$$]+++^,,,-...^,,,_---]+++^,,,_----... 	
+++
+++,,, 0111,,,<(((((rB   c                    t           rct          d           t          d| j                   t          d| j                   t          d| j                   t          d| j                   | j        r| j        }|                     |           nRi }dD ]E}t          j
                            | j        |          ||<   |                     ||                    F|d         }t          j
                            |d| j                                        z            }|                     t           ||                                 fd	|z             | j        rd S | j        j        d d          }|                     d
          }| j        r	dg|_        ndg|_        |                     d
           || j        _        |                                d         }|d         }|                     ||           | j        rWt          j
                            | j                  r|                     | j        |           nt7          d| j        z            t9          j        d           dg}	| j        r|	                    d           n2| j         r|	                    d           n|	                    d           |	!                    dd| j"        z  g           | j#        r<|	!                    ddt          j
        $                    | j                  z  g           | j%        s|	                    d           | j&        r|	                    d           |	                    |           d}
|
dz   }d|
z   dz   }d|d|d |d!}t          j'        |          }	 g }d }	 |(                                }|sna|)                                *                                }tW          |          d#k    sJ |                    |d$                    ||d         }x|,                                }|rt[          d%t]          |          z            	 |,                                 n# |,                                 w xY w| /                    |	           | j0        s| j        1                                rte                      }nd&}| j         st          j
                            |d'         |          }t          j
                            |          sJ | 3                    || j                   t          j
                            | j        |          }| j        j                            d(||f           | j        s|D ]}t          j
                            |d)         |          }t          j
                            |          r| 3                    || j                   t          j
                            | j        t          j
        4                    |                    }| j        j                            d(||f           d S d S d S )*Nzbefore _get_package_data():zvendor =z
packager =zdoc_files =zchangelog =)SOURCESSPECSBUILDRPMSSRPMSrf   z%s.speczwriting '%s'sdistbztargztarr   re   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 ' z\n' --specfile ''T   r   zFailed to execute: %sanyri   r
   rh   )5r   printr%   r&   r'   r(   r   r   mkpathrJ   rK   rL   r   rQ   get_nameexecuter   _make_spec_file
dist_filesreinitialize_commandr    formatsrun_commandget_archive_files	copy_filer)   r_   DistutilsFileErrorr   infor   r`   r   extendr   r;   abspathr9   r   popenreadlinestripsplitlencloseDistutilsExecErrorreprspawndry_runrR   r   	move_filebasename)r?   spec_dirrpm_dirr   	spec_pathsaved_dist_filesrj   source
source_dirrpm_cmd
nvr_stringsrc_rpmnon_src_rpmq_cmdoutbinary_rpms
source_rpmlinelstatus	pyversionsrpmfilenamerE   s                           r@   runzbdist_rpm.run   sJ    	1/000*dk***,...-000-000 > 	(}HKK!!!!GC ( (W\\$-;;
GAJ''''w'H GLL!*T->-G-G-I-I!IK K	Z**,,.#i/	1 	1 	1
 > 	F  ,7:))'22> 	&$IEMM$IEM!!!'7$((**1-Y'
vz***9 	Cw~~di(( Cty*5555(5	AC C C 	!!!, 	"NN5!!!! 	"NN5!!!!NN5!!!
MDK$?@AAA> 	MNNJ)BGOODM,J,JJL M M M~ 	&NN9%%%: 	&NN9%%%y!!!
 5
z) :->GG[[[)))- huoo	KJ	&||~~ JJLL&&((1vv{{{{""1Q4(((%!"1J	& YY[[F P()@4;;)NOOOP IIKKKKCIIKKKK

7| 	@ 0022 ".00		!	# 8w||GG$4jAAw~~d++,,,tT]3337<<zBB!,33 )X68 8 8 # @& @ @C',,wv<<Cw~~c** @sDM:::#%7<<020@0@0E0E$G $G)4;;()X>@ @ @+	@ 	@@ @@ @s   B2Q Q2c                     t           j                            | j        t           j                            |                    S )N)rJ   rK   rL   r   r   )r?   rK   s     r@   
_dist_pathzbdist_rpm._dist_path  s*    w||DM27+;+;D+A+ABBBrB   c           	      
   d| j                                         z   d| j                                                             dd          z   d| j                                         z   d| j                            dd          z   dd| j                                         z   g}t          j        d	          }d
                    d |	                                D                       }d}d}|                    ||          }||k    r0|
                    d           |
                    d|z   d
z              |                    g d           | j        r|
                    d           n|
                    d           |                    d| j                                         z   d| j        z   ddg           | j        s/| j                                         s|
                    d           n|
                    d| j        z             dD ]}t#          | |                                          }t'          |t(                    r.|
                    |dd                    |                     g||
                    |d|           | j                                         dk    r/|
                    d| j                                         z              | j        r|
                    d| j        z              | j        r0|
                    d d                    | j                  z              | j        r:|
                    d!t2          j                            | j                  z              | j        r|
                    d"           |                    dd#| j                                         g           | j        dt2          j                            t>          j         d$                   }d%|z  }	| j!        rd&|	z   }	d'|z  }
d(d)d*|	fd+d,|
fd-d.d/d0d1d2g	}|D ]\  }}}t#          | |          }|s|r|                    dd3|z   g           |rbtE          |          5 }|                    |#                                $                    d
                     ddd           n# 1 swxY w Y   |
                    |           |                    g d4           | j%        r0|
                    d5d                    | j%                  z              | j&        r1|                    dd6g           |                    | j&                   |S )7ziGenerate 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                 <    g | ]}d |                                 z  S )z  %s \)r   ).0r   s     r@   
<listcomp>z-bdist_rpm._make_spec_file.<locals>.<listcomp>  s;     !G !G !G%) "+TZZ\\!9 !G !G !GrB   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: rn   NUNKNOWNzUrl: zDistribution: zBuildRequires: zIcon: z
AutoReq: 0z%descriptionr   z%s buildzenv CFLAGS="$RPM_OPT_FLAGS" z>%s install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES)r3   r*   z&%setup -n %{name}-%{unmangled_version}buildr+   installr,   )cleanr-   zrm -rf $RPM_BUILD_ROOT)verifyscriptr.   N)prer/   N)postr0   N)preunr1   N)postunr2   N%)r   z%files -f INSTALLED_FILESz%defattr(-,root,root)z%doc z
%changelog)'rQ   rt   get_versionreplacer#   get_description
subprocess	getoutputrL   
splitlinesr`   r   r    get_licenser"   r=   rR   getattrlowerr]   r^   get_urlr!   r7   r)   rJ   rK   r   r<   get_long_descriptionr   rM   argvr:   openreadr   r'   r(   )r?   	spec_filevendor_hookproblemfixed
fixed_hookfieldvaldef_setup_call	def_buildinstall_cmdscript_optionsrpm_optattrdefaultfs                   r@   rv   zbdist_rpm._make_spec_file  sE    d/88:::!2!>!>!@!@!H!HS!Q!QQ(4+<+H+H+J+JJ!5!5c#!>!>>$+;;===	 !*+LMM ii !G !G-8-C-C-E-E!G !G !G H H/9 ((%88
$$QRRR9JFMNNN 	 $ $ $ 	% 	% 	% > 	MLMMMMKLLL$+77999
"L 	$ 	% 	% 	%  	B$4466 6  !4555o?AAA 	: 	:E $..C#t$$ :  UUUCHHSMMM!BCCCC  UUUCC!8999 $$&&)33Wt'8'@'@'B'BBCCC! 	H-0FFGGG 	<. XXd&9::; < < < 9 	EX(8(8(C(CCDDD? 	+\***2244 	 	 	$ %)KKK0@0@!0M0M0MN/	! 	C6BI25CD Nni0(+6?3(*,.

 )7 	. 	.$WdG $%%C .g .  'M"$ % % %  .c ?a!(()=)=>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $$W--- 	    	 	 	 > 	AWsxx'?'??@@@> 	-       T^,,,s   -;R44R8	;R8	c                 `   |s|S g }|                                                     d          D ]t}|                                 }|d         dk    r|                    d|g           :|d         dk    r|                    |           \|                    d|z              u|d         s|d= |S )zKFormat the changelog correctly and convert it to a list of strings
        r   r   r   r   r   z  )r   r   r   r`   )r?   r(   new_changelogr   s       r@   ra   zbdist_rpm._format_changelog0  s      	OO%%++D11 	2 	2D::<<DAw#~~$$b$Z0000aC$$T****$$TD[1111 Q 	!a rB   N)__name__
__module____qualname__descriptionuser_optionsboolean_optionsnegative_optrA   rT   rS   r   r   rv   ra    rB   r@   r
   r
      s        .Kk
 k
 k
LZ. . .O %0(;!,. .L
+ + +Z% % %>+) +) +)ZB@ B@ B@HC C Cg g gR    rB   r
   )__doc__r   rM   rJ   distutils.corer   distutils.debugr   distutils.file_utilr   distutils.errorsdistutils.sysconfigr   	distutilsr   r
   r   rB   r@   <module>r      s    
             " " " " " " ! ! ! ! ! ! * * * * * *     2 2 2 2 2 2      u u u u u u u u u urB   