<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
gt`1                 @   s   d dl mZ d dl mZ d dlmZ d dlmZmZ d dlZd dl	Zd dl
Z
d dlZd dlZd dlZd dlZd dlZdZG dd dejZG d	d
 d
ejjZG dd dejjZdd Zdd Zdd ZdS )    )absolute_import)unicode_literals)ucd)_loggerNzdnf-debug-dump version 1
c                   s    e Zd ZdZ fddZ  ZS )Debugdebugc                sD   t t| j|| || _|| _| jd k	r@| jjt | jjt d S )N)superr   __init__basecliZregister_commandDebugDumpCommandDebugRestoreCommand)selfr   r   )	__class__ /usr/lib/python3.6/debug.pyr
   )   s    
zDebug.__init__)__name__
__module____qualname__namer
   __classcell__r   r   )r   r   r   %   s   r   c                   st   e Zd ZdZedZ fddZdd Zedd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )r   
debug-dumpz5dump information about installed rpm packages to filec                s   t t| j| d | _d S )N)r	   r   r
   	dump_file)r   r   )r   r   r   r
   7   s    zDebugDumpCommand.__init__c             C   s   d| j j_d| j j_d S )NT)r   demandssack_activationavailable_repos)r   r   r   r   	configure;   s    
zDebugDumpCommand.configurec             C   s.   | j dddtdd | j ddtdd	 d S )
Nz	--norepos
store_trueFz/do not attempt to dump the repository contents.)actiondefaulthelpfilename?zoptional name of dump file)nargsr!   )add_argumentr   )parserr   r   r   set_argparser?   s    zDebugDumpCommand.set_argparserc             C   s   | j j}|s6tjdtjtj }dtj d |f }tjj|}|j	dr\t
j|d| _nt|d| _| jt | j  | j  | j  | j| j j  | j  | jj  ttd|  dS )z{create debug txt file and compress it, if no filename specified
           use dnf_debug_dump-<timestamp>.txt.gz by defaultz%Y-%m-%d_%Tzdnf_debug_dump-%s-%s.txt.gz   z.gzwzOutput written to: %sN)optsr"   timeZstrftimeZ	localtimeosunamepathabspathendswithgzipGzipFiler   openwriteDEBUG_VERSIONdump_system_infodump_dnf_config_infodump_rpm_problemsdump_packagesZnoreposdump_rpmdb_versionscloseprintr   )r   r"   Znowr   r   r   runH   s     


zDebugDumpCommand.runc             C   s4   t jjr t| jtjr t|d}t jj| j| d S )Nutf8)	dnfZpycompZPY3
isinstancer   r1   r2   bytesZwrite_to_file)r   msgr   r   r   r4   a   s    
zDebugDumpCommand.writec             C   sX   | j d tj }| j d|d |d f  | j dtj  | j dtjjdd  d S )	Nz%%%%SYSTEM INFO
z  uname: %s, %s
      z  rpm ver: %s
z  python ver: %s

 )r4   r,   r-   rpm__version__sysversionreplace)r   r-   r   r   r   r6   f   s    
z!DebugDumpCommand.dump_system_infoc             C   s   | j jj}djdd | j jjD }| jd | jd|d   | jd|d   | jd	|d
   | jdtjj	  | jd|  | jddj| j jj
  d S )N,c             S   s   g | ]
}|j qS r   )r   ).0pr   r   r   
<listcomp>p   s    z9DebugDumpCommand.dump_dnf_config_info.<locals>.<listcomp>z%%%%DNF INFO
z  arch: %s
archz  basearch: %s
Zbasearchz  releasever: %s
Z
releaseverz  dnf ver: %s
z  enabled plugins: %s
z  global excludes: %s
)r   confZsubstitutionsjoinZ_pluginspluginsr4   r?   constVERSIONexcludepkgs)r   varrS   r   r   r   r7   n   s    

z%DebugDumpCommand.dump_dnf_config_infoc             C   sP   | j d t| j\}}| j djdd |D  | j djdd |D  d S )Nz%%%%RPMDB PROBLEMS
rF   c             S   s$   g | ]\}}d t |t |f qS )zPackage %s requires %s
)r   )rM   reqpkgr   r   r   rO   }   s   z6DebugDumpCommand.dump_rpm_problems.<locals>.<listcomp>c             S   s$   g | ]\}}d t |t |f qS )zPackage %s conflicts with %s
)r   )rM   rQ   rY   r   r   r   rO      s   )r4   rpm_problemsr   rR   )r   Zmissing	conflictsr   r   r   r8   z   s    
z"DebugDumpCommand.dump_rpm_problemsc       	      C   s\  | j jj }| jd x&t|j D ]}| jdt|  q$W |sFd S | jd |j }xt| j jj	 dd dD ]}yd }|j
d k	r|j
}n*|jd k	r|j}nt|jdkr|jd }| jd|j|f  | jd	d
j|j  x,t|j|jdD ]}| jdt|  qW W qr tjjk
rR } z| jd|t|f  wrW Y d d }~X qrX qrW d S )Nz
%%%%RPMDB
z  %s
z
%%%%REPOS
c             S   s   | j S )N)id)xr   r   r   <lambda>   s    z0DebugDumpCommand.dump_packages.<locals>.<lambda>)keyr   z
%%%s - %s
z  excludes: %s
rL   )ZreponamezError accessing repo %s: %s
)r   sackqueryr4   sorted	installedpkgspec	availableZreposZiter_enabledZmetalinkZ
mirrorlistlenZbaseurlr\   rR   rV   filterr?   
exceptionsErrorstr)	r   Z
load_reposqrN   re   ZrepoZurlZpoer   r   r   r9      s2    




zDebugDumpCommand.dump_packagesc             C   s(   | j d | jjj }| j d|  d S )Nz%%%%RPMDB VERSIONS
z
  all: %s
)r4   r   r`   Z_rpmdb_version)r   rJ   r   r   r   r:      s    
z$DebugDumpCommand.dump_rpmdb_versions)r   )r   r   r   aliasesr   summaryr
   r   staticmethodr'   r=   r4   r6   r7   r8   r9   r:   r   r   r   )r   r   r   2   s   		r   c               @   sP   e Zd ZdZedZdd Zedd Zdd Z	d	d
 Z
dd Zedd ZdS )r   debug-restorez,restore packages recorded in debug-dump filec             C   s4   d| j j_d| j j_d| j j_| jjs0d| j j_d S )NT)r   r   r   r   Z	root_userr*   outputZ	resolving)r   r   r   r   r      s
    


zDebugRestoreCommand.configurec             C   s~   | j ddtdd | j ddtdd | j ddtdd | j d	d
dtdd | j ddtdd | j ddtdd d S )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]zinstall, remove, replacezlimit 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(   zname of dump file)r$   r!   )r%   r   )r&   r   r   r   r'      s$    z!DebugRestoreCommand.set_argparserc             C   sV   | j jr$t| j jjddj | j _| j| j jd }| j|| j  | j|| j  dS )z Execute the command action here.rL    r   N)	r*   filter_typessetrK   splitread_dump_filer"   process_installedprocess_dump)r   	dump_pkgsr   r   r   r=      s    zDebugRestoreCommand.runc             C   s   | j jj j }| j j|}x|D ]}d}t|}|j|j|jfd }|d k	r|j	|j
|jf}	|	|krpd||	< q||kr~d}qd|jkrd}
nd}
x|j D ]}|
||< qW nd}|r"d|jkr"||ks|jr"|jrtd|  q"| j j| q"W d S )NFskipTrK   removezremove    %s)r   r`   ra   rc   Z_get_installonly_queryrd   getr   rP   epochrJ   releasert   keysZremove_installonlyrq   r<   Zpackage_remove)r   rz   r*   rc   Zinstallonly_pkgsrY   Z
pkg_removespecdumped_versionsZevrr   Zd_evrr   r   r   rx      s.    


z%DebugRestoreCommand.process_installedc             C   s   xt |j D ]\}}|||f }xt |j D ]\}}}||||f }	|	dkrRq0|jr^d}
nd| }
|jr|	dkrd||
f }nt||
|||}|	|jkr0|jrtd|	|f  q0y| jj	| W q0 t
jjk
r   tjtd| Y q0X q0W qW d S )Nr{   rF   .installz%s%sz%s   %szPackage %s is not available)rb   r   Zignore_archZinstall_latestpkgtup2specrt   rq   r<   r   r   r?   rh   ZMarkingErrorr   errorr   )r   rz   r*   nar   rl   vrr   rP   pkg_specr   r   r   ry      s&    
z DebugRestoreCommand.process_dumpc             C   s   | j drtj| }nt| }t|j tkrFtjt	d|  t
jjd}i }xp|D ]h}t|}|rr|dkrTd}qT| s|d dkrP |j }tj|}d|j|j|jfi |j|j|jf< qTW |S )	Nz.gzzBad dnf debug file: %sTz
%%%%RPMDB
Fr   rs   r   )r0   r1   r2   r3   r   readliner5   r   r   r   r?   rh   ri   striphawkeyZsplit_nevra
setdefaultr   rP   r~   rJ   r   )r"   Zfobjr{   Zpkgsliner   Znevrar   r   r   rw     s(    


(z"DebugRestoreCommand.read_dump_fileN)rp   )r   r   r   rm   r   rn   r   ro   r'   r=   rx   ry   rw   r   r   r   r   r      s   #r   c                s   t jj| }|j j  t }t }x@ D ]8|jfddjD  |jfddjD  q*W  fdd|D } fdd|D }||fS )Nc                s2   g | ]*}t |d k rt |jd r| fqS )zsolvable:prereqmarkerzrpmlib()rj   
startswith)rM   rX   )rY   r   r   rO   :  s    z rpm_problems.<locals>.<listcomp>c                s   g | ]}| fqS r   r   )rM   rQ   )rY   r   r   rO   =  s    c                s$   g | ]\}} j |d s||fqS ))provides)rg   )rM   rX   rY   )allpkgsr   r   rO   ?  s    c                s$   g | ]\}} j |d r||fqS ))r   )rg   )rM   rQ   rY   )r   r   r   rO   A  s    )	r?   r`   Z_rpmdb_sackra   rc   ru   updaterequiresr[   )r   Zrpmdbr   r[   Zmissing_requiresZexisting_conflictsr   )r   rY   r   rZ   3  s    
rZ   c             C   s   t | j| j| j| j| jS )N)r   r   rP   r~   rJ   r   )rY   r   r   r   rd   F  s    rd   c             C   s<   |sdnd|j d }|dkr"dnd| }d| ||||f S )NrF   z.%sr   z%s:z%s-%s%s-%s%s)NrF   )lstrip)r   rP   r~   rJ   r   r   rl   r   r   r   r   J  s    r   )Z
__future__r   r   Zdnf.i18nr   Zdnfpluginscorer   r   r?   Zdnf.clir1   r   r,   rG   rI   r+   r5   ZPluginr   r   ZCommandr   r   rZ   rd   r   r   r   r   r   <module>   s&   w 