3
šgt`1 ã @ sÎ d dl mZ d dl mZ d dlmZ d dlmZmZ d dlZd dl Zd dl
Z
d dlZd dlZd dl
Z
d dlZd dlZdZG dd„ dejƒZG d d
„ d
ejjƒZG dd„ dejjƒZd
d„ Zdd„ Zdd„ ZdS )é )Úabsolute_import)Úunicode_literals)Úucd)Ú_ÚloggerNzdnf-debug-dump version 1
c s e Zd ZdZ‡ fdd„Z‡ ZS )ÚDebugÚdebugc sD t t| ƒj||ƒ || _|| _| jd k r@| jjtƒ | jjtƒ d S )N)Úsuperr Ú__init__ÚbaseÚcliZregister_commandÚDebugDumpCommandÚDebugRestoreCommand)Úselfr r )Ú __class__© ú/usr/lib/python3.6/debug.pyr
) s
zDebug.__init__)Ú__name__Ú
__module__Ú__qualname__Únamer
Ú
__classcell__r r )r r r % s r c st e Zd ZdZedƒZ‡ fdd„Zdd„ Zedd„ ƒZ d d
„ Z
dd„ Zd
d„ Zdd„ Z
dd„ Zdd„ Zdd„ Z‡ ZS )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 zDebugDumpCommand.__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
zDebugDumpCommand.configurec C s. | j dddtdƒd� | j ddtdƒd � d S )
Nz --noreposÚ
store_trueFz/do not attempt to dump the repository contents.)ÚactionÚdefaultÚhelpÚfilenameú?zoptional name of dump file)Únargsr! )Úadd_argumentr )Úparserr r r Ú
set_argparser? s zDebugDumpCommand.set_argparserc C sÀ | j j}|s6tjdtjtjƒ ƒƒ}dtjƒ d |f }tjj|ƒ}|j dƒr\t
j|dƒ| _nt
|dƒ| _| jtƒ | jƒ | jƒ | jƒ | j| j j ƒ | jƒ | jjƒ ttdƒ| ƒ dS )z{create debug txt file and compress it, if no filename specified
use dnf_debug_dump-.txt.gz by defaultz%Y-%m-%d_%Tzdnf_debug_dump-%s-%s.txt.gzé z.gzÚwzOutput written to: %sN)Úoptsr" ÚtimeZstrftimeZ 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 )r r" Znowr r r ÚrunH s
zDebugDumpCommand.runc C s4 t jjr t| jtjƒr t|dƒ}t jj| j|ƒ d S )NÚutf8) ÚdnfZpycompZPY3Ú
isinstancer r1 r2 ÚbytesZ
write_to_file)r Úmsgr r r r4 a s
zDebugDumpCommand.writec C sX | j dƒ tjƒ }| j d|d |d f ƒ | j dtj ƒ | j dtjjddƒ ƒ 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 jj}djdd„ | j jjD ƒƒ}| jdƒ | jd|d ƒ | jd|d ƒ | jd |d
ƒ | jdtjj ƒ | jd| ƒ | jd
dj| j jj
ƒ ƒ d S )Nú,c S s g | ]
}|j ‘qS r )r )Ú.0Úpr r r ú
p s z9DebugDumpCommand.dump_dnf_config_info..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Ú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 djdd„ |D ƒƒƒ | j djdd„ |D ƒƒƒ d S )Nz%%%%RPMDB PROBLEMS
rF c S s$ g | ]\}}d t |ƒt |ƒf ‘qS )zPackage %s requires %s
)r )rM ÚreqÚpkgr r r rO } s z6DebugDumpCommand.dump_rpm_problems..c S s$ g | ]\}}d t |ƒt |ƒf ‘qS )zPackage %s conflicts with %s
)r )rM rQ rY r r r rO s )r4 Úrpm_problemsr rR )r ZmissingÚ conflictsr r r r8 z s
z"DebugDumpCommand.dump_rpm_problemsc C s\ | j jjƒ }| jdƒ x&t|jƒ ƒD ]}| jdt|ƒ ƒ q$W |sFd S | jdƒ |jƒ }xþt| j jj ƒ dd„ d�D ]â}yœd }|j
d k rŽ|j
}n*|jd k r |j}nt|j
ƒdkr¸|j
d }| jd|j|f ƒ | jd d
j|jƒ ƒ x,t|j|jd�ƒD ]}| jdt|ƒ ƒ qöW W qr tjjk
�rR } z| jd|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 Ú� s z0DebugDumpCommand.dump_packages..)Úkeyr z
%%%s - %s
z excludes: %s
rL )ZreponamezError accessing repo %s: %s
)r ÚsackÚqueryr4 ÚsortedÚ installedÚpkgspecÚ availableZreposZiter_enabledZmetalinkZ
mirrorlistÚlenZbaseurlr\ rR rV Úfilterr? Ú
exceptionsÚErrorÚstr) r Z
load_reposÚqrN re ZrepoZurlZpoÚer r r r9 ƒ s2
zDebugDumpCommand.dump_packagesc C s( | j dƒ | jjjƒ }| 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 Zd ZdZedƒZdd„ Zedd„ ƒZdd„ Z d d
„ Z
dd„ Zed
d„ ƒZdS )r ú
debug-restorez,restore packages recorded in debug-dump filec C s4 d| j j_d| j j_d| j j_| jjs0d| j j_d S )NT)r r r r Z root_userr* ÚoutputZ resolving)r r r r r ® s
zDebugRestoreCommand.configurec C s~ | j ddtdƒd� | j ddtdƒd� | j ddtdƒd� | j d d
dtdƒd
� | j ddtdƒd� | j ddtdƒ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]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 file)r$ r! )r% r )r&