o
     JAf!T  ã                   @   sr   	 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	„ d	eƒZdS )
é    N)ÚCommand)ÚDEBUG)Ú
write_file)Ú*)Úget_python_version)Úlogc                   @   sd   e Zd ZdZg d¢Zg d¢ZddddœZdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zd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                 C   sî   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=   ú2/usr/lib/python3.10/distutils/command/bdist_rpm.pyÚinitialize_options‡   sN   
zbdist_rpm.initialize_optionsc                 C   sº   |   dd¡ | jd u r| jstdƒ‚tj | jd¡| _| jd u r,| j	r(t
j| _nd| _n| j	r3tdƒ‚tjdkr?tdtj ƒ‚| jrI| jrItd	ƒ‚| j ¡ sQd
| _|   dd¡ |  ¡  d S )NZbdist)r   r   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   )r   r   )Zset_undefined_optionsr   r8   ZDistutilsOptionErrorÚosÚpathÚjoinr   r   r   ÚsysÚ
executableÚnameZDistutilsPlatformErrorr   r   ÚdistributionÚhas_ext_modulesr7   Úfinalize_package_datar;   r=   r=   r>   Úfinalize_options´   s6   
ÿ

ÿ
ÿÿ
zbdist_rpm.finalize_optionsc                 C   sT  |   dd¡ |   dd| j ¡ | j ¡ f ¡ |   d¡ |  d¡ t| jtƒr<dD ]}tj	 
|¡r;|| jvr;| j |¡ q(|   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%s <%s>r#   r$   )ZREADMEz
README.txtr    Ú1r!   r   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r1   r2   r3   r4   r5   r:   )Zensure_stringrH   Zget_contactZget_contact_emailZensure_string_listÚ
isinstancer$   ÚlistrB   rC   ÚexistsÚappendÚ_format_changelogr%   Zensure_filename)r<   Zreadmer=   r=   r>   rJ   Ó   sD   
ÿÿ

€

















zbdist_rpm.finalize_package_datac                 C   sœ  t rtdƒ td| jƒ td| jƒ td| jƒ td| jƒ | jr*| j}|  |¡ ni }dD ]}t	j
 | j|¡||< |  || ¡ q.|d }t	j
 |d| j ¡  ¡}|  t||  ¡ fd	| ¡ | jrdd S | jjd d … }|  d
¡}| jrydg|_ndg|_|  d
¡ || j_| ¡ d }|d }|  ||¡ | jr¯t	j
 | j¡r¨|  | j|¡ ntd| j ƒ‚t d¡ dg}	| jrÀ|	 d¡ n| j rÉ|	 d¡ n|	 d¡ |	 !dd| j" g¡ | j#ré|	 !ddt	j
 $| j¡ g¡ | j%sñ|	 d¡ | j&rù|	 d¡ |	 |¡ d}
|
d }d|
 d }d|||f }t	 '|¡}z:g }d }	 | (¡ }|s$n| )¡  *¡ }| |d  ¡ |d u r:|d }q| +¡ }|rKt,d!t-|ƒ ƒ‚W | +¡  n| +¡  w |  .|	¡ | j/sÈ| j 0¡ rit1ƒ }nd"}| j s‘t	j
 |d# |¡}|  2|| j¡ t	j
 | j|¡}| jj d$||f¡ | jsÊ|D ]4}t	j
 |d% |¡}t	j
 |¡rÆ|  2|| j¡ t	j
 | jt	j
 3|¡¡}| jj d$||f¡ q—d S d S d S )&Nzbefore _get_package_data():zvendor =z
packager =zdoc_files =zchangelog =)ÚSOURCESÚSPECSÚBUILDÚRPMSÚSRPMSrS   z%s.speczwriting '%s'ÚsdistÚbztarÚgztarr   rR   zicon file '%s' does not existzbuilding RPMsZ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'Tr   zFailed to execute: %sÚanyrV   r   rU   )4r   Úprintr"   r#   r$   r%   r   r   ZmkpathrB   rC   rD   r   rH   Úget_nameZexecuter   Ú_make_spec_fileZ
dist_filesZreinitialize_commandr   ÚformatsZrun_commandZget_archive_filesZ	copy_filer&   rO   ZDistutilsFileErrorr   Úinfor   rP   r   Úextendr   r8   Úabspathr6   r   ÚpopenÚreadlineÚstripÚsplitÚcloseZDistutilsExecErrorÚreprÚspawnÚdry_runrI   r   Z	move_fileÚbasename)r<   Zspec_dirZrpm_dirr	   Z	spec_pathZsaved_dist_filesrW   ÚsourceZ
source_dirZrpm_cmdZ
nvr_stringZsrc_rpmZnon_src_rpmZq_cmdÚoutZbinary_rpmsZ
source_rpmÚlineÚlÚstatusZ	pyversionZsrpmÚfilenamer@   r=   r=   r>   Úrun   sÚ   ÿÿý


ÿ

ÿ


ÿ

÷ÿ
ÿ

ÿÿ€ëzbdist_rpm.runc                 C   s   t j | jt j |¡¡S )N)rB   rC   rD   r   rj   )r<   rC   r=   r=   r>   Ú
_dist_path„  s   zbdist_rpm._dist_pathc              	   C   sL  	 d| j  ¡  d| j  ¡  dd¡ d| j  ¡  d| j dd¡ dd| j  ¡  g}t d	¡}d
 dd„ | 	¡ D ƒ¡}d}d}| ||¡}||krU| 
d¡ | 
d| d
 ¡ | g d¢¡ | jre| 
d¡ n| 
d¡ | d| j  ¡  d| j ddg¡ | js‰| j  ¡ sˆ| 
d¡ n| 
d| j ¡ dD ](}t| | ¡ ƒ}t|tƒr®| 
d|d |¡f ¡ q“|d ur»| 
d||f ¡ q“| j  ¡ dkrÍ| 
d| j  ¡  ¡ | jrØ| 
d| j ¡ | jræ| 
d d | j¡ ¡ | jrõ| 
d!tj | j¡ ¡ | jrý| 
d"¡ | dd#| j  ¡ g¡ d$| jtj tj d% ¡f }d&| }	| j!r"d'|	 }	d(| }
d)d*d+|	fd,d-|
fd.d/d0d1d2d3g	}|D ]C\}}}t| |ƒ}|sI|r{| dd4| g¡ |rvt"|ƒ}| | #¡  $d
¡¡ W d   ƒ n	1 sow   Y  q9| 
|¡ q9| g d5¢¡ | j%r“| 
d6d | j%¡ ¡ | j&r¤| dd7g¡ | | j&¡ |S )8Nz%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 |  ¡  ‘qS )z  %s \)rd   )Ú.0rm   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)ZVendorZPackagerZProvidesZRequiresZ	ConflictsZ	Obsoletesz%s: %sú Z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_FILES)r0   r'   z&%setup -n %{name}-%{unmangled_version}Zbuildr(   Úinstallr)   )Zcleanr*   zrm -rf $RPM_BUILD_ROOT)Zverifyscriptr+   N)Úprer,   N)Zpostr-   N)Zpreunr.   N)Zpostunr/   Nú%)ru   z%files -f INSTALLED_FILESz%defattr(-,root,root)z%doc z
%changelog)'rH   r\   Zget_versionÚreplacer    Zget_descriptionÚ
subprocessÚ	getoutputrD   Ú
splitlinesrP   r`   r   Zget_licenser   r:   rI   ÚgetattrÚlowerrM   rN   Zget_urlr   r4   r&   rB   rC   rj   r9   Zget_long_descriptionr   rE   Úargvr7   ÚopenÚreadre   r$   r%   )r<   Z	spec_fileZvendor_hookZproblemÚfixedZ
fixed_hookZfieldÚvalZdef_setup_callZ	def_buildZinstall_cmdZscript_optionsZrpm_optÚattrÚdefaultÚfr=   r=   r>   r]   ‡  sÄ   ú

ÿ
	
ü

€
€
ÿ
ýÿ÷
þ
ÿ€
€þzbdist_rpm._make_spec_filec                 C   s~   	 |s|S g }|  ¡  d¡D ]'}|  ¡ }|d dkr"| d|g¡ q|d dkr.| |¡ q| d| ¡ q|d s=|d= |S )Nrv   r   r   ru   rs   z  )rd   re   r`   rP   )r<   r%   Znew_changelogrm   r=   r=   r>   rQ   0  s   zbdist_rpm._format_changelogN)Ú__name__Ú
__module__Ú__qualname__ÚdescriptionZuser_optionsZboolean_optionsZnegative_optr?   rK   rJ   rq   rr   r]   rQ   r=   r=   r=   r>   r      s"    mþ--  *r   )r~   rE   rB   Zdistutils.corer   Zdistutils.debugr   Zdistutils.file_utilr   Zdistutils.errorsZdistutils.sysconfigr   Z	distutilsr   r   r=   r=   r=   r>   Ú<module>   s    