o
    LK&hU  ã                   @   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mZmZmZmZ dd	lmZ dd
lmZ G dd„ de	ƒZdS )zwdistutils.command.bdist_rpm

Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions).é    N)Úlog)ÚClassVaré   )ÚCommand)ÚDEBUG)ÚDistutilsExecErrorÚDistutilsFileErrorÚDistutilsOptionErrorÚDistutilsPlatformError)Ú
write_file)Úget_python_versionc                   @   s   e Zd ZU dZg d¢Zg d¢Zeee  e	d< ddddœZ
eeeef  e	d	< d
d„ Zddd„Zddd„Zd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   Úboolean_optionsr   r   r   )r   r   r   Únegative_optc                 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 )NFT)'Ú
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© rC   úZ/var/www/html/venv/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.pyÚinitialize_optionsš   sN   
zbdist_rpm.initialize_optionsÚreturnNc                 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rJ| jrJtd	ƒ‚| j ¡ sRd
| _|   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Úposixz7don't know how to create RPM distributions on platform z6cannot supply both '--source-only' and '--binary-only'F)r   r   )Úset_undefined_optionsr   r>   r	   ÚosÚpathÚjoinr   r   r   ÚsysÚ
executableÚnamer
   r!   r"   ÚdistributionÚhas_ext_modulesr=   Úfinalize_package_datarA   rC   rC   rD   Úfinalize_optionsÇ   s2   


ÿ

ÿÿ
zbdist_rpm.finalize_optionsc                 C   sX  |   dd¡ |   d| j ¡ › d| j ¡ › d¡ |   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 <ú>r)   r*   )ÚREADMEz
README.txtr&   Ú1r'   r$   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r7   r8   r9   r:   r;   r@   )Úensure_stringrR   Úget_contactÚget_contact_emailÚensure_string_listÚ
isinstancer*   ÚlistrL   rM   ÚexistsÚappendÚ_format_changelogr+   Úensure_filename)rB   ÚreadmerC   rC   rD   rT   è   sB   þ

€

















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
 || j ¡ › d¡}|  t||  ¡ fd	|› d
¡ | jrgd S | jjd d … }|  d¡}| jr|dg|_ndg|_|  d¡ || j_| ¡ d }|d }|  ||¡ | jr´t	j
 | j¡r«|  | j|¡ n	td| j› dƒ‚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 |› d!|› d"|› d
}t	 '|¡}zBg }d }	 | (¡ }|s1n!| )¡  *¡ }t+|ƒd$ks@J ‚| |d% ¡ |d u rP|d }q)| ,¡ }|r`t-d&|›ƒ‚W | ,¡  n| ,¡  w |  .|	¡ | j/sæ| j 0¡ r~t1ƒ }nd'}| j s¯t	j
 |d( |¡}t	j
 |¡s–J ‚|  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ÚSRPMSre   z.specz	writing 'ú'ÚsdistÚbztarÚgztarr   rd   zicon file 'z' does not existzbuilding RPMsÚrpmbuildz-bsz-bbz-baz--definez	__python z_topdir z--cleanz--quietz%{name}-%{version}-%{release}z.src.rpmz%{arch}/z.%{arch}.rpmzrpm -q --qf 'ú z\n' --specfile 'Tr   é   zFailed to execute: Úanyrh   r   rg   )4r   Úprintr(   r)   r*   r+   r    r   ÚmkpathrL   rM   rN   r   rR   Úget_nameÚexecuter   Ú_make_spec_fileÚ
dist_filesÚreinitialize_commandr#   ÚformatsÚrun_commandÚget_archive_filesÚ	copy_filer,   r_   r   r   Úinfor"   r`   r!   Úextendr   r>   Úabspathr<   r   ÚpopenÚreadlineÚstripÚsplitÚlenÚcloser   ÚspawnÚdry_runrS   r   Ú	move_fileÚbasename)rB   Ú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ÚellÚstatusÚ	pyversionÚsrpmÚfilenamerH   rC   rC   rD   Úrun  sÄ   ÿ









÷ÿ
ý€ízbdist_rpm.runc                 C   s   t j | jt j |¡¡S )N)rL   rM   rN   r   rˆ   )rB   rM   rC   rC   rD   Ú
_dist_path–  s   zbdist_rpm._dist_pathc              	   C   s`  d| j  ¡  d| j  ¡  dd¡ d| j  ¡  d| j dd¡ dd| j  ¡ p&d	 g}t d
¡}d dd„ | 	¡ D ƒ¡}d}d}| ||¡}||krV| 
d¡ | 
d| d ¡ | g d¢¡ | jrf| 
d¡ n| 
d¡ | d| j  ¡ ptd	 d| j ddg¡ | jsŒ| j  ¡ s‹| 
d¡ n	| 
d| j› ¡ dD ])}t| | ¡ ƒ}t|tƒr²| 
d |d |¡¡¡ q—|durÀ| 
|› d|› ¡ q—| j  ¡ rÐ| 
d | j  ¡  ¡ | jrÛ| 
d!| j ¡ | jré| 
d"d | j¡ ¡ | jrø| 
d#tj | j¡ ¡ | jr| 
d$¡ | dd%| j  ¡ pdg¡ | j› dtj t j!d& ¡› }|› d'}	| j"r+d(|	 }	|› d)}
d*d+d,|	fd-d.|
fd/d0d1d2d3d4g	}|D ]C\}}}t| |ƒ}|sS|r…| dd5| g¡ |r€t#|ƒ}| | $¡  %d¡¡ W d  ƒ n	1 syw   Y  qC| 
|¡ qC| g d6¢¡ | j&r| 
d7d | j&¡ ¡ | j'r®| dd8g¡ | | j'¡ |S )9ziGenerate 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}Ú
c                 S   s   g | ]
}d |  ¡ › d‘qS )ú  z \)r   )Ú.0r—   rC   rC   rD   Ú
<listcomp>­  s    ÿz-bdist_rpm._make_spec_file.<locals>.<listcomp>zbrp-python-bytecompile \
z%brp-python-bytecompile %{__python} \
z3# Workaround for https://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: )ÚVendorÚPackagerÚProvidesÚRequiresÚ	ConflictsÚ	Obsoletesz{}: {}rn   Nz: zUrl: zDistribution: zBuildRequires: zIcon: z
AutoReq: 0z%descriptionr   z buildzenv CFLAGS="$RPM_OPT_FLAGS" z< install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES)r6   r-   z&%setup -n %{name}-%{unmangled_version}Úbuildr.   Úinstallr/   )Úcleanr0   zrm -rf $RPM_BUILD_ROOT)Úverifyscriptr1   N)Úprer2   N)Úpostr3   N)Úpreunr4   N)Úpostunr5   Nú%)r¡   z%files -f INSTALLED_FILESz%defattr(-,root,root)z%doc z
%changelog)(rR   rs   Úget_versionÚreplacer&   Úget_descriptionÚ
subprocessÚ	getoutputrN   Ú
splitlinesr`   r}   r#   Úget_licenser%   r@   rS   ÚgetattrÚlowerr]   r^   ÚformatÚget_urlr$   r:   r,   rL   rM   rˆ   r?   Úget_long_descriptionr   rO   Úargvr=   ÚopenÚreadr‚   r*   r+   )rB   Ú	spec_fileÚvendor_hookÚproblemÚfixedÚ
fixed_hookÚfieldÚvalÚdef_setup_callÚ	def_buildÚinstall_cmdÚscript_optionsÚrpm_optÚattrÚdefaultÚfrC   rC   rD   ru   ™  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 )zBFormat the changelog correctly and convert it to a list of stringsr£   r   Ú*r¡   rŸ   r¤   )r   r‚   r}   r`   )rB   r+   Únew_changelogr—   rC   rC   rD   ra   D  s   zbdist_rpm._format_changelog)rF   N)Ú__name__Ú
__module__Ú__qualname__ÚdescriptionÚuser_optionsr   r   r^   ÚstrÚ__annotations__r   ÚdictrE   rU   rT   r   rž   ru   ra   rC   rC   rC   rD   r      s"   
 q	ý
-
!
.  ,r   )Ú__doc__rL   r¹   rO   Údistutils._logr   Útypingr   Úcorer   Údebugr   Úerrorsr   r   r	   r
   Ú	file_utilr   Ú	sysconfigr   r   rC   rC   rC   rD   Ú<module>   s    