Current File : //proc/self/root/kunden/lib/python3.9/site-packages/dnf-plugins/__pycache__/debug.cpython-39.pyc
a

�&c1�@s�ddlmZddlmZddlmZddlmZmZddlZddl	Zddl
Z
ddlZddlZddl
Z
ddlZddlZdZGdd�dej�ZGd	d
�d
ejj�ZGdd�dejj�Zd
d�Zdd�Zdd�ZdS)�)�absolute_import)�unicode_literals��ucd)�_�loggerNzdnf-debug-dump version 1
cs eZdZdZ�fdd�Z�ZS)�Debug�debugcsDtt|��||�||_||_|jdur@|j�t�|j�t�dS�N)�superr�__init__�base�cliZregister_command�DebugDumpCommand�DebugRestoreCommand)�selfr
r��	__class__��5/usr/lib/python3.9/site-packages/dnf-plugins/debug.pyr)s
zDebug.__init__)�__name__�
__module__�__qualname__�namer�
__classcell__rrrrr%srcsteZdZdZed�Z�fdd�Zdd�Zedd��Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Z�ZS)r)z
debug-dumpz5dump information about installed rpm packages to filecstt|��|�d|_dSr
)rrr�	dump_file)rrrrrr7szDebugDumpCommand.__init__cCsd|jj_d|jj_dS�NT)r�demands�sack_activation�available_repos�rrrr�	configure;s
zDebugDumpCommand.configurecCs.|jdddtd�d�|jddtd�d	�dS)
Nz	--norepos�
store_trueFz/do not attempt to dump the repository contents.)�action�default�help�filename�?zoptional name of dump file��nargsr%��add_argumentr��parserrrr�
set_argparser?s��zDebugDumpCommand.set_argparsercCs�|jj}|s6t�dt�t����}dt��d|f}tj�|�}|�	d�r\t
�|d�|_nt
|d�|_|�t�|��|��|��|�|jj�|��|j��ttd�|�dS)z{create debug txt file and compress it, if no filename specified
           use dnf_debug_dump-<timestamp>.txt.gz by defaultz%Y-%m-%d_%Tzdnf_debug_dump-%s-%s.txt.gz��.gz�wzOutput written to: %sN)�optsr&�time�strftime�	localtime�os�uname�path�abspath�endswith�gzip�GzipFiler�open�write�
DEBUG_VERSION�dump_system_info�dump_dnf_config_info�dump_rpm_problems�
dump_packagesZnorepos�dump_rpmdb_versions�close�printr)rr&Znowrrr�runHs 


zDebugDumpCommand.runcCs4tjjr t|jtj�r t|d�}tj�|j|�dS)N�utf8)	�dnfZpycompZPY3�
isinstancerr;r<�bytesZ
write_to_file)r�msgrrrr>as
zDebugDumpCommand.writecCsX|�d�t��}|�d|d|df�|�dtj�|�dtj�dd��dS)	Nz%%%%SYSTEM INFO
z  uname: %s, %s
��z  rpm ver: %s
z  python ver: %s
�
�)r>r6r7�rpm�__version__�sys�version�replace)rr7rrrr@fs
z!DebugDumpCommand.dump_system_infocCs�|jjj}d�dd�|jjjD��}|�d�|�d|d�|�d|d�|�d	|d
�|�dtjj	�|�d|�|�d
d�|jjj
��dS)N�,cSsg|]
}|j�qSr)r)�.0�prrr�
<listcomp>p�z9DebugDumpCommand.dump_dnf_config_info.<locals>.<listcomp>z
%%%%DNF INFO
z  arch: %s
�archz  basearch: %s
Zbasearchz  releasever: %s
Z
releaseverz  dnf ver: %s
z  enabled plugins: %s
z  global excludes: %s
)r
�confZ
substitutions�joinZ_plugins�pluginsr>rI�constZVERSION�excludepkgs)r�varr^rrrrAns

z%DebugDumpCommand.dump_dnf_config_infocCsP|�d�t|j�\}}|�d�dd�|D���|�d�dd�|D���dS)Nz%%%%RPMDB PROBLEMS
rPcSs$g|]\}}dt|�t|�f�qS)zPackage %s requires %s
r�rW�req�pkgrrrrY}s�z6DebugDumpCommand.dump_rpm_problems.<locals>.<listcomp>cSs$g|]\}}dt|�t|�f�qS)zPackage %s conflicts with %s
r�rWr\rdrrrrYs��)r>�rpm_problemsr
r])r�missing�	conflictsrrrrBzs
�
�z"DebugDumpCommand.dump_rpm_problemsc	Cs\|jj��}|�d�t|���D]}|�dt|��q"|sBdS|�d�|��}t|jj�	�dd�d�D]�}z�d}|j
dur�|j
}n*|jdur�|j}nt|j
�dkr�|j
d}|�d|j|f�|�d	d
�|j��t|j|jd��D]}|�dt|��q�Wqltjj�yT}z.|�d|t|�f�WYd}~qlWYd}~qld}~00qldS)
N�
%%%%RPMDB
z  %s
z
%%%%REPOS
cSs|jSr
)�id)�xrrr�<lambda>�rZz0DebugDumpCommand.dump_packages.<locals>.<lambda>)�keyrz
%%%s - %s
z  excludes: %s
rV)ZreponamezError accessing repo %s: %s
)r
�sack�queryr>�sorted�	installed�pkgspec�	availableZreposZiter_enabledZmetalinkZ
mirrorlist�lenZbaseurlrjr]r`�filterrI�
exceptions�Error�str)	rZ
load_repos�qrXrsZrepo�urlZpo�errrrC�s2




$zDebugDumpCommand.dump_packagescCs(|�d�|jj��}|�d|�dS)Nz%%%%RPMDB VERSIONS
z
  all: %s
)r>r
Z_tsZdbCookie)rrTrrrrD�s
z$DebugDumpCommand.dump_rpmdb_versions)rrr�aliasesr�summaryrr!�staticmethodr.rGr>r@rArBrCrDrrrrrr2s
	rc@sPeZdZdZed�Zdd�Zedd��Zdd�Z	d	d
�Z
dd�Zed
d��ZdS)r)z
debug-restorez,restore packages recorded in debug-dump filecCs4d|jj_d|jj_d|jj_|jjs0d|jj_dSr)rrrrZ	root_userr2�outputZ	resolvingr rrrr!�s



zDebugRestoreCommand.configurecCs~|jddtd�d�|jddtd�d�|jddtd�d�|jd	d
dtd�d
�|jddtd�d�|jddtd�d�dS)Nz--outputr"z,output commands that would be run to stdout.)r#r%z--install-latestz0Install the latest version of recorded packages.z
--ignore-archz_Ignore architecture and install missing packages matching the name, epoch, version and release.z--filter-typesz[install, remove, replace]zinstall, remove, replacezlimit to specified type)�metavarr$r%z--remove-installonlyzqAllow removing of install-only packages. Using this option may result in an attempt to remove the running kernel.r&r/zname of dump filer(r*r,rrrr.�s0�����
�z!DebugRestoreCommand.set_argparsercCsV|jjr$t|jj�dd����|j_|�|jjd�}|�||j�|�||j�dS)z Execute the command action here.rV� rN)	r2�filter_types�setrU�split�read_dump_filer&�process_installed�process_dump)r�	dump_pkgsrrrrG�s�zDebugRestoreCommand.runcCs�|jj����}|j�|�}|D]�}d}t|�}|�|j|jfd�}|dur�|j	|j
|jf}	|	|vrnd||	<q�||vr|d}q�d|jvr�d}
nd}
|�
�D]}|
||<q�nd}|r d|jvr ||vs�|jr |jr�td|�q |j�|�q dS)NF�skipTrU�removezremove    %s)r
rnrorqZ_get_installonly_queryrr�getrr[�epochrT�releaser��keysZremove_installonlyrrFZpackage_remove)rr�r2rqZinstallonly_pkgsrdZ
pkg_remove�spec�dumped_versionsZevrr#Zd_evrrrrr��s.

z%DebugRestoreCommand.process_installedc
Cs�t|���D]�\}}|||f}t|���D]�\}}}||||f}	|	dkrNq,|jrZd}
nd|}
|jr~|	dkr~d||
f}nt||
|||�}|	|jvr,|jr�td|	|f�q,z|j�	|�Wq,t
jjy�t
�td�|�Yq,0q,qdS)Nr�rP�.�installz%s%sz%s   %szPackage %s is not available)rpr�Zignore_archZinstall_latest�pkgtup2specr�rrFr
r�rIrvZMarkingErrorr�errorr)rr�r2�n�ar�r{�v�rr#r[�pkg_specrrrr��s&
z DebugRestoreCommand.process_dumpcCs�|�d�rt�|�}nt|�}t|���tkrFt�t	d�|�t
jj�d}i}|D]h}t|�}|rp|dkrRd}qR|r�|ddkr�q�|�
�}t�|�}d|�|j|jfi�|j|j|jf<qR|S)	Nr0zBad dnf debug file: %sTriFrr�r�)r:r;r<r=r�readliner?rr�rrIrvrw�strip�hawkeyZsplit_nevra�
setdefaultrr[r�rTr�)r&Zfobjr�Zpkgs�liner�Znevrarrrr�s.

��z"DebugRestoreCommand.read_dump_fileN)
rrrr|rr}r!r~r.rGr�r�r�rrrrr�s
#rcs�tj�|�}|�����t�}t�}�D]8�|��fdd��jD��|��fdd��jD��q(�fdd�|D�}�fdd�|D�}||fS)Ncs.g|]&}t|�dkst|��d�s|�f�qS)zsolvable:prereqmarkerzrpmlib()rx�
startswith)rWrc�rdrrrY:s�z rpm_problems.<locals>.<listcomp>csg|]}|�f�qSrr)rWr\r�rrrY=rZcs$g|]\}}�j|d�s||f�qS�)Zprovides�rurb��allpkgsrrrY?s�cs$g|]\}}�j|d�r||f�qSr�r�rer�rrrYAs�)	rIrnZ_rpmdb_sackrorqr��update�requiresrh)r
Zrpmdbr�rhZmissing_requiresZexisting_conflictsr)r�rdrrf3srfcCst|j|j|j|j|j�Sr
)r�rr[r�rTr�r�rrrrrFsrrcCs<|sdnd|�d�}|dvr"dnd|}d|||||fS)NrPz.%sr�)NrPz%s:z%s-%s%s-%s%s)�lstrip)rr[r�rTr�r�r{rrrr�Jsr�)Z
__future__rrZdnf.i18nrZdnfpluginscorerrrIZdnf.clir;r�r6rQrSr3r?ZPluginrrZCommandrrrfrrr�rrrr�<module>s&
w