ok

Mini Shell

Direktori : /lib/python3.6/site-packages/dnf/cli/commands/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dnf/cli/commands/__pycache__/history.cpython-36.pyc

3

��f%F�@s�ddlmZddlmZddlmZddlZddlZddlmZmZddl	m
Z
ddlmZm
Z
ddl	ZddlZddlZddlZddlZddlZddlZejd�ZGd	d
�d
e
j�ZdS)�)�absolute_import)�print_function)�unicode_literalsN)�_�ucd)�commands)�TransactionReplay�serialize_transaction�dnfcs�eZdZdZd+Zed�Zddddd	d
ddgZ�fd
d�Ze	dd��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Z�ZS),�HistoryCommandzUA class containing methods needed by the cli to execute the
    history command.
    �history�histz(display, or use, the transaction history�list�info�redo�replay�rollback�store�undo�
userinstalledcstt|�j||�d|_dS)NF)�superr�__init__�_require_one_transaction_id)�self�args�kw)�	__class__��/usr/lib/python3.6/history.pyr4szHistoryCommand.__init__c
Cs�|jddddjtjddjtjdd���d�|jd	d
dd�|jd
ddtd�d�|jdd
td�d�|jdd
td�d�|jdd
td�d�|jddddd�|jddddd�dS)N�transactions_action�?ZCOMMANDz$Available commands: {} (default), {}rz, �)�nargs�metavar�helpz	--reverse�
store_truez$display history list output reversed)�actionr$z-oz--outputz<For the store command, file path to store the transaction to)�defaultr$z--ignore-installedzXFor the replay command, don't check for installed packages matching those in transactionz--ignore-extraszRFor the replay command, don't check for extra packages pulled into the transactionz--skip-unavailablezYFor the replay command, skip packages that are not available or have missing dependencies�transactions�*ZTRANSACTIONz�For commands working with history transactions, Transaction ID (<number>, 'last' or 'last-<number>' for one transaction, <transaction-id>..<transaction-id> for a range)�transaction_filenameZTRANSACTION_FILEzEFor the replay command, path to the stored transaction file to replay)�add_argument�formatr�_CMDS�joinr)�parserrrr�
set_argparser9s$



zHistoryCommand.set_argparsercCs.|jjs|jd|j_n0|jj|jkrH|jjjd|jj�|jd|j_td�j|jj�|_|jj	}|jjdk�r|jjs�t
jjtd���t|jj�dkr�t
jjtd���t
jj|jjd�|j_g|j_d|_d|_d|_d|jj_d|jj_t
jjj|j|j�n�|jjd	k�r6d|_|jj�s�t
jjtd
���n�|jjdk�r�d|_d|_d|_d|_|jj�s�td
�}tj|�t
jj|��n,t|jj�dk�r�tj|j�t
jj|j��d|_t
jjj|j|j�nd|_d|_|jjjdk�r*t
j |jjjt
j!��r*td|jjj�}tj|�t
jj|��dS)NrzUFound more than one transaction ID.
'{}' requires one transaction ID or package name.rzNo transaction file name given.r!z6More than one argument given as transaction file name.TFrz(No transaction ID or package name given.rrrz:memory:z+You don't have access to the history DB: %s)rrr)"�optsrr-r(�insertrr,�_require_one_transaction_id_msg�cli�demandsr
�CliError�len�os�path�abspathr*Zavailable_reposZ	resolvingZ	root_user�base�confZclean_requirements_on_removeZinstall_weak_depsrZ_checkGPGKeyr�logger�criticalZfresh_metadataZsack_activationr�access�R_OK)rr5�msgrrr�	configureUsZ




(
zHistoryCommand.configurecCs�t|tjj�rv|jjdkr2|jj\}td�|fS|jjdkrv|jjddkrV|jjn|jjdd�\}td�|fStjj	j
j||�S)	z.Get suggestions for resolving the given error.rzVCannot undo transaction %s, doing so would result in an inconsistent package database.rr�forcer!NzZCannot rollback transaction %s, doing so would result in an inconsistent package database.)�
isinstancer
�
exceptionsZTransactionCheckErrorr1rr(rr4r�Command�get_error_output)r�errorZid_rrrrG�s
zHistoryCommand.get_error_outputcCs:|j|�}t|�}t|j|dd|jjd�|_|jj�dS)NT)�data�ignore_installed�
ignore_extras�skip_unavailable)�_history_get_transactionr	rr;r1rLr�run)r�extcmds�oldrIrrr�
_hcmd_redo�s
zHistoryCommand._hcmd_redocCsD|stjjtd���|jjj|�}|s@tjjtd�j|d���|S)NzNo transaction ID givenzTransaction ID "{0}" not found.r)r
r4r6rr;rrPr,)rrOrPrrr�_history_get_transactions�sz(HistoryCommand._history_get_transactionscCs.|j|�}t|�dkr&tjjtd���|dS)Nr!z#Found more than one transaction ID!r)rRr7r
r4r6r)rrOrPrrrrM�s
z'HistoryCommand._history_get_transactioncCs|j|�}|j|�dS)N)rM�_revert_transaction)rrOrPrrr�
_hcmd_undo�s
zHistoryCommand._hcmd_undocCs�|j|�}|jjj�}d}|j|jkr�x�|jjjtt|jd|jd���D]X}|jrjt	j
td�|j�n|jr�t	j
td�|j�|dkr�t
jjj|�}qL|j|�qLW|j|�dS)Nr!z-Transaction history is incomplete, before %u.z,Transaction history is incomplete, after %u.)rMr;r�last�tidrPr�rangeZaltered_lt_rpmdbr=ZwarningrZaltered_gt_rpmdbr
ZdbZMergedTransactionWrapper�mergerS)rrOrPrUZmerged_trans�transrrr�_hcmd_rollback�s
*zHistoryCommand._hcmd_rollbackc	Cs&dddddddddd	d
d�}t|�}x�dD]�}x�|j|g�D]�}||d|d<|ddkrt|jdd�dkrtd|d<|dd
kr�d|kr�tj|d�}|jtjgd�d}|jjjj	|j
|j|j�dd�}t
jj|�|d<|jd�tjkr<d|d<q<Wq*Wt|j|dd|jjd�|_|jj�dS)N�Removed�Install�
Downgraded�	Downgrade�Upgraded�Upgrade�	Reinstall�Reinstalled�	Obsoletedz
Reason Change)r\r[r`r_r^r]rbrarcZObsoletez
Reason Change�rpms�groups�environmentsr&�reasonZcleanZ
dependency�nevra)Zformsrr!Zrepo_idT)rIrJrKrL)rdrerf)r	�get�hawkeyZSubjectZget_nevra_possibilitiesZ
FORM_NEVRA�outputrZswdbZresolveRPMTransactionItemReason�nameZarch�tids�libdnfZtransactionZTransactionItemReasonToStringZSYSTEM_REPO_NAMErr;r1rLrrN)	rrYZ
action_maprIZcontent_typeZtiZsubjrhrgrrrrS�sD

z"HistoryCommand._revert_transactioncCs:t|jj��}|jj|dd�}|dkr6tjjtd���dS)z&Execute history userinstalled command.zPackages installed by userrhrzNo packages to listN)	�tupler;Ziter_userinstalledrkZlistPkgsr
r4r6r)rZpkgsZn_listedrrr�_hcmd_userinstalledsz"HistoryCommand._hcmd_userinstalledc
s��fdd�}t�}t�}�xĈjjD�]�}d|k�r\y|jdd�\}}Wn0tk
rxtjtd�j|��t	j
j�YnXtd�}y||�}Wn0tk
r�tjt|�j|��t	j
j�YnXy||�}Wn0tk
r�tjt|�j|��t	j
j�YnX�j�r$||k�r$tj�j
�t	j
j�||k�r8||}}|j||f�|jt||d��q$y|j||��Wq$tk
�r��jjj|g�}|�r�|j|�n4td�j|�}	�j�r�tj|	�t	j
j�n
tj|	�Yq$Xq$Wt|d	d
�|fS)z0Convert commandline arguments to transaction idscsJ|dkrd}n|jd�r$|dd�}t|�}|dkrF|�jjj�j7}|S)NrU�0zlast-�r)�
startswith�intrkrrUrV)�sZtransaction_id)rrr�str2transaction_ids
z@HistoryCommand._args2transaction_ids.<locals>.str2transaction_idz..�zWInvalid transaction ID range definition '{}'.
Use '<transaction-id>..<transaction-id>'.zNCan't convert '{}' to transaction ID.
Use '<number>', 'last', 'last-<number>'.r!z8No transaction which manipulates package '{}' was found.T)�reverse)�setr1r(�split�
ValueErrorr=r>rr,r
r4r6rr3�add�updaterWrkr�searchr�sorted)
rrvrm�merged_tids�tZbegin_transaction_idZend_transaction_idZcant_convert_msgZtransact_ids_from_pkgnamerAr)rr�_args2transaction_ids
sV





z$HistoryCommand._args2transaction_idsc
Cs@|jj}|dkrDt|j|jj|jj|jj|jjd�|_|jj	��n�|j
�\}}|dkr~|sf|jjr~|jj
||jjd��n�|dkr�|s�|jjr�|jj||jj|��n�|dkr�|j|��nz|dkr�|j|��nd|dkr�|j|��nN|d	k�r|j��n8|d
k�r<|j|�}t|�}y�|jjdk	�r8|jjnd}|jjj�sV|jjj�r�tjj|��r�td�j|�}|jjj�s�|jjjd
j|�dj|�d��r�ttd�j|��dSt |d��"}t!j"||ddd�|j#d�WdQRXttd�j|��Wn>t$k
�r:}	z t%j&j'td�jt(|	����WYdd}	~	XnXdS)Nr)�filenamerJrKrLr)rxrrrrrrztransaction.jsonz{} exists, overwrite?z
{} [y/N]: z
{} [Y/n]: )rAZdefaultyes_msgzNot overwriting {}, exiting.�wrrT)�indentZ	sort_keys�
zTransaction saved to {}.zError storing transaction: {}))r1rrr;r*rJrKrLrrNr�r(rkZhistoryListCmdrxZhistoryInfoCmdrTrQrZrprMr	r<ZassumenoZ	assumeyesr8r9�isfilerr,Zuserconfirm�print�open�json�dump�write�OSErrorr
r4r6�str)
rZvcmdrmr�rVrIr�rA�f�errrrNMsN


(zHistoryCommand.runcCs|jjdkrdS|jj�dS)Nrrrr)rrrr)r1rrZpost_transaction)rrrr�run_resolvedszHistoryCommand.run_resolvedcCsX|jjdkrdS|jj�}|rTtjtjjt	d��x |D]}tjtjjd|�q8WdS)NrrrrzEWarning, the following problems occurred while running a transaction:z  )rrrr)
r1rrZget_warningsr=�logr
�loggingZWARNINGr)r�warningsr�rrr�run_transaction�s


zHistoryCommand.run_transaction)rr
)�__name__�
__module__�__qualname__�__doc__�aliasesrZsummaryr-r�staticmethodr0rBrGrQrRrMrTrZrSrpr�rNr�r��
__classcell__rr)rrr*s&=	0@2r)Z
__future__rrrrnrjZdnf.i18nrrZdnf.clirZdnf.transaction_srrr	r
Zdnf.exceptionsZdnf.transactionZdnf.utilr�r�r8Z	getLoggerr=rFrrrrr�<module>s 


Zerion Mini Shell 1.0