a º&c1ã@sÎddlmZddlmZddlmZddlmZmZddlZddl Zddl Z ddl Z ddl Z ddl Z ddlZddlZdZGdd„dejƒZGd d „d ejjƒZGd d „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 d d „Z d d„Z dd„Z dd„Zdd„Zdd„Z‡ZS)r)z debug-dumpz5dump information about installed rpm packages to filecstt|ƒ |¡d|_dSr )r rr Ú 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-.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 ¡| d tjj ¡| d |¡| d d |jjj ¡¡dS)Nú,cSsg|] }|j‘qSr)r)Ú.0ÚprrrÚ pó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Ú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..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„dD]ê}z˜d}|j durˆ|j }n*|j durš|j }nt |j ƒdkr²|j d}| d|j|f¡| d d  |j¡¡t|j|jd ƒD]}| dt|ƒ¡qîWqltjjyT}z.| d |t|ƒf¡WYd}~qlWYd}~qld}~00qldS) Nú %%%%RPMDB z %s z %%%%REPOS cSs|jSr )Úid)ÚxrrrÚrZz0DebugDumpCommand.dump_packages..)Ú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 d d „Z ed 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 d td ƒd |jddtdƒd|jddtdƒddS)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 |j f} | |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 j j yæt  tdƒ| ¡Yq,0q,q dS)Nr‰rPÚ.Úinstallz%s%sz%s %szPackage %s is not available)rprŽZ ignore_archZinstall_latestÚ pkgtup2specr‚rrFr r’rIrvZ MarkingErrorrÚerrorr) rrˆr2ÚnÚarr{ÚvÚrr#r[Úpkg_specrrrr‡ûs&  z DebugRestoreCommand.process_dumpcCsÀ| d¡rt |¡}nt|ƒ}t| ¡ƒtkrFt t dƒ|¡t j j ‚d}i}|D]h}t|ƒ}|rp|dkrRd}qR|r€|ddkr„q¼|  ¡}t |¡}d| |j|jfi¡|j|j|jf<qR|S) Nr0zBad dnf debug file: %sTriFrrr’)r:r;r<r=rÚreadliner?rr”rrIrvrwÚstripÚhawkeyZ split_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..csg|] }|ˆf‘qSrr)rWr\r rrrY=rZcs$g|]\}}ˆj|ds||f‘qS©)Zprovides©rurb©ÚallpkgsrrrY?s  ÿcs$g|]\}}ˆj|dr||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ŒrTrr rrrrrFsrrcCs<|sdn d| d¡}|dvr"dnd|}d|||||fS)NrPz.%sr‘)NrPz%s:z %s-%s%s-%s%s)Úlstrip)rr[rŒrTrr–r{rrrr“Jsr“)Z __future__rrZdnf.i18nrZdnfpluginscorerrrIZdnf.clir;rœr6rQrSr3r?ZPluginrrZCommandrrrfrrr“rrrrÚs&    w