3 f<@sddlZddlZddlZddlZddlmZddlm Z ddl Z Gddde Z Gddde Z Gdd d e ZGd d d e ZdS) N)_)loggerc@sleZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS) PersistorBasecCsBt|tjjjs ttt|||_i|_i|_ i|_ i|_ dS)N) isinstancednfdbhistoryZ SwdbInterfaceAssertionErrorstrtype _installed_removed _upgraded _downgraded)selfrr/usr/lib/python3.6/group.py__init__ s  zPersistorBase.__init__cCs(t|jt|jt|jt|jS)N)lenr r rr)rrrr__len__(szPersistorBase.__len__cCsi|_i|_i|_i|_dS)N)r r rr)rrrrclean+szPersistorBase.cleancCstdS)N)NotImplementedError)robjrrr _get_obj_id1szPersistorBase._get_obj_idcCs*|jjj|d|tjj}|jtjjdS)N)rswdbaddItemlibdnf transactionTransactionItemReason_USERZsetStateZTransactionItemState_DONE)ritemactiontirrr_add_to_history4szPersistorBase._add_to_historycCs$||j|j|<|j|tjjdS)N)r rr#rrTransactionItemAction_INSTALL)rrrrrinstall8szPersistorBase.installcCs$||j|j|<|j|tjjdS)N)r rr#rrTransactionItemAction_REMOVE)rrrrrremove<szPersistorBase.removecCs$||j|j|<|j|tjjdS)N)rrr#rrTransactionItemAction_UPGRADE)rrrrrupgrade@szPersistorBase.upgradecCs$||j|j|<|j|tjjdS)N)rrr#rrTransactionItemAction_DOWNGRADE)rrrrr downgradeDszPersistorBase.downgradecCstdS)N)r)robj_idnametranslated_name pkg_typesrrrnewHszPersistorBase.newcCstdS)N)r)rr,rrrgetKszPersistorBase.getcCstdS)N)r)rpatternrrrsearch_by_patternNszPersistorBase.search_by_patternN)__name__ __module__ __qualname__rrrrr#r%r'r)r+r0r1r3rrrrrsrc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)GroupPersistorcCs"|jjj}dd|D}t|S)NcSsg|]}|jr|qSr)getCompsGroupItem).0irrr Vsz+GroupPersistor.__iter__..)rrgetItemsiter)ritemsrrr__iter__Ts zGroupPersistor.__iter__cCs|jS)N) getGroupId)rrrrrrYszGroupPersistor._get_obj_idcCsH|jjj}|j||dk r(|j||dk r:|j||j||S)N)rrZcreateCompsGroupItemZ setGroupIdsetNamesetTranslatedNamesetPackageTypes)rr,r-r.r/ swdb_grouprrrr0\s     zGroupPersistor.newcCs"|jjj|}|sdS|j}|S)N)rrr8)rr,rDrrrr1fs zGroupPersistor.getcCs|jjj|S)N)rrZgetCompsGroupItemsByPattern)rr2rrrr3msz GroupPersistor.search_by_patterncCs|jjj|S)N)rrZgetPackageCompsGroups)rpkg_namerrrget_package_groupspsz!GroupPersistor.get_package_groupscCs|jjj|dd}|tjjkr"dSt|j|}xJ|jj D]<\}}x2|j D]&}|j |kr`qN|j sjqN|j |qNWqZ getPackagesZgetName getInstalledr'r add)rrEreasonZpackage_groupsgroup_idgrouppkgrrris_removable_pkgss*   zGroupPersistor.is_removable_pkgN) r4r5r6r?rr0r1r3rFrQrrrrr7Rs r7c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)EnvironmentPersistorcCs"|jjj}dd|D}t|S)NcSsg|]}|jr|qSr)getCompsEnvironmentItem)r9r:rrrr;sz1EnvironmentPersistor.__iter__..)rrr<r=)rr>rrrr?s zEnvironmentPersistor.__iter__cCs|jS)N)ZgetEnvironmentId)rrrrrrsz EnvironmentPersistor._get_obj_idcCsH|jjj}|j||dk r(|j||dk r:|j||j||S)N)rrZcreateCompsEnvironmentItemZsetEnvironmentIdrArBrC)rr,r-r.r/swdb_envrrrr0s     zEnvironmentPersistor.newcCs"|jjj|}|sdS|j}|S)N)rrrS)rr,rTrrrr1s zEnvironmentPersistor.getcCs|jjj|S)N)rrZ!getCompsEnvironmentItemsByPattern)rr2rrrr3sz&EnvironmentPersistor.search_by_patterncCs|jjj|S)N)rrZgetCompsGroupEnvironments)rrNrrrget_group_environmentssz+EnvironmentPersistor.get_group_environmentscCs|jjj|}|sdSt|j|}xJ|jjD]<\}}x2|jD]&}|j|krTqB|j s^qB|j |qBWq0WxJ|j jD]<\}}x2|jD]&}|j|krq|j sq|j |qWq|W|rdSdS)NFT) rrOr1rJrUr r>Z getGroupsr@rKr'r rL)rrNrDZgroup_environmentsZenv_idenvrOrrris_removable_groups*  z'EnvironmentPersistor.is_removable_groupN) r4r5r6r?rr0r1r3rUrWrrrrrRs rRc@seZdZd,ddZddZddZdd Zd-d d Zd d ZddZ ddZ d.ddZ d/ddZ d0ddZ d1ddZd2ddZd3ddZd4ddZd d!Zd"d#Zed$d%Zed&d'Zd(d)Zd*d+ZdS)5RPMTransactionNc Cs:||_||_|js0y|jjjWn YnXi|_dS)N)rrrZinitTransaction _swdb_ti_pkg)rrrrrrrszRPMTransaction.__init__cs8jrjj}n jjj}fdd|D}t|S)Ncs&g|]}|jrtjjjj|qSr) getRPMItemrrrRPMTransactionItemWrapper)r9r:)rrrr;sz+RPMTransaction.__iter__..)rr<rrr=)rr>r)rrr?s   zRPMTransaction.__iter__cs8jrjj}n jjj}fdd|D}t|S)Ncs&g|]}|jrtjjjj|qSr)rZrrrr[)r9r:)rrrr;sz*RPMTransaction.__len__..)rr<rrr)rr>r)rrrs   zRPMTransaction.__len__cCsP|jjj}|j|j|j|jp$d|j|j|j |j |j |j |S)Nr) rrZ createRPMItemrAr-ZsetEpochZepochZ setVersionversionZ setReleasereleaseZsetArcharch)rrPrpm_itemrrr_pkg_to_swdb_rpm_items     z$RPMTransaction._pkg_to_swdb_rpm_itemcCsV|j|}|j|}|dkr&|j|}|jjj||||}|rH|j|||j|<|S)N)r` get_repoid get_reasonrrr addReplacedByrY)rrPr!rM replaced_byr_Zrepoidresultrrrr0s     zRPMTransaction.newcCst|dd}|r|S|jS)NZ_force_swdb_repoid)getattrZreponame)rrPrerrrras zRPMTransaction.get_repoidcCs|jjj|j|jdS)zGet reason for package)rrrIr-r^)rrPrrrrbszRPMTransaction.get_reasoncCstjj|j|S)zGet reason for package)rrZTransactionItemReasonToStringrb)rrPrrrget_reason_nameszRPMTransaction.get_reason_namecCs8|pg}x*|D]"}|j|tjj}|r|j|qWdS)N)r0rrTransactionItemAction_OBSOLETEDrc)r obsoletedrdZobsr"rrr_add_obsoleted s  zRPMTransaction._add_obsoletedcCs6|j|tjj}|j|tjj|d}|j||ddS)N)rd)r0rrr* TransactionItemAction_DOWNGRADEDrl)rr0oldrkti_newti_oldrrr add_downgradeszRPMTransaction.add_downgradecCs|j||dS)N) add_remove)rrnrMrrr add_eraseszRPMTransaction.add_erasecCs4|dkrtjj}|j|tjj|}|j||ddS)N)rd)rrrr0r$rl)rr0rkrMrorrr add_installszRPMTransaction.add_installcCs6|j|tjj}|j|tjj|d}|j||ddS)N)rd)r0rrTransactionItemAction_REINSTALL!TransactionItemAction_REINSTALLEDrl)rr0rnrkrorprrr add_reinstallszRPMTransaction.add_reinstallcCs"|p tjj}|j|tjj|}dS)N)rrrr0r&)rrnrMrprrrrr$s zRPMTransaction.add_removecCs6|j|tjj}|j|tjj|d}|j||ddS)N)rd)r0rrr(TransactionItemAction_UPGRADEDrl)rr0rnrkrorprrr add_upgrade(szRPMTransaction.add_upgradec Cs^|jr dS|jjrdSy.|drB|j rBtjtdj|dSWntk rXdSXdS)NrZmodularitylabelz\No available modular metadata for modular package '{}', it cannot be installed on the systemrg) Z _from_cmdlineZrepoZmodule_hotfixesZ_is_in_active_modulerZcriticalrformat ValueError)rhdrrPrrr_test_fail_safe-s zRPMTransaction._test_fail_safecCsRd}x0|D]&}y|jtjjkrP|jj}||j||j7}|j||dn|jtjjkrp|j |jj n|jtjj kr|jj}||j||j7}|j||dnL|jtjj kr|jj}||j||j7}|j||dn|jtjj kr|j |jj n|jtjjkr<|jj}||j||j7}|j||n|jtjjkr\|j |jj n|jtjjkr||j |jj nz|jtjjkr|jj}||j||j7}|j||dn@|jtjjkr|j |jj n |jtjjkrntd|jWq tjk r2}ztjjtd|WYdd}~Xq Xq W|rNtjjtd|S)z!Populate the RPM transaction set.rur:z%TransactionItemAction not handled: %szAn rpm exception occurred: %sNz1No available modular metadata for modular package)r!rrr*rPZ_headerr}Z addInstallrmZaddEraseidxr$ZTransactionItemAction_OBSOLETErjruZ addReinstallrvr&r(rxZ#TransactionItemAction_REASON_CHANGE RuntimeErrorrpmerrorr exceptionsErrorr)rZtsZmodular_problemstsir|errr_populate_rpm_ts;sR*zRPMTransaction._populate_rpm_tsc CsXt}xL|D]D}|jtjjkr y|j|jWq tk rNtd|Yq Xq W|S)Nz*TransactionItem is has no RPM attached: %s) rJr!rrZFORWARD_ACTIONSrLrPKeyErrorr)rrerrrr install_setms zRPMTransaction.install_setc Csbt}xV|D]N}|jtjjtjjgkr y|j|jWq t k rXt d|Yq Xq W|S)Nz*TransactionItem is has no RPM attached: %s) rJr!rrZBACKWARD_ACTIONSrrvrLrPrr)rrerrrr remove_setys zRPMTransaction.remove_setcCs,dd|jD}t|r(td|dSdS)zj Ensures all the members can be passed to rpm as they are to perform the transaction. cSsg|]}|jdkr|qS)src)r^)r9rPrrrr;sz3RPMTransaction._rpm_limitations..z+Will not install a source rpm package (%s).rN)rrr)rZ src_installsrrr_rpm_limitationss  zRPMTransaction._rpm_limitationscsfdd|DS)Ncsg|]}|jkr|qSr)r!)r9r)r!rrr;sz-RPMTransaction._get_items..r)rr!r)r!r _get_itemsszRPMTransaction._get_items)N)NN)N)N)N)NN)N)N)N)r4r5r6rr?rr`r0rarbrirlrqrsrtrwrrryr}rpropertyrrrrrrrrrXs*          2  rX)Zlibdnf.transactionrZdnf.db.historyrZdnf.transactionZdnf.exceptionsZdnf.i18nrZdnf.utilrrobjectrr7rRrXrrrrs  3<<