Your IP : 18.227.105.110


Current Path : /usr/lib/python3.6/site-packages/dnf/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/dnf/__pycache__/transaction_sr.cpython-36.pyc

3

��faf�@s�ddlmZddlmZddlmZddlZddlZddlmZddlZ	ddl
Z
dZdZdeefZ
Gdd�de	jj�ZGd	d
�d
e	jj�ZGdd�de�Zd
d�Zdd�ZGdd�de�ZdS)�)�absolute_import)�print_function)�unicode_literalsN)�_z%s.%scseZdZ�fdd�Z�ZS)�TransactionErrorcstt|�j|�dS)N)�superr�__init__)�self�msg)�	__class__��$/usr/lib/python3.6/transaction_sr.pyr/szTransactionError.__init__)�__name__�
__module__�__qualname__r�
__classcell__rr)rr
r.srcseZdZ�fdd�Z�ZS)�TransactionReplayErrorcsv||_t|ttf�r||_n|g|_|r:td�j|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}":)�filenamez<The following problems occurred while running a transaction:z
  N)r�
isinstance�list�tuple�errorsr�format�strrrr)r	rrr
�error)rrr
r4szTransactionReplayError.__init__)rrrrrrr)rr
r3srcseZdZ�fdd�Z�ZS)�#IncompatibleTransactionVersionErrorcstt|�j||�dS)N)rrr)r	rr
)rrr
rMsz,IncompatibleTransactionVersionError.__init__)rrrrrrr)rr
rLsrc"Cs�|jd�\}}yt|�}Wn8tk
rR}zt|td�j|d���WYdd}~XnXyt|�Wn8tk
r�}zt|td�j|d���WYdd}~XnX|tkr�t|td�j|td���dS)N�.z1Invalid major version "{major}", number expected.)�majorz1Invalid minor version "{minor}", number expected.)�minorzPIncompatible major version "{major}", supported major version is "{major_supp}".)rZ
major_supp)�split�int�
ValueErrorrrr�
VERSION_MAJORr)�versionrrr�errr
�_check_versionQs$$$r%cCs�dti}g}g}g}|dkr |S�x0|j�D�]"}|j�r`|j|j|jtjj|j	�|j
d��q,|j�r�|j�}|j|j
�gtjj|j��d�}x:|j�D].}|dj|j�|j�tjj|j��d��q�W|j|�q,|j�r,|j�}	|j|	j�gtjj|	j��d�}
x<|	j�D]0}|
dj|j
�|j�tjj|j��d	���qW|j|
�q,W|�rb||d
<|�rp||d<|�r~||d<|S)z�
    Serializes a transaction to a data structure that is equivalent to the stored JSON format.
    :param transaction: the transaction to serialize (an instance of dnf.db.history.TransactionWrapper)
    r#N)�action�nevra�reason�repo_id)r&�id�packages�
package_typesr+)�name�	installed�package_type)r&r*�groupsr,r0)r*r.�
group_type�rpms�environments)�VERSIONr+�
is_package�appendZaction_namer'�libdnf�transactionZTransactionItemReasonToStringr(Z	from_repoZis_groupZ	get_groupZ
getGroupIdZcompsPackageTypeToStringZgetPackageTypesZgetPackagesZgetNameZgetInstalledZgetPackageTypeZis_environmentZget_environmentZgetEnvironmentIdZ	getGroupsZgetGroupType)r8�datar2r0r3�tsi�group�
group_data�pkg�env�env_data�grprrr
�serialize_transactionlsXrAc@s�eZdZdZd/dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZdS)0�TransactionReplaya�
    A class that encapsulates replaying a transaction. The transaction data are
    loaded and stored when the class is initialized. The transaction is run by
    calling the `run()` method, after the transaction is created (but before it is
    performed), the `post_transaction()` method needs to be called to verify no
    extra packages were pulled in and also to fix the reasons.
    �NFcCsv||_||_||_||_||_|jjjs.d|_t�|_i|_	g|_
|rX|rXttd���n|rh|j
|�n
|j|�dS)a
        :param base: the dnf base
        :param filename: the filename to load the transaction from (conflicts with the 'data' argument)
        :param data: the dictionary to load the transaction from (conflicts with the 'filename' argument)
        :param ignore_extras: whether to ignore extra package pulled into the transaction
        :param ignore_installed: whether to ignore installed versions of packages
        :param skip_unavailable: whether to skip transaction packages that aren't available
        TzKConflicting TransactionReplay arguments have been specified: filename, dataN)�_base�	_filename�_ignore_installed�_ignore_extras�_skip_unavailable�conf�strict�set�_nevra_cache�_nevra_reason_cache�	_warningsr!r�_load_from_file�_load_from_data)r	�baserr9Z
ignore_extrasZignore_installedZskip_unavailablerrr
r�s
zTransactionReplay.__init__c%Cs�||_t|d��N}ytj|�}Wn8tjjk
rX}zt|t|�d��WYdd}~XnXWdQRXy|j|�Wn,t	k
r�}zt||��WYdd}~XnXdS)N�rr)
rE�open�json�load�decoderZJSONDecodeErrorrrrPr)r	�fn�f�replay_datar$rrr
rO�s.z!TransactionReplay._load_from_filecCs|||_|j|j�|jjdg�|_|j|jtdd�|jjdg�|_|j|jtdd�|jjdg�|_|j|jtdd�dS)Nr2Zarrayr0r3)�_replay_data�_verify_toplevel_json�get�_rpms�_assert_typer�_groups�
_environments)r	r9rrr
rP�sz!TransactionReplay._load_from_datacCs|r|jj|�nt|��dS)N)rNr6r)r	Z	warn_onlyr
rrr
�_raise_or_warnsz TransactionReplay._raise_or_warncCs$t||�s ttd�j||d���dS)Nz*Unexpected type of "{id}", {exp} expected.)r*Zexp)rrrr)r	�value�tr*Zexpectedrrr
r^s
zTransactionReplay._assert_typecCsJ|j}d|kr$t|tdjdd����|j|dtdd�t|d|�dS)Nr#zMissing key "{key}".)�key�string)rErrrr^rr%)r	rYrWrrr
r[s
z'TransactionReplay._verify_toplevel_jsoncCsDy,|d}|d}|d}tjj|d�}Wnvtk
rh}z ttd�j|jdd���WYdd}~Xn<tk
r�}z ttd�j|d|d	���WYdd}~XnXt	j
|�}|jt	jgd
�}t
|�dkr�ttd�j|d
���|d}	d|	j|	jf}
|jjj�j|	j|	jd�}|	jdk	�r"|	jnd}|j||	j|	jd�}
|�r`|
j|d�}|�r`|j|
j��}
|
�s�|j|jtd�j|d
��dS|dk�r�|jj|�|d(k�r�||j|<|d)k�r.|dk�r�|j��r�|jj|��r�|j|jtd�j|
|d��t j!j"|jj�j#|
d�}|jj$j%||jj&j'd��n|dk�r�|
j(�}
|
�sf|j|jtd�j||d��dSt j!j"|jj�j#|
d�}|jj$j%||jj&j'd�n�|d*k�r
|
j�}
|
�s�|j|jtd#�j||d��dS|j�s�|dk�r@xX|
D]}|jj$j)|d$d%��q�Wn6|dk�r*|jj*j+|
d|�nttd&�j||d'���dS)+Nr&r'r)r(z%Missing object key "{key}" in an rpm.r)rdzFUnexpected value of package reason "{reason}" for rpm nevra "{nevra}".)r(r')Zforms�z)Cannot parse NEVRA for package "{nevra}".)r'z%s.%s)r-�arch)�epochr#�release)Zreponamez Cannot find rpm nevra "{nevra}".z
Reason Change�Install�Upgrade�	Downgrade�	Reinstall�Removedz:Package "{na}" is already installed for action "{action}".)�nar&)r=)ZselectZoptionalzLPackage nevra "{nevra}" not available in repositories for action "{action}".)r'r&�Upgraded�
Downgraded�Reinstalled�	Obsoletedz<Package nevra "{nevra}" not installed for action "{action}".F)Z
clean_depszFUnexpected value of package action "{action}" for rpm nevra "{nevra}".)r&r')rjrkrlrmrn)rjrkrl)rprqrrrnrs),r7r8ZStringToTransactionItemReason�KeyErrorrrr�args�
IndexError�hawkeyZSubjectZget_nevra_possibilitiesZ
FORM_NEVRA�lenr-rgrDZsack�query�filterrhr#ri�unionr.rarHrL�addrMZ_get_installonly_queryrF�dnfZselectorZSelectorrKZgoal�installrIrJZ	availableZerase�historyZ
set_reason)r	�pkg_datar&r'r)r(r$ZsubjZ
parsed_nevrasZparsed_nevraroZquery_narhryZ
query_repoZsltrr=rrr
�_replay_pkg_actionsz("





$



z$TransactionReplay._replay_pkg_actioncCs2|jjj|�}|s,|j|jtd�|�dS|jjjj||j	|j
|�}y�x�|D]�}|d}|j|tdd�|d}|j|t
dd�|d}	|j|	td	d�y|j||tjj|	��WqNtjjk
r�}
ztt|
���WYdd}
~
XqNXqNWWn>tk
�r,}
z ttd
�j|
jdd���WYdd}
~
XnX|S)
NzGroup id '%s' is not available.r-zgroups.packages.namerer.zgroups.packages.installed�booleanr/zgroups.packages.package_typez.Missing object key "{key}" in groups.packages.r)rd)rD�compsZ_group_by_idrarHrrr;�newr-�ui_namer^r�boolZ
addPackager7r8�stringToCompsPackageTyper�Errorrrtrru)r	�group_id�	pkg_types�pkgsZcomps_group�
swdb_groupr=r-r.r/r$rrr
�_create_swdb_groupvs*
&*z$TransactionReplay._create_swdb_groupcCs*|j|||�}|dk	r&|jjjj|�dS)N)r�rDrr;r~)r	r�r�r�r�rrr
�_swdb_group_install�sz%TransactionReplay._swdb_group_installcCsT|jjjj|�s*|j|jtd�|�dS|j|||�}|dk	rP|jjjj|�dS)NzGroup id '%s' is not installed.)	rDrr;r\rarFrr��upgrade)r	r�r�r�r�rrr
�_swdb_group_upgrade�s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	r�r�r�r�rrr
�_swdb_group_downgrade�sz'TransactionReplay._swdb_group_downgradecCsT|jjjj|�s*|j|jtd�|�dS|j|||�}|dk	rP|jjjj|�dS)NzGroup id '%s' is not installed.)	rDrr;r\rarFrr��remove)r	r�r�r�r�rrr
�_swdb_group_remove�sz$TransactionReplay._swdb_group_removecCsd|jjj|�}|s,|j|jtd�|�dS|jjjj||j	|j
|�}y�x�|D]�}|d}|j|tdd�|d}|j|t
dd�|d}	|j|	td	d�ytjj|	�}	Wn2tjjk
r�}
ztt|
���WYdd}
~
XnX|	tjjtjjfk�rttd
�j|dd���|j|||	�qNWWn>tk
�r^}
z ttd�j|
jd
d���WYdd}
~
XnX|S)Nz%Environment id '%s' is not available.r*zenvironments.groups.idrer.zenvironments.groups.installedr�r1zenvironments.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)rDr�Z_environment_by_idrarHrrr>r�r-r�r^rr�r7r8r�rr�rZCompsPackageType_MANDATORYZCompsPackageType_OPTIONALrZaddGrouprtru)r	�env_idr�r0Z	comps_env�swdb_envr@r*r.r1r$rrr
�_create_swdb_environment�s8
*z*TransactionReplay._create_swdb_environmentcCs*|j|||�}|dk	r&|jjjj|�dS)N)r�rDrr>r~)r	r�r�r0r�rrr
�_swdb_environment_install�sz+TransactionReplay._swdb_environment_installcCsT|jjjj|�s*|j|jtd�|�dS|j|||�}|dk	rP|jjjj|�dS)Nz%Environment id '%s' is not installed.)	rDrr>r\rarFrr�r�)r	r�r�r0r�rrr
�_swdb_environment_upgrade�sz+TransactionReplay._swdb_environment_upgradecCsT|jjjj|�s*|j|jtd�|�dS|j|||�}|dk	rP|jjjj|�dS)Nz%Environment id '%s' is not installed.)	rDrr>r\rarFrr�r�)r	r�r�r0r�rrr
�_swdb_environment_downgrade�sz-TransactionReplay._swdb_environment_downgradecCsT|jjjj|�s*|j|jtd�|�dS|j|||�}|dk	rP|jjjj|�dS)Nz%Environment id '%s' is not installed.)	rDrr>r\rarFrr�r�)r	r�r�r0r�rrr
�_swdb_environment_remove�s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_warningscCs�|j}g}xJ|jD]@}y|j|�Wqtk
rP}z|j|�WYdd}~XqXqW�x�|jD�]�}�y
|d}|d}ytjj|d�}Wn:tj	j
k
r�}z|jtt|���w`WYdd}~XnX|dkr�|j|||d�n�|dk�r|j
|||d�nl|dk�s|d	k�r,|j|||d�nD|d
k�s@|dk�rT|j|||d�n|jttd�j||d
���Wq`tk
�r�}z&|jttd�j|jdd���WYdd}~Xq`tk
�r�}z|j|�WYdd}~Xq`Xq`W�x�|jD�]�}	�y|	d}|	d}
ytjj|	d�}Wn>tj	j
k
�r^}z|jtt|����w�WYdd}~XnX|dk�r~|j|
||	d�n�|dk�r�|j|
||	d�nl|dk�s�|d	k�r�|j|
||	d�nD|d
k�s�|dk�r�|j|
||	d�n|jttd�j||
d���Wnptk
�rN}z&|jttd�j|jdd���WYdd}~Xn.tk
�rz}z|j|�WYdd}~XnX�q�W|�r�t||��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]r�rr6r_r7r8r�rr�rr�r�r�r�rrrtrur`r�r�r�r�r)r	rWrr�r$r<r&r�r�r?r�rrr
�runsv 
* 

*"zTransactionReplay.runcCs8|jjsdSg}�x|jjD�]}y
|j}Wn$tk
rP}zwWYdd}~XnXt|�}||jkr�|js�|jtjj	tjj
tjjfkr�td�j
|d�}|js�|jt|��n|jj|�y>|j|}|jtjjtjjfks�tjj||j�dkr�||_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[r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rB�s4
 


a


(


SrB)Z
__future__rrrr7rwZdnf.i18nrZdnf.exceptionsr}rTr"Z
VERSION_MINORr4�
exceptionsr�rrrr%rA�objectrBrrrr
�<module>s K

?>