3 gt`1@sddlmZddlmZddlmZddlmZmZddlZddl Zddl Z ddl Z ddl Z ddl Z ddlZddlZdZGdddejZGd d d ejjZGd d d ejjZd dZddZddZdS))absolute_import)unicode_literals)ucd)_loggerNzdnf-debug-dump version 1 cs eZdZdZfddZZS)DebugdebugcsDtt|j||||_||_|jdk r@|jjt|jjtdS)N)superr__init__basecliZregister_commandDebugDumpCommandDebugRestoreCommand)selfr r ) __class__/usr/lib/python3.6/debug.pyr )s   zDebug.__init__)__name__ __module__ __qualname__namer __classcell__rr)rrr%srcsteZdZdZedZfddZddZeddZ d d Z d d Z d dZ ddZ ddZddZddZZS)r debug-dumpz5dump information about installed rpm packages to filecstt|j|d|_dS)N)r r r dump_file)rr )rrrr 7szDebugDumpCommand.__init__cCsd|jj_d|jj_dS)NT)r demandssack_activationavailable_repos)rrrr configure;s zDebugDumpCommand.configurecCs.|jdddtdd|jddtdd dS) Nz --norepos store_trueFz/do not attempt to dump the repository contents.)actiondefaulthelpfilename?zoptional name of dump file)nargsr!) add_argumentr)parserrrr set_argparser?s  zDebugDumpCommand.set_argparsercCs|jj}|s6tjdtjtj}dtjd|f}tjj|}|j dr\t j |d|_ n t |d|_ |jt|j|j|j|j|jj |j|j jttd|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.gzz.gzwzOutput written to: %sN)optsr"timeZstrftimeZ localtimeosunamepathabspathendswithgzipGzipFileropenwrite DEBUG_VERSIONdump_system_infodump_dnf_config_infodump_rpm_problems dump_packagesZnoreposdump_rpmdb_versionscloseprintr)rr"ZnowrrrrunHs      zDebugDumpCommand.runcCs4tjjr t|jtjr t|d}tjj|j|dS)Nutf8) dnfZpycompZPY3 isinstancerr1r2bytesZ write_to_file)rmsgrrrr4as zDebugDumpCommand.writecCsX|jdtj}|jd|d|df|jdtj|jdtjjdddS) Nz%%%%SYSTEM INFO z uname: %s, %s z rpm ver: %s z python ver: %s  )r4r,r-rpm __version__sysversionreplace)rr-rrrr6fs  z!DebugDumpCommand.dump_system_infocCs|jjj}djdd|jjjD}|jd|jd|d|jd|d|jd |d |jd tjj |jd ||jd dj|jjj dS)N,cSsg|] }|jqSr)r).0prrr psz9DebugDumpCommand.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 substitutionsjoinZ_pluginspluginsr4r?constVERSION excludepkgs)rvarrSrrrr7ns  z%DebugDumpCommand.dump_dnf_config_infocCsP|jdt|j\}}|jdjdd|D|jdjdd|DdS)Nz%%%%RPMDB PROBLEMS rFcSs$g|]\}}dt|t|fqS)zPackage %s requires %s )r)rMreqpkgrrrrO}sz6DebugDumpCommand.dump_rpm_problems..cSs$g|]\}}dt|t|fqS)zPackage %s conflicts with %s )r)rMrQrYrrrrOs)r4 rpm_problemsr rR)rZmissing conflictsrrrr8zs   z"DebugDumpCommand.dump_rpm_problemsc Cs\|jjj}|jdx&t|jD]}|jdt|q$W|sFdS|jd|j}xt|jjj dddD]}yd}|j dk r|j }n*|j dk r|j }nt |j dkr|j d}|jd|j|f|jd d j|jx,t|j|jd D]}|jdt|qWWqrtjjk rR}z|jd |t|fwrWYdd}~XqrXqrWdS) Nz %%%%RPMDB z %s z %%%%REPOS cSs|jS)N)id)xrrrsz0DebugDumpCommand.dump_packages..)keyrz %%%s - %s z excludes: %s rL)ZreponamezError accessing repo %s: %s )r sackqueryr4sorted installedpkgspec availableZreposZ iter_enabledZmetalinkZ mirrorlistlenZbaseurlr\rRrVfilterr? exceptionsErrorstr) rZ load_reposqrNreZrepoZurlZpoerrrr9s2      zDebugDumpCommand.dump_packagescCs(|jd|jjj}|jd|dS)Nz%%%%RPMDB VERSIONS z all: %s )r4r r`Z_rpmdb_version)rrJrrrr:s  z$DebugDumpCommand.dump_rpmdb_versions)r)rrraliasesrsummaryr r staticmethodr'r=r4r6r7r8r9r:rrr)rrr 2s    r c@sPeZdZdZedZddZeddZddZ d d Z d d Z ed dZ dS)r debug-restorez,restore packages recorded in debug-dump filecCs4d|jj_d|jj_d|jj_|jjs0d|jj_dS)NT)r rrrZ root_userr*outputZ resolving)rrrrrs    zDebugRestoreCommand.configurecCs~|jddtdd|jddtdd|jddtdd|jd d d td d |jddtdd|jddtdddS)Nz--outputrz,output commands that would be run to stdout.)rr!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&rrrr's$     z!DebugRestoreCommand.set_argparsercCsV|jjr$t|jjjddj|j_|j|jjd}|j||j|j||jdS)z Execute the command action here.rL rN) r* filter_typessetrKsplitread_dump_filer"process_installed process_dump)r dump_pkgsrrrr=s zDebugRestoreCommand.runc Cs|jjjj}|jj|}x|D]}d}t|}|j|j|jfd}|dk r|j |j |j f} | |krpd|| <q||kr~d}qd|j krd} nd} x|j D] } | || <qWnd}|r"d|j kr"||ks|jr"|jrtd|q"|jj|q"WdS)NFskipTrKremovez remove %s)r r`rarcZ_get_installonly_queryrdgetrrPepochrJreleasertkeysZremove_installonlyrqr<Zpackage_remove) rrzr*rcZinstallonly_pkgsrYZ pkg_removespecdumped_versionsZevrrZd_evrrrrrxs.    z%DebugRestoreCommand.process_installedc Csxt|jD]\}}|||f}xt|jD]\}}}||||f} | dkrRq0|jr^d} nd|} |jr| dkrd|| f} nt|| |||} | |jkr0|jrtd| | fq0y|jj | Wq0t j j k rt jtd| Yq0Xq0WqWdS)Nr{rF.installz%s%sz%s %szPackage %s is not available)rbrZ ignore_archZinstall_latest pkgtup2specrtrqr<r rr?rhZ MarkingErrorrerrorr) rrzr*narrlvrrrPpkg_specrrrrys&  z DebugRestoreCommand.process_dumpcCs|jdrtj|}nt|}t|jtkrFtjt d|t j j d}i}xp|D]h}t|}|rr|dkrTd}qT| s|ddkrP|j }tj|}d|j|j|jfi|j|j|jf<qTW|S) Nz.gzzBad dnf debug file: %sTz %%%%RPMDB Frrsr)r0r1r2r3rreadliner5rrrr?rhristriphawkeyZ split_nevra setdefaultrrPr~rJr)r"Zfobjr{ZpkgslinerZnevrarrrrws(    (z"DebugRestoreCommand.read_dump_fileN)rp) rrrrmrrnrror'r=rxryrwrrrrrs  #rcstjj|}|jjt}t}x@D]8|jfddjD|jfddjDq*Wfdd|D}fdd|D}||fS)Ncs2g|]*}t|dk rt|jd r|fqS)zsolvable:prereqmarkerzrpmlib()rj startswith)rMrX)rYrrrO:sz rpm_problems..csg|] }|fqSrr)rMrQ)rYrrrO=scs$g|]\}}j|ds||fqS))provides)rg)rMrXrY)allpkgsrrrO?scs$g|]\}}j|dr||fqS))r)rg)rMrQrY)rrrrOAs) r?r`Z _rpmdb_sackrarcruupdaterequiresr[)r Zrpmdbrr[Zmissing_requiresZexisting_conflictsr)rrYrrZ3s   rZcCst|j|j|j|j|jS)N)rrrPr~rJr)rYrrrrdFsrdcCs<|sdn d|jd}|dkr"dnd|}d|||||fS)NrFz.%srz%s:z %s-%s%s-%s%s)NrF)lstrip)rrPr~rJrrrlrrrrJsr)Z __future__rrZdnf.i18nrZdnfpluginscorerrr?Zdnf.clir1rr,rGrIr+r5ZPluginrr ZCommandr rrZrdrrrrrs&    w