3 faf@sddlmZddlmZddlmZddlZddlZddlmZddlZ ddl Z dZ dZ de e fZ Gddde jjZGd d d e jjZGd d d eZd dZddZGdddeZdS))absolute_import)print_function)unicode_literalsN)_z%s.%scseZdZfddZZS)TransactionErrorcstt|j|dS)N)superr__init__)selfmsg) __class__$/usr/lib/python3.6/transaction_sr.pyr/szTransactionError.__init__)__name__ __module__ __qualname__r __classcell__r r )r r r.srcseZdZfddZZS)TransactionReplayErrorcsv||_t|ttfr||_n|g|_|r:tdj|d}ntd}x|jD]}|dt|7}qJWtt |j |dS)z :param filename: The name of the transaction file being replayed :param errors: a list of error classes or a string with an error description zWThe following problems occurred while replaying the transaction from file "{filename}":)filenameztk r,} z ttd j| jd d WYdd} ~ XnX|S) NzGroup id '%s' is not available.r-zgroups.packages.namerer.zgroups.packages.installedbooleanr/zgroups.packages.package_typez.Missing object key "{key}" in groups.packages.r)rd)rDcompsZ _group_by_idrarHrrr;newr-ui_namer^rboolZ addPackager7r8stringToCompsPackageTyperErrorrrtrru) r group_id pkg_typespkgsZ comps_group swdb_groupr=r-r.r/r$r r r _create_swdb_groupvs* &*z$TransactionReplay._create_swdb_groupcCs*|j|||}|dk r&|jjjj|dS)N)rrDrr;r~)r rrrrr r r _swdb_group_installsz%TransactionReplay._swdb_group_installcCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)NzGroup id '%s' is not installed.) rDrr;r\rarFrrupgrade)r rrrrr r r _swdb_group_upgrades z%TransactionReplay._swdb_group_upgradecCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)NzGroup id '%s' is not installed.) rDrr;r\rarFrr downgrade)r rrrrr r r _swdb_group_downgrades z'TransactionReplay._swdb_group_downgradecCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)NzGroup id '%s' is not installed.) rDrr;r\rarFrrremove)r rrrrr r r _swdb_group_removes z$TransactionReplay._swdb_group_removec Csd|jjj|}|s,|j|jtd|dS|jjjj||j |j |}yx|D]}|d}|j |t dd|d}|j |t dd|d} |j | t d dytjj| } Wn2tjjk r} ztt | WYdd} ~ XnX| tjjtjjfkr ttd j|dd |j||| qNWWn>tk r^} z ttd j| jd dWYdd} ~ XnX|S)Nz%Environment id '%s' is not available.r*zenvironments.groups.idrer.zenvironments.groups.installedrr1zenvironments.groups.group_typezlInvalid value "{group_type}" of environments.groups.group_type, only "mandatory" or "optional" is supported.)r1z2Missing object key "{key}" in environments.groups.r)rd)rDrZ_environment_by_idrarHrrr>rr-rr^rrr7r8rrrrZCompsPackageType_MANDATORYZCompsPackageType_OPTIONALrZaddGrouprtru) r env_idrr0Z comps_envswdb_envr@r*r.r1r$r r r _create_swdb_environments8 *z*TransactionReplay._create_swdb_environmentcCs*|j|||}|dk r&|jjjj|dS)N)rrDrr>r~)r rrr0rr r r _swdb_environment_installsz+TransactionReplay._swdb_environment_installcCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)Nz%Environment id '%s' is not installed.) rDrr>r\rarFrrr)r rrr0rr r r _swdb_environment_upgrades z+TransactionReplay._swdb_environment_upgradecCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)Nz%Environment id '%s' is not installed.) rDrr>r\rarFrrr)r rrr0rr r r _swdb_environment_downgrades z-TransactionReplay._swdb_environment_downgradecCsT|jjjj|s*|j|jtd|dS|j|||}|dk rP|jjjj|dS)Nz%Environment id '%s' is not installed.) rDrr>r\rarFrrr)r rrr0rr r r _swdb_environment_removes z*TransactionReplay._swdb_environment_removecCs|jS)z> :returns: the loaded data of the transaction )rZ)r r r r get_dataszTransactionReplay.get_datacCs|jS)zW :returns: an array of warnings gathered during the transaction replay )rN)r r r r get_warnings szTransactionReplay.get_warningsc Cs|j}g}xJ|jD]@}y|j|Wqtk rP}z|j|WYdd}~XqXqWx|jD]}y |d}|d}ytjj|d}Wn:tj j k r}z|jtt |w`WYdd}~XnX|dkr|j |||dn|dkr|j |||dnl|dks|d kr,|j|||dnD|d ks@|d krT|j|||dn|jttd j||d Wq`tk r}z&|jttdj|jddWYdd}~Xq`tk r}z|j|WYdd}~Xq`Xq`Wx|jD]} y| d}| d} ytjj| d}Wn>tj j k r^}z|jtt |wWYdd}~XnX|dkr~|j| || dn|dkr|j| || dnl|dks|d kr|j| || dnD|d ks|d kr|j| || dn|jttdj|| dWnptk rN}z&|jttdj|jddWYdd}~Xn.tk rz}z|j|WYdd}~XnXqW|rt||dS)z* Replays the transaction. Nr&r*r,rjr+rnrkrprlrqz@Unexpected value of group action "{action}" for group "{group}".)r&r;z&Missing object key "{key}" in a group.r)rdr0zJUnexpected value of environment action "{action}" for environment "{env}".)r&r>z-Missing object key "{key}" in an environment.)rEr]rrr6r_r7r8rrrrrrrrrrrtrur`rrrrr) r rWrrr$r<r&rrr?rr r r runsv   *   *"zTransactionReplay.runcCs8|jjs dSg}x|jjD]}y |j}Wn$tk rP}zwWYdd}~XnXt|}||jkr|j s|jtjj tjj tjj fkrt dj |d}|js|jt|n |jj|y>|j|}|jtjjtjjfkstjj||jdkr||_Wqtk r}zWYdd}~XqXqW|r4t|j|dS)z Sets reasons in the transaction history to values from the stored transaction. Also serves to check whether additional packages were pulled in by the transaction, which results in an error (unless ignore_extras is True). NzgPackage nevra "{nevra}", which is not present in the transaction file, was pulled into the transaction.)r'r)rDr8r=rtrrLrFr&r7ZTransactionItemAction_UPGRADEDZ TransactionItemAction_DOWNGRADEDZ!TransactionItemAction_REINSTALLEDrrrGr6rrNrMZTransactionItemAction_INSTALLZTransactionItemAction_REMOVEZTransactionItemReasonComparer(rrE)r rr:r=r$r'r Z replay_reasonr r r post_transactionds<        z"TransactionReplay.post_transaction)rCNFFF)rrr__doc__rrOrPrar^r[rrrrrrrrrrrrrrrr r r r rBs4    a   (   SrB)Z __future__rrrr7rwZdnf.i18nrZdnf.exceptionsr}rTr"Z VERSION_MINORr4 exceptionsrrrrr%rAobjectrBr r r r s     K