Your IP : 3.145.92.213


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

3

�ft`2J�@s�dZddlmZddlmZddlmZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
mZdd	lmZd
d�ZGdd
�d
e	j�ZdS)zUpdateInfo CLI command.�)�absolute_import)�print_function)�unicode_literalsN)�commands)�OptionParser)�_�exact_width)�unicodecCstdd�|D��S)z7Return maximum length of items in a non-empty iterable.css|]}t|�VqdS)N)r)�.0�item�r� /usr/lib/python3.6/updateinfo.py�	<genexpr>&sz_maxlen.<locals>.<genexpr>)�max)�iterablerrr
�_maxlen$srcs.eZdZdZejed�ejed�ejed�ej	ed�ej
ed�iZed�ed�ed	�ed
�d�Zdddd
d
d
dd�Z
dgee
j��Zed�ZdZdddegZ�fdd�Zedd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$�Z%S)6�UpdateInfoCommandz)Implementation of the UpdateInfo command.�bugfix�enhancement�security�unknown�
newpackagez
Critical/Sec.zImportant/Sec.z
Moderate/Sec.zLow/Sec.)�Critical�	Important�Moderate�Low�list�info�summary)zlist-updateinfoz
list-securityzlist-seczinfo-updateinfoz
info-securityzinfo-seczsummary-updateinfoZ
updateinfoz!display advisories about packages�	available�	installed�updates�allcstt|�j|�d|_dS)zInitialize the command.N)�superr�__init__�_installed_query)�self�cli)�	__class__rr
r$CszUpdateInfoCommand.__init__c	Cs|j�}|jddddtd�d�|jddddtd	�d�|jd
dddtd�d�|jd
dddtd�d�dddg}|j�}|jddddtd�d�|jddddtd�d�|jddddtd�d�|jddddtd�d�|jd d!ddtd"�d�|jd#d$d%||d&tjtd'�d(�dS))Nz--available�
_availabilityr�store_constz?advisories about newer versions of installed packages (default))�dest�const�action�helpz--installedr z?advisories about equal and older versions of installed packagesz	--updatesr!zbadvisories about newer versions of those installed packages for which a newer version is availablez--allr"z3advisories about any versions of installed packagesrrrz	--summary�_spec_actionz$show summary of advisories (default)z--listzshow list of advisoriesz--infozshow info of advisoriesz
--with-cve�with_cveF�
store_truez'show only advisories with CVE reference)r+�defaultr-r.z	--with-bz�with_bzz,show only advisories with bugzilla reference�spec�*ZSPECrzPackage specification)�nargs�metavar�choicesr2r-r.)Zadd_mutually_exclusive_group�add_argumentrrZPkgNarrowCallback)�parser�availabilityZcmdsZ
output_formatrrr
�
set_argparserHsD






zUpdateInfoCommand.set_argparsercCs�d|jj_d|jj_|jj|jkr6|j|jj|j_n|jjrJ|jj|j_|jj	r`|jj	|j_
n:|jjs||jjd|jkr�|j
|j_
n|jjjd�|j_
t�|j_|jjr�|jjjtj�|jjr�|jjjtj�|jjr�|jjjtj�|jj�r|jjjtj�|jj�r�|jjjd�}|dk�r:|jjjtj�n�|dk�rV|jjjtj�np|dk�rr|jjjtj�nT|dk�r�|jjjtj�n8|d
k�r�d|j_n$|d
k�r�d|j_n|jjjd|�|jj�r�|jjj|jj�dS)zADo any command-specific configuration based on command arguments.Trrrr�secr�	bugzillas�bzs�cvesN)rr=)r>r?) r'ZdemandsZavailable_reposZsack_activation�optsZcommand�direct_commands�spec_actionr/r)r;r4�availabilities�availability_default�pop�set�_advisory_typesr�add�hawkey�ADVISORY_BUGFIXr�ADVISORY_ENHANCEMENTr�ADVISORY_NEWPACKAGEr�ADVISORY_SECURITYr3r0�insert�advisory�extend)r&r4rrr
�	configurensJ













zUpdateInfoCommand.configurecCs�|jjdkr$|j|jj�}td�}n^|jjdkrH|j|jj�}td�}n:|jjdkrl|j|jj�}td�}n|j|jj�}td�}|jjdkr�|j	|�n$|jjdkr�|j
|�n|j||�dS)z#Execute the command with arguments.r r!r"rrrN)rAr;�installed_apkg_adv_instsr4r�updating_apkg_adv_insts�all_apkg_adv_insts�available_apkg_adv_instsrC�display_list�display_info�display_summary)r&�apkg_adv_insts�descriptionrrr
�run�s 


zUpdateInfoCommand.runcCs@|jdkr |jjj�j�j�|_|jj|j|jd�}t	|�dkS)N)�nameZevr__gter)
r%�base�sack�queryr Zapply�filterr]�evr�len)r&�apackage�qrrr
�_newer_equal_installed�s
z(UpdateInfoCommand._newer_equal_installedcs,|jjrJ|jjrJ|jjrJ|jjrJ|jjrJ|jjrJ|jjrJdS�j|jjkr\dSt	�fdd�|jjD��rzdS|jjr��j|jjkr�dS|jjr�t	�fdd�|jjD��r�dS|jjr�t	�fdd�|jjD��r�dS|jj�rt	dd��j
D���rdS|jj�r(t	dd��j
D���r(dSd	S)
NTc3s|]}tj�j|�VqdS)N)�fnmatch�fnmatchcase�id)r
�pat)rPrr
r�sz6UpdateInfoCommand._advisory_matcher.<locals>.<genexpr>csg|]}�j|��qSr)Z	match_bug)r
Zbug)rPrr
�
<listcomp>�sz7UpdateInfoCommand._advisory_matcher.<locals>.<listcomp>csg|]}�j|��qSr)Z	match_cve)r
Zcve)rPrr
rk�scSsg|]}|jtjk�qSr)�typerJ�
REFERENCE_CVE)r
�refrrr
rk�scSsg|]}|jtjk�qSr)rlrJ�REFERENCE_BUGZILLA)r
rnrrr
rk�sF)rArHr4�severityZbugzillar@r0r3rl�any�
references)r&rPr)rPr
�_advisory_matcher�s2






""

z#UpdateInfoCommand._advisory_matcherc#shxb|j|�D]T��j|jj�}|j|�}t�fdd�|jjD��}|sJ|r|j��}�||fVqWdS)z4Return (adv. package, advisory, installed) triplets.c3s|]}tj�j|�VqdS)N)rgrhr])r
rj)rdrr
r�szAUpdateInfoCommand._apackage_advisory_installed.<locals>.<genexpr>N)	Zget_advisory_pkgsZget_advisoryr^r_rsrqrAr4rf)r&Z
pkgs_queryZcmptype�specsrPZadvisory_matchZapackage_matchr r)rdr
�_apackage_advisory_installed�s

z.UpdateInfoCommand._apackage_advisory_installedcCs@|jj}|j�jdd�}|j�}|r<|j|j�j|jd��}|S)z<Return query containing packages of currently running kernelT)�empty)�	sourcerpm)r^r_r`�filtermZget_running_kernel�unionrw)r&r_reZkernelrrr
�running_kernel_pkgs�sz%UpdateInfoCommand.running_kernel_pkgscCs8|jjj�j�jd�}|j|j�j��}|j|tj	|�S)z5Return available (adv. package, adv., inst.) triplets�)
r^r_r`r ZlatestryrzrurJ�GT)r&rtrerrr
rV�sz*UpdateInfoCommand.available_apkg_adv_instscCs"|j|jjj�j�tjtjB|�S)z5Return installed (adv. package, adv., inst.) triplets)rur^r_r`r rJ�LT�EQ)r&rtrrr
rS�sz*UpdateInfoCommand.installed_apkg_adv_instscCs |j|jjj�jdd�tj|�S)z4Return updating (adv. package, adv., inst.) tripletsT)Z
upgradable)rur^r_r`rxrJr|)r&rtrrr
rT�sz)UpdateInfoCommand.updating_apkg_adv_instscCs(|j|jjj�j�tjtjBtjB|�S)z5Return installed (adv. package, adv., inst.) triplets)	rur^r_r`r rJr}r~r|)r&rtrrr
rUsz$UpdateInfoCommand.all_apkg_adv_instscCsVi}xB|D]:\}}}|j||j<|jtjkr
|j|jf||j|jf<q
Wtj|j��S)zMake the summary of advisories.)rlrirJrNrp�collections�Counter�values)r&rZ�id2type�apkgrPr rrr
�_summaryszUpdateInfoCommand._summaryc	
CsV|j|�}|�r<ttd�|�dtd�|tjfdtd�|tjfdtd�|tjdffdtd�|tjd	ffdtd
�|tjdffdtd�|tjd
ffdtd�|tjdffdtd�|tjfdtd�|tjfdtd�|tjfg
}t	dd�|D��}x<|D]4\}}}|�s�qtd|d|t
|�|f��qW|jjj
�rR|jj�dS)z"Display the summary of advisories.zUpdates Information Summary: rzNew Package notice(s)zSecurity notice(s)r{zCritical Security notice(s)rzImportant Security notice(s)rzModerate Security notice(s)rzLow Security notice(s)rzUnknown Security notice(s)NzBugfix notice(s)zEnhancement notice(s)zother notice(s)css"|]}|drt|d�VqdS)�N)r	)r
�vrrr
r(sz4UpdateInfoCommand.display_summary.<locals>.<genexpr>z
    %*s %s�)r��printrrJrMrNrKrL�ADVISORY_UNKNOWNrr	r^�confZautocheck_running_kernelr'Z_check_running_kernel)	r&rZr[Ztyp2cntZlabel_counts�width�indent�label�countrrr
rYs2
$z!UpdateInfoCommand.display_summarycs��fdd�}�fdd�}t�}x�|D]�\}}}d|j|j|jf}�jjsR�jjr�x�|jD]Z}	|	jt	j
krx�jjrxqZn|	jt	jkr��jjr�qZ|j|jf|j
|||jft��|	j<qZWq$|j|jf|j
|||jft��|j<q$Wg}
d}}}
x�t|j�dd�d	�D]r\\}}}}t|
t|��}
xR|j�D]F\}}t|t|��}||�}t|t|��}|
j||�||||f��q.W�qWxZ|
D]R\}}}}}�jjj�r�td
||||||
||f�ntd||||||f��q�WdS)
zDisplay the list of advisories.cs �jjdksdS|rdSdSdS)Nr"�zi z  )rAr;)�inst)r&rr
�	inst2mark2s
z1UpdateInfoCommand.display_list.<locals>.inst2markcs2|tjkr�jj|td��S�jj|td��SdS)NzUnknown/Sec.r)rJrN�SECURITY2LABEL�getr�
TYPE2LABEL)�typZsev)r&rr
�
type2label:s
z2UpdateInfoCommand.display_list.<locals>.type2labelz%s-%s.%srcSs|dS)Nrr)�xrrr
�<lambda>Rsz0UpdateInfoCommand.display_list.<locals>.<lambda>)�keyz%s%-*s %-*s %-*s %sz%s%-*s %-*s %sN)�dictr]rb�archrAr0r3rrrlrJrormrp�
setdefault�updatedri�sorted�itemsrrc�appendr^r��verboser�)r&rZr�r�Znevra_inst_dictr�rPr ZnevrarnZadvlistZidwZtlwZnwr�Zaupdatedr�ZaidZatypesevr�r)r&r
rW0s4*($$zUpdateInfoCommand.display_listcs��jjj���jjj�td�td�td�td�td�td�td�td�td	�td
�f
�����fdd�}t�}x"|D]\}}}|j|||��qtWtd
j	t
|dd�d���dS)z/Display the details about available advisories.z	Update IDZTypeZUpdatedZBugsZCVEsZDescriptionZSeverityZRightsZFilesZ	Installedc
s�|jg�jj|jtd��gt|j�ggg|jp0dj�|j	g|j
pBdj�tt�fdd�|j
D���dg
}xV|jD]L}|jtjkr�|djdj|j|jp�d��qn|jtjkrn|dj|j�qnW|dj�|dj��s�d|d<d|d	<�jjd
k�r|�rtd�ntd�g|d
<t��}g}|jdd�|jd|j�|jdd�xxt�|�D]j\}}|ddgfk�rt�qXxJt|�D]>\}}	|dk�r�|nd}
|t|
�}|jd|d|
|	f��q~W�qXWdj|�S)Nrr�c3s|]}|j�kr|jVqdS)N)r��filename)r
Zpkg)�archesrr
rsszHUpdateInfoCommand.display_info.<locals>.advisory2info.<locals>.<genexpr>�z{} - {}r���r"�trueZfalse�	�=�Oz  rz	%*s%s: %s�
)rir�r�rlrr	r�r[�
splitlinesrpZrightsr�rGZpackagesrrrJror��format�titlerm�sortrAr;r�zip�	enumerater�join)rPr Z
attributesrnr��linesr�Z	atr_lines�i�liner�Zkey_padding)r��labelsr&r�rr
�
advisory2infoisF
 "z5UpdateInfoCommand.display_info.<locals>.advisory2infoz

cSs|j�S)N)�lower)r�rrr
r��sz0UpdateInfoCommand.display_info.<locals>.<lambda>)r�N)r^r_Zlist_archesr�r�rrGrIr�r�r�)r&rZr�Z
advisoriesr�rPr r)r�r�r&r�r
rXas
(zUpdateInfoCommand.display_info)&�__name__�
__module__�__qualname__�__doc__rJrKrrLrNr�rMr�r�rBr�keys�aliasesrrErDr$�staticmethodr<rRr\rfrsrurzrVrSrTrUr�rYrWrX�
__classcell__rr)r(r
r)sJ



&6	1r)r�Z
__future__rrrrrgrJZdnf.clirZdnf.cli.option_parserrZdnf.i18nrrZ
dnf.pycompr	rZCommandrrrrr
�<module>s

?>