3 f@sXdZddlmZddlmZddlmZddlmZddlZddlZddlZ ddl m Z ddl m Z dd lmZmZmZdd lmZdd lmZdd lmZydd lmZWn ek rdd lmZYnXddlZddlZddl ZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zddl%Zddl&Zddl'Zyddl(ZdZ)Wnek r`dZ)YnXddl*Zddl+Zddl,Zddl-Zddl.Zddl/Zddl0Zddl1Zddl2Zddl3Zddl4Zddl5ZddlZddl6Zddl7Z7ddl8Z8ddl9Z9ddl:Z:ddl;Z;ddlZ>ddl?Z?ddl@Z@ddlAZAddlBZBe;jCdZDGdddeEZFddZGdS)z Supplies the Base class. )absolute_import)division)print_function)unicode_literalsN)deepcopy) CompsQuery)_P_ucd) _parse_specs) SwdbInterface)misc)SequenceTFdnfc@seZdZdddZddZddZdd Zd d Zd d Ze ddZ ddZ dddZ ddZ eddZeddZeddZejddZeejjddd Zed!d"Zed#d$Zed%d&Zejd'd&Zd(d)Zffdfd*d+Zd,d-Zd.d/Zd0d1Zdd2d3Z dd5d6Z!dd7d8Z"d9d:Z#d;d<Z$dd=d>Z%dd?d@Z&dAdBZ'e(j)e(j*e(j+e(j,e(j-e(j.e(j/dCZ0e1e(dDre(j2e0dE<dFe(j3e(j4BiZ5edGdHZ6edIdJZ7e7jdKdJZ7ddLdMZ8dNdOZ9edPdQdRdQdSdQdTdUZ:dVdWZ;dXdYZd^d_Z?dd`daZ@ffdbdcZAdddeZBdfdgZCdhdiZDddjdkZEddldmZFddndoZGddpdqZHdrdsZIdtduZJdvdwZKddydzZLdd{d|ZMd}d~ZNddZOddZPddZQdddZRddZSdddZTdddZUddZVddZWddZXddZYddZZddZ[dddZ\ddZ]ddZ^ddZ_dddZ`dddZadddZbdddZcdddZdddZeddZfddZgdddZhdddZidddZjdddZkdddZldddZmdddZnddZoddd„ZpddĄZqffffffddƄZrddȄZsdddʄZtddd̄Zuddd΄ZvddЄZwdddӄZxdddՄZyddׄZzddلZ{ddۄZ|dd݄Z}dd߄Z~ddZddZdS( BaseNcCsd|_|p|j|_d|_d|_d|_d|_d|_d|_t j j |_ d|_ t|_t|_t jj|_t jj|_t jj|_ttjg|_t jj|_d|_ d|_!d|_"g|_#i|_$d|_%t|_&d|_'dS)NF)(_closed_setup_default_conf_conf_goal_repo_persistor_sack _transaction_priv_ts_compsrcompsTransactionBunch _comps_trans_historyset _tempfiles_trans_tempfilescallbackZDepsolve _ds_callbackloggingZLogging_loggingrepodictRepoDict_reposrpmZRPMPROB_FILTER_OLDPACKAGE_rpm_probfilterZpluginZPlugins_plugins_trans_success_trans_install_set_tempfile_persistor_update_security_filters_update_security_options_allow_erasing_repo_set_imported_gpg_keysoutput)selfconfr5/usr/lib/python3.6/base.py__init__]s2     z Base.__init__cCs|S)Nr5)r3r5r5r6 __enter__zszBase.__enter__cGs |jdS)N)close)r3Zexc_argsr5r5r6__exit__}sz Base.__exit__cCs |jdS)N)r9)r3r5r5r6__del__sz Base.__del__cCs.|jr|jj|n|jjrn |jj|dS)N)rr updater4destdirr)r3filesr5r5r6_add_tempfiless zBase._add_tempfilescCs|jtd|jdd}|jr&d|d<y|jj|jfddi|WnTtjk r}z6t j t dj |j |tjjt dj |j WYdd}~XnXdS)NT)load_filelists load_prestoload_updateinfo load_other build_cachezloading repo '{}' failure: {}z"Loading repository '{}' has failed)loaddictdeltarpmload_metadata_otherr load_repo_repohawkey Exceptionloggerdebugrformatidr exceptions RepoError)r3repo mdload_flagser5r5r6_add_repo_to_sackszBase._add_repo_to_sackcCs.tjj}|j}d|kr*tjj|j|d<|S)N releasever)rr4ZConf substitutionsr(Zdetect_releasever installroot)r4Zsubstr5r5r6rs  zBase._setup_default_confcCsdd|jjD}y0|jj|j||jj|jjd|jj|jj d}Wn4t j k rx}zt j jt|WYdd}~XnX|rtjt jjj|ddS)NcSsg|]}|jr|jqSr5)Zmodule_hotfixesrP).0ir5r5r6 sz0Base._setup_modular_excludes..F)Z update_onlyZ debugsolvermodule_obsoletesr)repos iter_enabledsackZfilter_modules_moduleContainerr4rYZmodule_platform_id debug_solverr]rKrLrrQErrorr rMwarningmodule module_baseZformat_modular_solver_errors)r3Z hot_fix_reposZ solver_errorsrUr5r5r6_setup_modular_excludess "zBase._setup_modular_excludesFc Cst|jj}d|kr$tr$|jdSg}g}|s>x|jjD]}|j|krPq@t|j dkr|j j j dd}x8t|j D]*}t jj|}|j|j|j dddd}q|W|j |jd|j|j|jf|j j j dd} x8t|jD]*} t jj| }| j|j|j dddd} qW| j |jd| r@|j| |jfq@Wd|kr6|j j j dd} t|jj dkrx.) rr4 cacheonlyr^r_Zexpired_to_addr<saver-)r3Zexpiredr5r5r6_store_persistent_datas  zBase._store_persistent_datacCs|jdkr|jdd|jS)NT) arch_filter)r read_comps)r3r5r5r6rs  z Base.compscCs|jS)N)r)r3r5r5r6r4sz Base.confcCs|jS)N)r')r3r5r5r6r^sz Base.reposcCs d|_dS)N)r')r3r5r5r6r^sZ _priv_rpmconncCstjjj|jjS)N)rr(Z connectionZ RpmConnectionr4rY)r3r5r5r6_rpmconn sz Base._rpmconncCs|jS)N)r)r3r5r5r6r`sz Base.sackcCsP|jdkrtjjd|jjdkrHtjjd|jj |jj d|jj |j_|jjS)NzSack was not initializedFarch) r`rrQrcralibdnfreZModulePackageContainerr4rYrX persistdir)r3r5r5r6ras     zBase._moduleContainercCs|jS)N)r)r3r5r5r6 transactionszBase.transactioncCs|jrtd||_dS)Nztransaction already set)r ValueError)r3valuer5r5r6r$scCstjj|jj|_dS)N)r persistorZ RepoPersistorr4cachedirr)r3r5r5r6_activate_persistor+szBase._activate_persistorcCs,|jjr|jj|j|||jj||dS)z&Load plugins and run their __init__().N)r4Zpluginsr*_loadZ _run_init)r3Z disabled_globZenable_pluginsclir5r5r6 init_plugins.szBase.init_pluginscCs|jjdS)z#Run plugins pre_configure() method.N)r*Z_run_pre_config)r3r5r5r6pre_configure_plugins5szBase.pre_configure_pluginscCs|jjdS)zRun plugins configure() method.N)r*Z _run_config)r3r5r5r6configure_plugins:szBase.configure_pluginscCs|jjdS)zRun plugins unload() method.N)r*Z_unload)r3r5r5r6unload_plugins?szBase.unload_pluginsc Cs|jj}|jdkr|j|j}|rtjjrDtd}tj |dStjj dkrhtd}tj |dS|dkrtd}tj |dS|j }|dk r||krtj tddSx|j j D]}|jjdqW|j jstj tdjd j|jjdSx|j jD]}|j\}} | dkr6tj td |jnx| sH| dkrftjtd |j|jjnH|r| |krtd }tj||j| |jjntjtd |j| qW|rd|_|jdddtj tddS)NzCMetadata timer caching disabled when running on metered connection.Fz:Metadata timer caching disabled when running on a battery.rz Metadata timer caching disabled.z"Metadata cache refreshed recently.z*There are no enabled repositories in "{}".z", "z4%s: will never be expired and will not be refreshed.z&%s: has expired and will be refreshed.zC%s: metadata will expire after %d seconds and will be refreshed nowz!%s: will expire after %d seconds.T)load_system_repoload_available_reposzMetadata cache created.)r4Zmetadata_timer_syncrrrutilZon_metered_connectionrrMinfoZ on_ac_powersince_last_makecacher^valuesrJZsetMaxMirrorTries _any_enabledrOjoinZreposdirr_Z_metadata_expire_inrPrNexpireZreset_last_makecache fill_sack) r3timerZperiodrmsgrrSr{Zis_cacheZ expires_inr5r5r6 update_cacheDsZ            zBase.update_cacheTc CsPtjjd}|jdddtjj||_tjj|j j |j j }||dk ry|jj ddWnt k r~|dkrzYnX|rg}d}tj}|j jrtjjjx|jjD]}y`|j||jj|kr|jj}|jj|kr|jj}tjtd|jtjj|jjWqtj j!k rz} z>|jj"|j#dkrJtj$d | |j%|j|j&WYd d } ~ XqXqW|rtj$td d j'||jj(r|dkr|dkrtj)td t*j+t,|dtjj|n|jj-j&Wd QRX|j } |jj.| j/| j0| j1|j2|tj3j4|j|_5| j6|j5_6|j7j8|jS)z'Prepare the Sack and the Goal objects. z sack setupT)r`goalF)rDautorz%s: using metadata from %s.z Error: %sNzIgnoring repositories: %sz, z-Last metadata expiration check: %s ago on %s.)Zseconds)9rr#Timerresetr` _build_sackrlockbuild_metadata_lockr4r exit_on_lockrIOErrortimegpgkey_dns_verificationdnssecRpmImportedKeyscheck_imported_keys_validityr^r_rVrJZ getTimestampZgetAgerMrNrrPrnormalize_timegetMaxTimestamprQrRrskip_if_unavailablerdrwdisablerrrdatetimeZ timedeltaintrh _configureinstallonlypkgsinstallonly_limitallow_vendor_changerrGoalrprotect_running_kernelr*run_sack) r3rrrr error_reposZmtsZager{rUr4r5r5r6r|sf             zBase.fill_sackc Cs tjjd}|jdddtjj||_tjj|j j |j j }|n|dk ry|jj ddWnt k r~|dkrzYnXg}|j jrtjjjx|jjD]}yf|jjdddtd|jdd}|jrd|d <|jj|jf|tjtd |jtjj|jj Wqt!t"j#fk r}zZ|j$dkrPtj%j&td j'|j|ntjtd j'|j||j(|j|j)WYd d }~XqXqW|rtj*td dj+|Wd QRX|j }|jj,|j-|j.|j/|j0|tj1j2|j|_3|j4|j3_4|j5j6|jS)a Prepare Sack and Goal objects and also load all enabled repositories from cache only, it doesn't download anything and it doesn't check if metadata are expired. If there is not enough metadata present (repond.xml or both primary.xml and solv file are missing) given repo is either skipped or it throws a RepoError exception depending on skip_if_unavailable configuration. z sack setupT)r`rF)rDr)Z throwExceptZ ignoreMissing)r@rArBrCz%s: using metadata from %s.zloading repo '{}' failure: {}NzIgnoring repositories: %sz, )7rr#rrr`rrrrr4rrrrrrrrr^r_rJZ loadCacherFrGrHrIrMrNrrPrrr RuntimeErrorrKrLrrQrRrOrwrrdrrrrrrrrrrr*r) r3rrrrrSrTrUr4r5r5r6fill_sack_from_repos_in_cachesX      z"Base.fill_sack_from_repos_in_cachecCstjj|jj|_|jjsl|j|j|j r\|j j |jj |jj |jrl|j|j n|jjj |j |jjrtjtdtjtddjtjjd|jdk r|jj|j|jd|_ dS)NzRThe downloaded packages were saved in cache until the next successful transaction.z1You can remove cached packages by executing '%s'.z{prog} clean packages)progF)rrZTempfilePersistorr4rr-Z keepcache_clean_packagesrr+r r<Zget_saved_tempfilesrir,Ztempfiles_to_addrMrrrOrZ MAIN_PROGrhistoryr9r _closeRpmDB)r3r5r5r6_finalize_bases*       zBase._finalize_basecCsB|jr dStjtjjdd|_|j|jddddd|_dS)ztClose all potential handles and clean cache. Typically the handles are to data sources and sinks. Nz Cleaning up.T)r`r^r) rrMlogrr#DDEBUGrrr*)r3r5r5r6r9sz Base.closecCsftjjj|j|}xN|D]F}y|jj|Wqtjjk r\}ztj |WYdd}~XqXqWdS)z?Read repositories from the main conf file and from .repo files.N) rr4readZ RepoReaderr^addrQZ ConfigErrorrMrd)r3ZoptsreaderrSrUr5r5r6read_all_repos"s  zBase.read_all_reposcCs|r d|_|rtjj|_|rd|_|jdk rJtjj|j|_|jj |j_ |jr`|j r`|j j |j dk rt|j jtjj|_d|_g|_|r|rtjdS)z1Make the Base object forget about various things.N)rrr%r&r'rrrr4rraZrollbackrrr9rrrrr.gcZcollect)r3r`r^rr5r5r6r-s$        'z Base.resetcCs|`dS)z6Closes down the instances of rpmdb that could be open.N)_ts)r3r5r5r6rjszBase._closeRpmDB)Z noscriptsZ notriggersZnodocstestZjustdbZ nocontextsnocryptoRPMTRANS_FLAG_NOCAPSZnocapsrcCs|jS)N)r)r3r5r5r6r|sz Base.goalcCs|jdk r|jStjjj|jj|_|jjdxb|jjD]V}|j j |}|dkrdt j t d|q:|jj||jj |}|dk r:|jj|q:W|jjs|jjtj|jjr|jjtjtjtj|jd}|jj||jS)zMSet up the RPM transaction set that will be used for all the work.Nrz!Invalid tsflag in config file: %s)rrr(rZTransactionWrapperr4rYsetFlagsZtsflags_TS_FLAGS_TO_RPMgetrMcriticalrZ addTsFlag_TS_VSFLAGS_TO_RPM pushVSFlagsZdiskspacecheckr)rZRPMPROB_FILTER_DISKSPACEZ ignorearchZRPMPROB_FILTER_IGNOREARCH functoolsreduceoperatoror_Z setProbFilter)r3flagZrpm_flagZvs_flagZ probfilterr5r5r6rs*       zBase._tscCs&|jdkrdS|jj|`d|_dS)z"Releases the RPM transaction set. N)rr9)r3r5r5r6rs   cCs$tjjd}tjj|_tjtjjdx|j j D]}|j s@q4|j sHq4|j j}|sXq4tjtjjd|j|j jtjjkrtj|d}tjj|sq4n tj|d}y|jj|Wq4tjjk r}ztd}tj||j|WYdd}~Xq4Xq4W|r|jjj|j j!dg||jS)z6Create the groups object to access the comps metadata.z loading compszGetting group metadataz%Adding group file from repository: %sz groups.xmlz1Failed to add groups file for repository: %s - %sNbasearch)"rr#rrZCompsrrMrrr^r_Z enablegroupsrrJZ getCompsFnrPZgetSyncStrategyrSZSYNC_ONLY_CACHEr Zcalculate_repo_gen_destospathexistsZrepo_gen_decompressZ_add_from_xml_filenamerQ CompsErrorrrZ_irrrX)r3rrrSZcomps_fnZ decompressedrUrr5r5r6rs:       &zBase.read_compscCs*|jdkr$|jj}t|jj|d|_|jS)zeauto create the history object that to access/append the transaction history information. N)rW)rr4rWr r)r3rWr5r5r6 _getHistorys zBase._getHistorycCs|jS)N)r)r3r5r5r6sz Base.cCs t|d|S)Nr)setattr)r3rr5r5r6rscCs t|ddS)Nr)r)r3r5r5r6rszDNF SWDB Interface Object)fgetfsetfdeldoccsFjj}t|jj}|j|jj}xT|jD]H|j}|d}j j |dj j d|j ||ddq:Wx|j D]xj j d|j}t }g}x0|D](} t | |kr|jd| q|j| qW|d} |j| |ddqWx|jD]j j d|j}fdd|D}|j} |krt|jjd rt|j} x0|D](} |j| } tjj| | dkrz| } qzW|j|| fd d }tjj||qWx|jD]ȉ|j}d}x"|D]}|jjkr|}PqW|dkr*|jd}n |j|fd d|D}fd d }tjj|||krz|j|n|j||j j |dj j dqW|j }|rBj!j"t#j$dj}|j%|dxh|D]`|jjd r|d}|j|jj&||j|j j d|j} |j'| qW|S)NrZdddrr{r[cs$g|]}|ks|jjkr|qSr5)name)rZr[) all_obsoletedpkgr5r6r\sz*Base._goal2transaction..)rcsjj|dS)Nod)r" pkg_added)r)r3r5r6r sz(Base._goal2transaction..cs$g|]}|ks|jjkr|qSr5)r)rZr[)rrr5r6r\scsjj|dS)Nr)r"r)r)r3r5r6r!sZudu)flags)Zpkg__neqrU)(rr(rZlist_obsoleted_get_installonly_queryrx installedlist_downgradesZobsoleted_by_packager"rZ add_downgradelist_reinstallsstrinsertrwZ add_reinstall list_installs get_reasonfilterrrrZTransactionItemReasonCompareZ add_installrrZmapall list_upgradespopremoveZ add_upgradeZ list_erasuresr`rqrKIGNORE_EXCLUDESrr set_reasonZ add_erase)r3rtsZinstallonly_queryZinstallonly_query_installedZobsZ downgradedZ nevra_pkg obsoletesZobs_pkgZ reinstalledreasonZobsoleteZreason_obsoletecbZupgradedr[ZerasuresZremaining_installed_queryZ remainingr5)rrr3r6_goal2transactions                        zBase._goal2transactioncCsd|j}|j}|jj}g}g}x6|D].}||krJ|j||dq*|j||q*W||fS)aJ See what packages in the query match packages (also in older versions, but always same architecture) that are already installed. Unlike in case of _sltr_matches_installed(), it is practical here to know even the packages in the original query that can still be installed. r)r_na_dict availablerw)r3qinstZ inst_per_archZavail_per_archZavail_lZinst_lZnar5r5r6_query_matches_installed7s  zBase._query_matches_installedcCs"|jjjj|jd}t|S)z See if sltr matches a patches that is (in older version or different architecture perhaps) already installed. )r)r`rqrrrmatcheslist)r3sltrrr5r5r6_sltr_matches_installedKszBase._sltr_matches_installedcsfddjjjDS)z5Get iterator over the packages installed by the user.c3s|]}jj|r|VqdS)N)rZuser_installed)rZr)r3r5r6 Tsz*Base.iter_userinstalled..)r`rqr)r3r5)r3r6iter_userinstalledRszBase.iter_userinstalledcCs0|j||jj|jj d}|jjr,|jd|S)N)allow_uninstall force_bestZignore_weak_depsz./debugdata/rpms)runr4bestZinstall_weak_depsrbZwrite_debugdata)r3r allow_erasingretr5r5r6_run_hawkey_goalWs  zBase._run_hawkey_goalc Cstd}|jtjjd}|jj|j}|jrJ|j|j j j |j n|j jsd|j}|j||j|j j j|j jd|j||s|j jdkr|jtjj|j}tjj|}n |j||_|jj||jdk ot|jdk}|r|jj }|rtjj!|}|dk r"||j"j#|jj$}||jj%7}||jj&7}||jj'7}|j j(|j)||S)zBuild the transaction set.NZdepsolve)rr)*_finalize_comps_transrr#rr"startrZ req_has_eraseZpush_userinstalledr`rqrrr4Zupgrade_group_objects_upgrade_build_comps_solverZ'_exclude_packages_from_installed_groupsZ add_protectedrrZprotected_packagesr debuglevelZ log_decisionsr_format_resolve_problems problem_rulesrQZ DepsolveErrorrrendrpZ_rpm_limitationsrcr*Z run_resolvedrrrrZset_modules_enabled_by_pkgsetra) r3rexcrrsolverrZgot_transactionZnew_pkgsr5r5r6resolve_sH              z Base.resolvec Cs^t|ts|g}tjjjgt|}|js|jj |jj |j r|j j sV|j j rd}t|drx|jrxdj|j}nt|dr|jrdj|j}|jj}|dkr|jj}n|j}|jj|gg||jj||jj|jjd|_dSd}tjtdtj j!|j"j#|j"j$}||jj%|j&|j'}|rxtd}tj(|x|D]}tj(|qXWtj)j*|tjtdtj+j,d} tjtd |j&j-|j&j.tjjj/|dd } |j&j0| } t1| d kr\x&| j2D]}tj3td j4|qWtd d} x| D]} | dt5| 7} qW|j6| }|rP| d|7} tj)j7| ~ tjtd|j&j8t9j:rdS| |jj |jj tj+j,d} tjjj/||d}|j"j;dkrx|j|d}WdQRX| |jj?|j|jjdd}x&tj@jA||j|D]}tjB|qFW|S)Nargs cmdsTzRunning transaction checkz%Error: transaction check vs depsolve:zTransaction check succeeded.ztransaction testzRunning transaction test)rrzRPM: {}zTransaction test error: z %s zTransaction test succeeded.r)displaysFzRunning transaction)rcSs,g}x"|D]}|jdj|t|q W|S)Nz{}: {})rwrOr)actionZtsismsgstsir5r5r6 _pto_callbacks z*Base.do_transaction.._pto_callback)C isinstancerrZyumZrpmtransZLoggingTransactionDisplayr rrarZupdateFailSafeDatargroupenvhasattrr"rr$rlastr`_rpmdb_versionend_rpmdb_versionbegrr*Zrun_pre_transactionZrun_transactionr+rMrrrZbuild_rpmdb_lockr4rrZ_populate_rpm_tsr_run_rpm_checkerrorrQZTransactionCheckErrorr#rorderZcleanZRPMTransactionrrpmessagesrrOr _trans_error_summaryrc isTsFlagSetr(RPMTRANS_FLAG_TESTrr&r2_run_transactionZunload_removed_pluginsrZ_post_transaction_outputrN)r3ZdisplaycmdlineoldZ rpmdb_versiontidrr)rrZtestcbZtserrors errstringZdescrsummaryrZdisplay_r+r5r5r6do_transactions                              zBase.do_transactioncCsd}tjd}i}x|j|D]t}|jddkr>t|jdntjt|jdd}|jd|krr|||jd<||jd|kr|||jd<qW|r|tdd 7}x4|D],}|d td d ||j |||d 7}qW|sd Std d|}|S)zParse the error string for 'interesting' errors which can be grouped, such as disk space issues. :param errstring: the error string :return: a string containing a summary of the errors z9needs (\d+)(K|M)B(?: more space)? on the (\S+) filesystemr'Mrg@zDisk Requirements:r%z z7At least {0}MB more space needed on the {1} filesystem.Nz Error Summaryz ------------- ) recompilefinditerr-rmathZceilrr rO)r3r?r@pZdiskmZ size_in_mbkr5r5r6r8s&   *zBase._trans_error_summarycCs|jjo|jjtj S)N)r4Zhistory_recordrr9r(r:)r3r5r5r6_record_history%szBase._record_historycCsd}|jrt|jj}|jjj}|j|dj}|jj }|j j }|dk rX|j }|dksh||krt jtdjtjjdd}t|dr|jrdj|j}nt|dr|jrdj|j}|jjr|jjnd} |j j||g|| }|jjr$tjd } | r$ytj| Wnd } YnXt jtjjd |j j|j!d} t jtjjd |jjrzytj| Wn YnXtjj"|j |j#| dkrnt$| d krd d |j D} | sfx&|j%D]} t j&tdj| qWtd} tj'j(| nlt j&tdx | D]}t j&t)|d qW|jrR|j j*t+j, rR|j j-|td} tj'j(| xbdD]Z}t||rlt.||}yt/j0|Wn.t1t2fk rtd} t j&| |YnXqlWt3|j#j4|_5|j j*t+j,s|j6|j7|S)zh Perform the RPM transaction. :return: history database transaction ID or None N)rz RPMDB altered outside of {prog}.)rr"r#r$rBrzRPM transaction start.zRPM transaction over.cSsg|]}|jr|qSr5)ZFailed)rZZelr5r5r6r\esz)Base._run_transaction..zRPM: {}zCould not run transaction.zTransaction couldn't start: ts_all_fn ts_done_fnz$Failed to remove transaction file %s)rMrN)8rLr r4Zhistory_record_packagesr`rqrrrr1rr0r2rMrNrrOrrZMAIN_PROG_UPPERr/r"rr$commentr3Z reset_nicernicerr#rrr!Z_sync_rpm_trans_with_swdbrrpr7rrQrcr r9r(r:rgetattrr unlink_frOSErrorboolZ install_setr,_verify_transactionZverify_tsi_package)r3rr>Zusing_pkgs_patsinstalled_queryZ using_pkgsrpmdbvZlastdbvr<rOZoniceerrorsZfailedrrUr[fnr5r5r6r;)s~                 zBase._run_transactioncsdd|jD}t|fdd}tjjd}d}tjj|}|jj}t dd|D}xH|j j D]<} | j } x.| j D]"} | j|kr| jd| jqWqjWx|D]} || j|}qW|j} |j j| |d|_dS) NcSsg|]}|jtjjkr|qSr5)r(rrZ#TransactionItemAction_REASON_CHANGE)rZr*r5r5r6r\sz,Base._verify_transaction..cs |d7}dk r|||S)Nrr5)rcount)total verify_pkg_cbr5r6display_banners z0Base._verify_transaction..display_bannerzverify transactionrcSsg|] }|jqSr5)r)rZr[r5r5r6r\sT)rrprr#rr` rpmdb_sackrqrrrr-ZgetCompsGroupItemZ getPackagesZgetNameZ setInstalledrrr1rr+)r3r\Ztransaction_itemsr]rrZr^rnamesZtigrIr*rWr5)r[r\r6rUs(       zBase._verify_transactionc sXtjj|jj|jj}|tj}tdd|D}tdd|D} j j j dkrnj t||| dnj t||tj j |||jrtjjjtfdd|D} tj jd|j} |jj} | dk} xԈjo| s| dkr| dkr| d 8} td }tj|d djD}fd d|D}td d|D}j t||tj j |||jrtjjj| tfdd|D7} tj j| |i} qWjrtjjjj}tj|WdQRX|dk r|| || \}}||krT||krtd}n||kr,td}d||d}tj||d|d|dS)Ncss|] }|jVqdS)N) download_size)rZploadr5r5r6rsz1Base._download_remote_payloads..cSsg|]}t|tjjr|qSr5)r,rdrpmZ DeltaPayload)rZZpayloadr5r5r6r\sz2Base._download_remote_payloads..)Z total_drpmsc3s|]}j|VqdS)N)_bandwidth_used)rZrb)rXr5r6rsrrz,Some packages were not downloaded. Retrying.cSsg|]}|qSr5r5)rZrr5r5r6r\scs g|]}tjj|tjjqSr5)rrS _pkg2payload RPMPayload)rZr)progressr5r6r\scss|] }|jVqdS)N)ra)rZrbr5r5r6rsc3s|]}j|VqdS)N)re)rZrb)rXr5r6rsz?Delta RPMs reduced %.1f MB of updates to %.1f MB (%d.1%% saved)zIFailed Delta RPMs increased %.1f MB of updates to %.1f MB (%d.1%% wasted)dir')rrii)rrZbuild_download_lockr4rrrsumrpr__code__ co_argcountrSZ_download_payloadsZ_irrecoverablerQZ DownloadErrorZ_update_savingZ _recoverableretriesrrMrZ errmap2str)r3payloadsrcrhcallback_totalZ fail_fastrZ beg_downloadZest_remote_sizeZ total_drpmZ remote_sizeZsavingrmZforeverrZremaining_pkgsrealZfullZpercentr5)rXrhr6_download_remote_payloadssb              zBase._download_remote_payloadsc s|j|\}}|rzdkr$tjjtjj|jjj|j j |j dd|Dfdd|D}|j |||j j rxX|D]P}|jrtjj|j|jjd}ntjj|jj|jjd}tj||j j qWdS)aDownload the packages specified by the given list of packages. `pkglist` is a list of packages to download, `progress` is an optional DownloadProgress instance, `callback_total` an optional callback to output messages about the download operation. NcSsg|] }|jqSr5)localPkg)rZrr5r5r6r\sz*Base.download_packages..cs$g|]}tjj|jtjjqSr5)rrSrfZ delta_factoryrg)rZr)rcrhr5r6r\s/)_select_remote_pkgsrr!ZNullDownloadProgressrcZ DeltaInfor`rqrr4Zdeltarpm_percentager?rqr=ZbaseurlrrrZget_local_baseurllocationlstriprSZpkgdirshutilcopy) r3Zpkglistrhro remote_pkgsZ local_pkgsrnrrur5)rcrhr6download_packagess"      zBase.download_packagescCsg}|s |S|jjr&tjjtdg}x|D]}tjj| rhd|krhtj j ||j |}|j |gy|j |jj|Wq0tk r}ztj||j |WYdd}~Xq0Xq0W|jdd|r|rttdjdj||S)NzACannot add local packages, because transaction job already existsz://T)rzzCould not open: {}r#)rZ req_lengthrrQrcrrrrrZ_urlopen_progressr4r?rwr`Zadd_cmdline_packagerrMrdrrOr)r3 path_liststrictrhpkgsZ pkgs_errorrrUr5r5r6add_remote_rpmss(       zBase.add_remote_rpmsc Cs|jr|jj}d}n|j|j}|j}|j }|r|jj}tj j j |}tj j j ||j}tjj|j}~|dkrd} d} n|dkr|rd} nd} td|} n\|dkrd} td|} nB|dkr|rd} nd} d} td|} n|d krd} td |} nd} d} | | fS) aVerify the GPG signature of the given package object. :param po: the package object to verify the signature of :return: (result, error_string) where result is:: 0 = GPG signature verifies ok or verification is not required. 1 = GPG verification failed but installation of the right GPG key might help. 2 = Fatal GPG verification error, give up. rrBrr'z"Public key for %s is not installedzProblem opening package %srDz Public key for %s is not trustedrdzPackage %s is not signed) _from_cmdliner4Zlocalpkg_gpgcheckr^r~ZgpgcheckgpgkeyrYrr(rinitReadOnlyTransactionZ miscutilsZcheckSigrrrrbasenamer) r3pocheckZ hasgpgkeyrSrootrZ sigresultZlocalfnresultrr5r5r6_sig_check_pkg(sF    zBase._sig_check_pkgcCs |j|S)aVerify the GPG signature of the given package object. :param pkg: the package object to verify the signature of :return: (result, error_string) where result is:: 0 = GPG signature verifies ok or verification is not required. 1 = GPG verification failed but installation of the right GPG key might help. 2 = Fatal GPG verification error, give up. )r)r3rr5r5r6package_signature_checkcs zBase.package_signature_checkc Cslxf|D]^}tjj|sqytj|Wn&tk rLtjtd|wYqXtj t j j td|qWdS)NzCannot remove %sz %s removed) rrrr rRrSrMrdrrrr#r)r3packagesrYr5r5r6rrs   zBase._clean_packagesrhcCsv|dkr|jj}|dkr*|j|||||Stj|j||||d}|dksTt|dkr\|dSt||}tjdd|S)aRReturn a :class:`misc.GenericHolder` containing lists of package objects. The contents of the lists are specified in various ways by the arguments. :param pkgnarrow: a string specifying which types of packages lists to produces, such as updates, installed, available, etc. :param patterns: a list of names or wildcards specifying packages to list :param showdups: whether to include duplicate packages in the lists :param ignore_case: whether to ignore case when searching by package names :param reponame: limit packages list to the given repository :return: a :class:`misc.GenericHolder` instance with the following lists defined:: available = list of packageObjects installed = list of packageObjects upgrades = tuples of packageObjects (updating, installed) extras = list of packageObjects obsoletes = tuples of packageObjects (obsoleting, installed) recent = list of packageObjects N)showdups ignore_casermrcSs |j|S)N)Z merge_lists)abr5r5r6rsz(Base._do_package_lists..)r4Zshowdupesfromrepos _list_patternrpartialrpmapr)r3 pkgnarrowpatternsrrrmZlist_fnZyghsr5r5r6_do_package_listss  zBase._do_package_listsc&sfddfdd}fdd}tj|d}g} g} g} g} g} g}g}g}g}g}|}jj}|dk rtjj||d}|jjd d }|d kri}i}xH|jD]<}|||j <|rq|j |j f}||ks|||kr|||<qWt ||j } ||j}|s|jd d }x|D]}|rN|j |krB| j|n | j|nT|j |j f}|j |krr| j|n0||ks|j||r| j|n | j|q Wn|dkr||jd d} j| d d} | jddgd| jj} nP|dkrt ||j} n2|dkrB|r||j}|jj}x\|D]Tj j f}|j|g}fdd|D}t|dkr| jn | jq@Wn||jjd d j}|jjj}xz|D]r\} }!|| |!fd|j| |!fdgd}"|" s j|"r| jn"j|"r.| jn | jqWn|dkrh||jjj}#|#j}n|dkrfdd|jD}n|dkr|j}$|jjj|$d}j|d d d}|jddgdg}xl|D],j}%|jfdd|$j|%d DqWn6|d!krD|j}|s2|jd d }||j j!j"}| |_| |_| |_#| |_$| |_%||_||_&||_"||_||_'|S)"Ncsdkr dSjj|kS)z:Test whether given package originates from the repository.NT)rrS)package)rmr3r5r6 is_from_reposz(Base._list_pattern..is_from_repocsfdd|DS)z=Filter out the packages which do not originate from the repo.c3s|]}|r|VqdS)Nr5)rZr)rr5r6rsz=Base._list_pattern..pkgs_from_repo..r5)r)rr5r6pkgs_from_reposz*Base._list_pattern..pkgs_from_repocsdkr |S|jdS)z=Filter out the packages which do not originate from the repo.N)rm)r)rq)rmr5r6query_for_reposz*Base._list_pattern..query_for_repo)iter)rF)rkrhT)Zlatest_per_arch_by_priorityupgrades)Zupgrades_by_priority)upgradesrcnosrc) arch__neqrrcsg|]}|jjkr|qSr5)evr)rZr) avail_pkgr5r6r\sz&Base._list_pattern..r autoremoveextrascsg|]}|r|qSr5r5)rZr)rr5r6r\sr)Zobsoletes_by_priority)rdrcsg|] }|fqSr5r5)rZr=)newr5r6r\.s)providesrecent)(r Z GenericHolderr`rqrrsrtrvrZpkgtuprrr rrrrrwZevr_gt_merge_update_filterslatestrrrrpZevr_eq _unneededrswdbrrrextendZ_recentr4rreinstall_available old_availableupdatesobsoletesTuplesr)&r3rpatternrrrmrrZyghrrrrrrrrrrZicrr|ZdinstZndinstrkeyZavailrZinstalled_dictinstalled_pkgsZsame_verZavailable_dictrrZinst_pkgZ autoremove_qrZobsoleted_reldepsr5)rrrrmr3r6rs                                      zBase._list_patterncCs|j|7_t|S)N)rrp)r3transr5r5r6_add_comps_transEszBase._add_comps_transcs|j}|sdS|jjjdd}|jfdd|Dd}|j|}x|D]}jj|tjj qLW|j |}|j |}|rx |D]}j j |j jdqWdS)z Mark to remove packages that are not required by any user installed package (reason group or user) :param query: dnf.query.Query() object NF)rbcs g|]}jjj|jr|qSr5)rr-Zis_removable_pkgr)rZr[)r3r5r6r\Usz,Base._remove_if_unneeded..)r) clean_deps)rZ_safe_to_removerrr differencerrrZ TransactionItemReason_DEPENDENCY intersectionreraser4clean_requirements_on_remove)r3rqZ unneeded_pkgsZunneeded_pkgs_historyZpkg_with_dependent_pkgsrZremove_packagesr5)r3r6_remove_if_unneededIs     zBase._remove_if_unneededcs>j}jjd}fdd}fdd}dd}jjjdd }|jtj|dd f|j tj|d d f|j |f|j |ff}x|D]\}} x|D]} d | j i} | j r| jd |ijjjf| j} | jddgd| s | j } | j r| d|7} tjtdj| q| | || }jjj| j qWqWj|dS)Nrcs,tjjj}|j|djj|d|S)N)r)select)rselectorSelectorr`rrr)rq remove_query comps_pkgr )r3r5r6 trans_upgradegs z1Base._finalize_comps_trans..trans_upgradecsjjdkrr|js"j||dq|jj}j|tjj j }|j dj |j |jdjj|| dnltjj j }|jr|j dj |j |jdn,jjr|jj jj|d}|j |djj|| d|S)Nrh)r|z ({} if {}))r)roptional)r)r)r4multilib_policyZrequires_install_multiarchrrx_report_already_installedrrrr`rrOrrinstallrrurqrr)rqrrr|rVr )r3r5r6 trans_installms     z1Base._finalize_comps_trans..trans_installcSs|j|}|S)N)ru)rqrrr5r5r6 trans_removes z0Base._finalize_comps_trans..trans_removeT)ri)r|Frrrr)r.zNo match for group package "{}")rr4rXr`rqrrrrr install_optrrrZ basearchonlyr<rxrMrdrrOrZ group_membersrr)r3rrrrrrZattr_fnattrrYrZ query_argsrZpackage_stringr5)r3r6rcs4        zBase._finalize_comps_transcs fdd}tjjjj|S)Nc sNjjjj|d}|sdSyjjj|dStk rHtj j SXdS)N)rr) r`rqrrrrr(rAttributeErrorrrZTransactionItemReason_UNKNOWN)Zpkgnamer)r3r5r6 reason_fnsz+Base._build_comps_solver..reason_fn)rrZSolverrr)r3rr5)r3r6rs zBase._build_comps_solvercCsH|j}t|tstjj|}|j|||p.t||}|s>dS|j|S)a&Installs packages of environment group identified by env_id. :param types: Types of packages to install. Either an integer as a logical conjunction of CompsPackageType ids or a list of string package type ids (conditional, default, mandatory, optional). r) rr,rrrlistToCompsPackageTypeZ_environment_installrr)r3env_idtypesexcluder|exclude_groupsr rr5r5r6environment_installs  zBase.environment_installcCs|j}|j|}|j|S)N)rZ_environment_remover)r3rr rr5r5r6environment_removes zBase.environment_removec sfddd}|r2fdd|D}tjj|}j}t|tsPtjj|}|j ||||}|shdS|rt|j } n|j } t j td|| j|S)anInstalls packages of selected group :param pkg_types: Types of packages to install. Either an integer as a logical conjunction of CompsPackageType ids or a list of string package type ids (conditional, default, mandatory, optional). :param exclude: list of package name glob patterns that will be excluded from install set :param strict: boolean indicating whether group packages that exist but are non-installable due to e.g. dependency issues should be skipped (False) or cause transaction to fail to resolve (True) cs6tjj|r,jjj|d}tdd|S|fSdS)N) name__globcSs|jS)N)r)rIr5r5r6rszABase.group_install.._pattern_to_pkgname..)rris_glob_patternr`rqrrr)rr)r3r5r6_pattern_to_pkgnames z/Base.group_install.._pattern_to_pkgnameNcsg|] }|qSr5r5)rZrI)rr5r6r\sz&Base.group_install..rz#Adding packages from group '%s': %s) itertoolschain from_iterablerr,rrrrZ_group_installrrrMrNrr) r3grp_idZ pkg_typesrr|Zexclude_pkgnamesZnested_excludesr rZinstlogr5)rr3r6 group_installs"     zBase.group_installcCst|j|jtjtjBtj}d}d}x|D]} y|j| } Wn:tjj k rv} zt j t | d}w*WYdd} ~ XnXx2| j D](} | s| |kr||j| |||d7}qWx&| jD]} ||j| ||||d7}qWq*W| r|rtjjtd|S)NrTF)rr|)rr|rzNothing to do.)rrr ENVIRONMENTSGROUPS AVAILABLErrrQrrMr5r groupsr environmentsrrcr)r3rrr|rrrcntdonerreserrZgroup_idrr5r5r6env_group_installs(    zBase.env_group_installcCs|j}|j|}|j|S)N)rZ _group_remover)r3rr rr5r5r6 group_removes zBase.group_removecCst|j|jtjtjBtj}y|j|}WnFtjj k rp}z&t j dt |tjj tdWYdd}~XnXd}x|jD]}||j|7}q~Wx|jD]}||j|7}qW|S)Nz Warning: %szNo groups marked for removal.r)rrrrr INSTALLEDrrrQrrMr5r rcrrrrr)r3rrrrrr.grpr5r5r6env_group_remove s  "  zBase.env_group_removec CsLt|j|jtjtjBtj}d}x |D]}y|j|}Wn6tjj k rr}zt j t |w(WYdd}~XnXxX|j D]N}y|j|d}Wq|tjj k r}zt j t |w|WYdd}~Xq|Xq|WxZ|jD]P}y|j|d}Wqtjj k r$}zt j t |wWYdd}~XqXqWq(W|sHtd} tjj| dS)NFTzNo group marked for upgrade.)rrrrrrrrrQrrMr5r renvironment_upgrader group_upgraderrZCliError) r3rrZgroup_upgradedrrrr.rrr5r5r6env_group_upgrades6      zBase.env_group_upgradecCs|j}|j|}|j|S)N)rZ_environment_upgrader)r3rr rr5r5r6r9s zBase.environment_upgradecCs|j}|j|}|j|S)N)rZ_group_upgrader)r3rr rr5r5r6r@s zBase.group_upgradecCs|jjd}tjj|rdS|jj}tjjj |d}|j tj tj B|j dd}t|}~~|dkrldStjj|}tjj|stj|t|d}|j~dSdS) zChecks for the presence of GPG keys in the rpmdb. :return: 0 if there are no GPG keys in the rpmdb, and 1 if there are keys z/.gpgkeyschecked.yumr)rrz gpg-pubkeyrwN)r4rrrrrYrr(rrr_RPMVSF_NOSIGNATURES_RPMVSF_NODIGESTSZdbMatchrpdirnamemakedirsopenr9)r3ZgpgkeyscheckedrYZmytsidxkeysZmydirZfor5r5r6_gpg_key_checkGs&       zBase._gpg_key_checkc Cs|j|\}}|j|x~|D]v}tjj|j}|jjj|d}|jj rb|j |jjj|d}|j |d}|dk r|j |d}|j j || dqWt|S)N)r)r)rm)rr)r rrrrr`rqrrr4rrurrrrp) r3rqrmr| already_instrrr rr5r5r6res    zBase._install_multiarchcCs,tj}tj}t||t||||fS)a Categorize :param install and :param exclude list into two groups each (packages and groups) :param install: list of specs, whether packages ('foo') or groups/modules ('@bar') :param exclude: list of specs, whether packages ('foo') or groups/modules ('@bar') :return: categorized install and exclude specs (stored in argparse.Namespace class) To access packages use: specs.pkg_specs, to access groups use: specs.grp_specs )argparseZ Namespacer )r3rr install_specs exclude_specsr5r5r6_categorize_specsss   zBase._categorize_specscsddd|jDfdd|jD}|jjj|d}|jjjd}|jj||jj|dS)NcSsg|]}tjj|r|qSr5)rrr)rZrr5r5r6r\sz/Base._exclude_package_specs..csg|]}|kr|qSr5r5)rZr) glob_excludesr5r6r\s)r)r) pkg_specsr`rqrry)r3rexcludesr}Zglob_exclude_queryr5)rr6_exclude_package_specss  zBase._exclude_package_specsc Cst}t|j|jtjtjBtjtjB}x|D]}y|j|}Wn8t j j k rx}zt j dt|w.WYdd}~XnX|j|j|j|jx8|jD].}|jj|}x|jD]} |j| jqWqWq.Wt|S)NzWarning: Module or %s)rrrrrrrrrrrQrrMr5r r<rrZ_environment_by_idZ groups_iterrrPr ) r3 group_specsrrrrrZenvironment_idZ environmentr-r5r5r6_expand_groupss"       zBase._expand_groupsc Csx|D]x}yL|jj}d|kr<|jd}|d}|djd}|j|g|||j|jWqtjjk r||j d|YqXqWdS)Nrsrr,@) r4Zgroup_package_typessplitrr grp_specsrrQrcrw)r3rrZskippedr|Z group_specrrr5r5r6_install_groupss   zBase._install_groupscCs|dkr g}g}g}g}g} |j||\} } |j| xd| jD]Z} y|j| |||dWq>tjjk r} ztjt | |j | WYdd} ~ Xq>Xq>Wg}f}t o| j rLy tj jj|}|j| j |Wnxtjjk rH} zV| jr x| jD]}|j |qW| jr2x| jD]}|j d|qW| j}WYdd} ~ XnXn| j }|rv|j| j | _ |j|| |||s|s|s| s|rtjj|||| |ddS)N)rmr|formsr)no_match_group_specserror_group_specsno_match_pkg_specserror_pkg_specsmodule_depsolv_errors)rrrrrrQ MarkingErrorrMr5rrwrorrerfZ ModuleBaseZ MarkingErrorsrrr rr)r3rrrmr|rrrrrrrspecrUZno_match_module_specsr rfZe_specr5r5r6rsN      zBase.install_specsc Cstjj|}|j|j|dd}|jjdks4|j|rr|d}|dk rP|j|d|sb|j ||||j |||dS|jjdkr|j |||jj |d |d }|s|j |||x|D]} |j j| | d qWd Sd S)z@Mark package(s) given by pkg_spec and reponame for installation.F)rwith_srcrhrqN)rm)rmr|rT)rrrmreportssolution)rrrr)rrsrtget_best_solutionr`r4rZ_is_arch_specifiedrr_raise_package_not_found_errorr_get_best_selectorsrrr) r3pkg_specrmr|rr|rrsltrsr r5r5r6rs,    z Base.installcCs|jrd}t||jjjj|j|jdgd}|shtd}t j ||jt j j td|j|jn\t|d|krt jj|j}|j|gd|jj|| dd Std }t j ||jdSdS) Nz-downgrade_package() for an installed package.noarch)rrz.Package %s not installed, cannot downgrade it.zNo match for argument: %sr)r)rrrzCPackage %s of lower version already installed, cannot downgrade it.) _from_systemNotImplementedErrorr`rqrrrrrrrMrdrrQr rusortedrrrrr)r3rr|rrr r5r5r6package_downgrades  zBase.package_downgradecCs|jjj|j|j|j}|j|\}}||kr>|j|gnT|tj j |krdt j j td|jn.t jj|j}|j|gd|jj|| ddS)NzNo match for argument: %s)r)rrr)r`rq_nevrarrrr rrrrrrQPackageNotFoundErrorrrurrrrr)r3rr|rrrr r5r5r6package_installszBase.package_installcCsf|jjjj|j|j|jdr0|jj|dSt d}t j |t |t jjt d|j|jdS)N)rrrrz.Package %s not installed, cannot reinstall it.zNo match for argument: %s)r`rqrrrrrrrrrrMrdrrrQr ru)r3rrr5r5r6package_reinstall(s   zBase.package_reinstallcCs|jj|dS)Nr)rr)r3rr5r5r6package_remove0s zBase.package_removecCs`|jrd}t||jdkr6td}tj||jdS|jjj j }|j j r|jjj |gdj |drtjj|j}|j|gd|jj|ddS|jd kr|j|jd }n|j|j|jd gd }|std }tj||jtjjtd |j|jnZt|d|krBtjj|j}|j|gd|jj|ddStd}tj||jdSdS)Nz+upgrade_package() for an installed package.rz.)r)r)rmT)rrcSsg|] }|jqSr5)r)rZrr5r5r6r\xs)r)rr)r`rqrrrrrrurrrrrrrrrr) r3rqrrmrZ installed_allrrVr r5r5r6_upgrade_internalYs "    zBase._upgrade_internalc Csttjj|}|j|j}|d}|rZtjj|}| oH|doH|djr*|dj}|jjj j }|j j r||j |dn|jjjdd} | s*|j |dj } | std} tj| |tjjtd||nV|djotjj|dj r*| j|djd s*td } tj| d j||dj|j j oH|doH|dj} |j|| ||Stjjtd||dS) Nrqnevra)rT)ri)rz(Package %s available, but not installed.zNo match for argument: %s)rz?Package %s available, but installed for different architecture.z{}.{})rrsrtrr`rrrrqrrxr4rrrrrrMrdrQPackagesNotInstalledErrorrrOZ has_just_namerr ) r3rrmr|rrZwildcardpkg_namerZ obsoletersZinstalled_namerrr5r5r6rs0    &   z Base.upgradecCs|j|jj|jj|ddS)N)r)rr`rqr4r)r3rmr5r5r6 upgrade_allszBase.upgrade_allcCs|dkr|jjnxtjj|}|j|jdd}|djtj d|j |||j j dd}|spt jtd|dSx|D]}|jj|d qvWd S) NF)r rq) reponame__neqT)rrr zNo package %s installed.r)rr)rZdistupgrade_allrrsrtrr`rrrKZSYSTEM_REPO_NAMErr4rrMrrZ distupgrade)r3rrsrrr r5r5r6 distro_syncs   zBase.distro_syncc Cst|||gr||7}d}|rF|rFx4|D]}td}tj||q(Wn|rX|j|rXd}xX|D]P}y|j||dWn4tjjk r} ztj t | WYdd} ~ Xq^Xd}q^W|stjtdn4|j j j |jj|jjd} x| D]} |j| qWdS)zRemoves all 'leaf' packages from the system that were originally installed as dependencies of user-installed packages but which are no longer required by any such package.FzNot a valid form: %sT)rNzNo packages marked for removal.)rb)anyrrMrdrrrrQr rrr`rqrrrr4rbr) r3rrr filenamesrZgrp_specrrrUr}rr5r5r6rs,      zBase.autoremovecsptjj|jj|d}fdd|jD}|sBj||jj}x|D]}j j ||dqPWt |S)z'Mark the specified package for removal.)rcs(g|] }dks jj|kr|qS)N)rrS)rZr)rmr3r5r6r\szBase.remove..)r) rrsrtrvr`r"_raise_package_not_installed_errorr4rrrrp)r3rrmrr rrrr5)rmr3r6rs z Base.removec s tjj|}|jj}fdd|jD}|j} |dk rL| j|d|dk r`| j|dtjj | } |stj j d|| j d} j j} x\|D]T} y| t| }Wn*tk r|swjj| | dYnXjj|| d7} qW| dkrtj jd||| S) Ncs(g|] }dks jj|kr|qS)N)rrS)rZr) old_reponamer3r5r6r\sz"Base.reinstall..)rm)r$zno package matchedr)rr)rrsrtrvr`rrrrrqZ_per_nevra_dictrQr!rr4rr KeyErrorrrrZPackagesNotAvailableError)r3rr)Z new_reponameZnew_reponame_neqZ remove_nar|rrZ available_qZavailable_nevra2pkgrrZ installed_pkgZ available_pkgr5)r)r3r6 reinstalls6          zBase.reinstallcCs |j|S)zMark a package to be downgraded. This is equivalent to first removing the currently installed package, and then installing an older version. ) downgrade_to)r3rr5r5r6 downgrade szBase.downgradec Cstjj|}|j|j}|s6td|}tjj||d}|j}t |j j }|jj j j|d} t| dkrtd|}tjj|||xn| j j D]^} |jj| d} | std}tj|| qtjj|j} | j| d|jj| | dd}qW|S) zDowngrade to specific version if specified otherwise downgrades to one version lower than the package installed. zNo match for argument: %sr)rz6Packages for argument %s available, but not installed.zDPackage %s of lowest version already installed, cannot downgrade it.)r)rrr)rrsrtrvr`rrQrrr  _name_dictrrqrrrrpr!Z downgradesrrMrdrrrrr) r3rr|r|rrrZavailable_pkgsZavailable_pkg_namesZ q_installedr"Zdowngrade_pkgsr r5r5r6r, s.       zBase.downgrade_tocs|jjjd}|r |gfStjj|j}|r>|gfSjdsRjdr^dg}n&jdrr|gfSfddd D}|jjj|d|fS) N)Z file__glob/bin//sbin/z/usrrscsg|] }|qSr5r5)rZprefix) provides_specr5r6r\E sz!Base.provides.. /usr/bin/ /usr/sbin/)r/r0r3r4)r`rqrrrZ _by_provides startswith)r3r2Z providersZbinary_providesr5)r2r6r6 s      z Base.providesc Csddd}||krtd||}|rDd|} |jj| tj||rfd|} |jj| tj||rd|} |jj| tj||rd|} |jj| tj||rd |} |jj| tj|d S) a It modifies results of install, upgrade, and distrosync methods according to provided filters. :param cmp_type: only 'eq' or 'gte' allowed :param types: List or tuple with strings. E.g. 'bugfix', 'enhancement', 'newpackage', 'security' :param advisory: List or tuple with strings. E.g.Eg. FEDORA-2201-123 :param bugzilla: List or tuple with strings. Include packages that fix a Bugzilla ID, Eg. 123123. :param cves: List or tuple with strings. Include packages that fix a CVE (Common Vulnerabilities and Exposures) ID. Eg. CVE-2201-0123 :param severity: List or tuple with strings. Includes packages that provide a fix for an issue of the specified severity. Z__eqgZ __eqg__gt)eqZgtez Unsupported value for `cmp_type`Z advisory_typeadvisoryZ advisory_bugZ advisory_cveZadvisory_severityN)rr/ setdefaultrr<) r3Zcmp_typerr7ZbugzillaZcvesZseverityZcmp_dictZcmprr5r5r6add_security_filtersI s& zBase.add_security_filterscCs i|_dS)z, Reset all security filters N)r/)r3r5r5r6reset_security_filtersn szBase.reset_security_filtersc Cs>|jp |j s| r|S|jjjdd}|jrRx|jD]}|j|}q8W|g|_|jrx<|jjD].\}}|rx|d}||i} |j|jf| }qdW|j|}|s:|r:|j }t |j j } | dkr:|dkrt dj| } t dj| } tjt| | | n2t dj|| } t d j|| } tjt| | | |S) z Merge Queries in _update_filters and return intersection with q Query @param q: Query @return: Query T)riZ __upgraderNz3No security updates needed, but {} update availablez4No security updates needed, but {} updates availablez    zBase._merge_update_filtersc sjrtd}t||jjj|jk}|r:gnj}fdd}d}|jjjx |D]} t j j | } x| D]} t j |j| j| jdkrtd}tj|| | jq|jjrt jjj| j| j} t jjj| } tjt jj| | | | _|jjrt j j| | n t j j | d}|jj!r:d}n|jj"r|jjr| t jj#j$t jj#j%fkrd}tjt jj&tdnd}tjt jj&td nd}n<|r|| j| j| | j'| jd }n|r|| j| j}|sd}q|jj(t)j*}|r|jj+}|jj,|t)j*|jj-t j.| j}|rD|jj,||dkrjtd |}t j/j0||tjtd d}qWqhW| r|rt j/j0td |stdj1}t j/j0|||j2\}}|dkr|rtd}tj|t3|}t j/j0||dS)aRetrieve a key for a package. If needed, use the given callback to prompt whether the key should be imported. :param po: the package object to retrieve the key of :param askcb: Callback function to use to ask permission to import a key. The arguments *askcb* should take are the package object, the userid of the key, and the keyid :param fullaskcb: Callback function to use to ask permission to import a key. This differs from *askcb* in that it gets passed a dictionary so that we can expand the values passed. :raises: :class:`dnf.exceptions.Error` if there are errors retrieving the keys z6Unable to retrieve a key for a commandline package: %scs0|tdd7}|tddjj7}|S)Nz. Failing package is: %sz zGPG Keys are configured as: %sz, )rrr)r)rrSr5r6_prov_key_data sz1Base._get_key_for_package.._prov_key_dataFrz)GPG key at %s (0x%s) is already installedTzThe key has been approved.zThe key has been rejected.)ruseridZhexkeyidkeyurl fingerprint timestampzKey import failed (code %d)zKey imported successfullyzDidn't install any keyszThe GPG keys listed for the "%s" repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository.z+Import of key(s) didn't help, wrong key(s)?N)4rrrr^r~rPr1rrrZcryptoZretriever Z keyInstalledrZrpm_idrArMrZshort_idr4rrZKeyInfoZfrom_rpm_key_objectr>Zraw_keyZDNSSECKeyVerificationZverifyZ nice_user_msgurlZlog_dns_key_importZlog_key_importZassumenoZ assumeyesZValidityZVALIDZPROVEN_NONEXISTENCEZany_msgr@r9r(r:Z getTsFlagsrZpgpImportPubkeyZ procgpgkeyrQrcrrr )r3raskcb fullaskcbrZ key_installedZkeyurlsr=Z user_cb_failr?rrZ dns_input_keyZ dns_resultZrcZ test_flagZ orig_flagsrerrmsgr5)rrSr6_get_key_for_package s                zBase._get_key_for_packagecCs|j|||dS)aRetrieve a key for a package. If needed, use the given callback to prompt whether the key should be imported. :param pkg: the package object to retrieve the key of :param askcb: Callback function to use to ask permission to import a key. The arguments *askcb* should take are the package object, the userid of the key, and the keyid :param fullaskcb: Callback function to use to ask permission to import a key. This differs from *askcb* in that it gets passed a dictionary so that we can expand the values passed. :raises: :class:`dnf.exceptions.Error` if there are errors retrieving the keys N)rF)r3rrCrDr5r5r6package_import_key$ szBase.package_import_keycCs4g}|jjx |jjD]}|jt|qW|S)N)rrZproblemsrwr )r3resultsZprobr5r5r6r45 s  zBase._run_rpm_checkw+bcKstjj||j||f|S)z Open the specified absolute url, return a file object which respects proxy setting even for non-repo downloads )rrZ_urlopenr4)r3rBrSmoder<r5r5r6urlopen@ sz Base.urlopencCs,|dkr|jjtjd}|j|jjd}|S)N)r)r)rrqrKrrr4r)r3rZ installonlyr5r5r6rH szBase._get_installonly_querycCsrtjj|dd}|j|jdddd}|drn|drn|djrn||ddjkrntjtdj |ddjdS) NT)rF)rjrkrlrqr rz * Maybe you meant: {}) rrsrtrr`rrMrrrO)r3rr|rr5r5r6_report_icase_hintN s   zBase._report_icase_hintcCsdd}g}g}x6|D].}|jr:|jtjkrD|j|q|j|qWtd}|||sjtjjtd|j j rtd}|||stjjtdg}||fS)a  Check checksum of packages from local repositories and returns list packages from remote repositories that will be downloaded. Packages from commandline are skipped. :param install_pkgs: list of packages :return: list of remote pkgs cSsxd}xn|D]f}d}y |j}Wn0tk rN}ztjt|WYdd}~XnX|dk r tj|j||jd}q W|S)NTF)ZverifyLocalPkgrLrMrrrOrm)Zpkg_listZ logger_msgZall_packages_verifiedrZpkg_successfully_verifiedrUr5r5r6_verification_of_packages] s   z;Base._select_remote_pkgs.._verification_of_packagesz>Package "{}" from local repository "{}" has incorrect checksumz;Some packages from local repository have incorrect checksumz8Package "{}" from repository "{}" has incorrect checksumzVSome packages have invalid cache, but cannot be downloaded due to "--cacheonly" option) Z _is_local_pkgrmrKZCMDLINE_REPO_NAMErwrrrQrcr4r)r3Z install_pkgsrMryZlocal_repository_pkgsrrr5r5r6rtV s&       zBase._select_remote_pkgscCsx|D] }t|qWdS)N)_msg_installed)r3rrr5r5r6r s zBase._report_already_installedc Cs|jjtjd}tjj|}|j|j|d|d}|dk rH|dj|d|dsdtj j t d|nB|jjtj d}|dj |}|rt d}nt d}tj j ||dS) N)rF)rr rqrq)rmzNo match for argumentz?All matches were filtered out by exclude filtering for argumentz?All matches were filtered out by modular filtering for argument)r`rqrKrrrsrtrrrrQrrZIGNORE_REGULAR_EXCLUDESr) r3rrrm all_queryrsrZwith_regular_queryrr5r5r6r s  z#Base._raise_package_not_found_errorc sjjtjdj}tjj|}|jj|d|d}|dsNtj j t d|dk rpfdd|dD}n|d}|st d}nt d }tj j ||dS) N)rF)rr rqrqzNo match for argumentcs g|]}jj|kr|qSr5)rrS)rZr)rmr3r5r6r\ sz;Base._raise_package_not_installed_error..zCAll matches were installed from a different repository for argumentz?All matches were filtered out by exclude filtering for argument) r`rqrKrrrrsrtrrQr!r) r3rrrmrOrsrrrr5)rmr3r6r( s  z'Base._raise_package_not_installed_errorcCs|jj|jdddS)z Setup DNF file loggers based on given configuration file. The loggers are set the same way as if DNF was run from CLI. T)Zfile_loggers_onlyN)r$Z_setup_from_dnf_confr4)r3r5r5r6 setup_loggers szBase.setup_loggersc s|jjtjtjBtjB@r d}nd}t|j}|j|dd}|jf|}| rl|rlt j j |j }t j|t|jdd}t|jdd|} ddfdd|Dtfd d|D} tfd d| D} | | fS) zreturns set of conflicting packages and set of packages with broken dependency that would be additionally installed when --best and --allowerasingTF)rrZ ignore_weak)rcSstj|j|j|j|j|jdS)N)repochversionreleaser)rKZNEVRArrQrRrSr)itemr5r5r6r sz&Base._skipped_packages.._nevracsg|] }|qSr5r5)rZr*)rr5r6r\ sz*Base._skipped_packages..csg|]}|kr|qSr5r5)rZr)rtransaction_nevrasr5r6r\ scsg|]}|kr|qSr5r5)rZr)rrUr5r6r\ s)rZactionsrKINSTALLZUPGRADEZ UPGRADE_ALLrr0rrrrrrMrdrproblem_conflictsZproblem_broken_dependency) r3Zreport_problemsrrZngZparamsrrrWZproblem_dependencyZskipped_conflictsZskipped_dependencyr5)rrUr6_skipped_packages s(    zBase._skipped_packages)N)F)F)TT)T)N)FFF)F)F)N)T)NN)TN)rhNNFN)N)NTN)NT)TNN)NT)T)NNTN)NTN)F)T)N)N)N)N)NNNN)NN)NNNF)F)NTF)NN)NN)NrI)N)__name__ __module__ __qualname__r7r8r:r;r?rV staticmethodrrgrrpropertyrr4r^deleterrrZlazyattrrr`rarsetterrrrrrrrrrr9rrrr(ZRPMTRANS_FLAG_NOSCRIPTSZRPMTRANS_FLAG_NOTRIGGERSZRPMTRANS_FLAG_NODOCSr:ZRPMTRANS_FLAG_JUSTDBZRPMTRANS_FLAG_NOCONTEXTSZRPMTRANS_FLAG_NOFILEDIGESTrr/rrrrrrrrrrr r rrr!rAr8rLr;rUrqrzr~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr#r%rrr+r-r,rr9r:rrFrGr4rKrrLrtrrr(rPrXr5r5r5r6r[s   =      8 ; > =       '\ 8 l"] * B  ;  ) =  *     /   % &    #  & % )    -rcCs t|}td}tj||dS)Nz Package %s is already installed.)r rrMr)rrrr5r5r6rN srN)H__doc__Z __future__rrrrrrZlibdnf.transactionrrxrZ dnf.compsrZdnf.i18nrr r Zdnf.utilr Zdnf.db.historyr Zdnf.yumr collections.abcr ImportError collectionsrZ dnf.callbackZdnf.confZ dnf.conf.readZ dnf.cryptoZ dnf.dnssecZdnf.drpmZdnf.exceptionsZdnf.goalZ dnf.historyZdnf.lockZ dnf.loggingZdnf.module.module_baseroZ dnf.persistorZ dnf.pluginZ dnf.queryZdnf.repoZ dnf.repodictZdnf.rpm.connectionZdnf.rpm.miscutilsZdnf.rpm.transactionZdnf.sackZ dnf.selectorZ dnf.subjectZdnf.transactionZdnf.yum.rpmtransrrrKrr#rHrrrEr(rrwZ getLoggerrMobjectrrNr5r5r5r6s