a
    !cqZ                    @   s  d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZ	ddl
Z
ddlZddlZddlZddlZddlZddlmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZm Z m!Z! dd	l"m#Z# dd
l$m%Z% ddl&Z'ddl(Z'ddl)Z'ddl*Z'ddl+Z'ddl,Z'ddlZ'ddl-Z'ddl.Z'ddl/Z'e
0dZ1dd Z2G dd de3Z4G dd de'j5j6Z7G dd de'j5j8Z9G dd de#Z:dddZ;dS )z"Handle actual output from the cli.    )absolute_import)print_function)unicode_literalsN)format_numberformat_time)_C_P_ucdfill_exact_widthtextwrap_fillexact_widthselect_short_long)xrange
basestringlongunicodesys_maxsize)TransactionDisplay)MergedTransactionWrapperdnfc                 C   st   t |ft d}t|}| d }| | }|s@t d|}n|rR|d|  t|}tt|g|g| R  S )N    r   )	itertoolschainrepeatlenextenditerlistzip)Z
cols_countZlabellstleftZ
lst_lengthZright_countZmissing_itemsZlst_iter r$   2/usr/lib/python3.9/site-packages/dnf/cli/output.py_spread_in_columns6   s    
r&   c                   @   s
  e Zd ZdZdZedZdd Zdd Z	dd	 Z
d
d Zdd Zedd Zedd Zedd ZdlddZedd Zdd ZdmddZdnd d!Zdod"d#Zd$d% Zd&d' Zd(d) Zdpd+d,Zdqd-d.Zdrd/d0Zi di fd1d2Zdsd3d4Zd5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dtdAdBZ&dudCdDZ'dvdEdFZ(dGdH Z)dIdJ Z*dwdKdLZ+dMdN Z,dOdP Z-dQdR Z.dSdT Z/dUdV Z0dxdWdXZ1dydYdZZ2g e3 fd[d\Z4g fd]d^Z5e6d_e6d_e6d`e6dae6dbe6dce6dde6dee6dfe6dge6dhdiZ7g fdjdkZ8dS )zOutputz+Main output class for the yum command line.z   z	^\*{0,2}/c                 C   s$   || _ || _tjj | _d | _d S N)confbaser   clitermZTermprogress)selfr*   r)   r$   r$   r%   __init__I   s    zOutput.__init__c                 C   s0   | j j}dd | }| t||d}|||fS )N%s= )r,   columns
fmtColumnsr!   )r.   col_datarowZ
term_widthZruleheaderr$   r$   r%   _bannerO   s    zOutput._bannerc           	      C   sr   dd |d D }|D ]:}t |D ],\}}|| }t|}||dd ||< q"q| j|d dd}tttj|S )Nc                 S   s   g | ]
}t  qS r$   )dict).0r   r$   r$   r%   
<listcomp>V       z&Output._col_widths.<locals>.<listcomp>r   r     )indent)	enumerater   getcalcColumnsr    mapoperatorneg)	r.   rowsr5   r6   ivalZcol_dctZlengthcolsr$   r$   r%   _col_widthsU   s    zOutput._col_widthsc                 C   s   d}d}|snt |tr |dkr.| jjd }n|dkr8n|dd D ]}|dkrZd}qH|| jjv rx|| jj| 7 }qH|| jjv r|| jj| 7 }qH|dr|dd  | jjv r|| jj|dd   7 }qH|drH|dd  | jjv rH|| jj|dd   7 }qH|r| jjd }||fS )	Nr   boldnormal,r2   zfg:   zbg:)	
isinstancer   r,   ZMODEreplacesplitZFG_COLOR
startswithZBG_COLOR)r.   	highlighthibeghiendZhighr$   r$   r%   
_highlight`   s4    

zOutput._highlightc                 K   s(   |  |\}}| jj||||fi |S r(   )rU   r,   sub)r.   ZhaystackrR   ZneedleskwdsrS   rT   r$   r$   r%   _sub_highlight}   s    zOutput._sub_highlightc                 C   s2   d}|D ]$}||d |  k r  q.||d 7 }q|S )z; Spaces left on the current field will help how many pkgs? r   r   r$   )currentZ	data_tupsr#   rettupr$   r$   r%   _calc_columns_spaces_helps   s    z!Output._calc_columns_spaces_helpsc                 C   s   | j jS r(   )r*   historyr.   r$   r$   r%   r]      s    zOutput.historyc                 C   s   | j jS r(   )r*   sackr^   r$   r$   r%   r_      s    zOutput.sackNr   r   c                 C   s  t |}|}dg| }td|D ]}t||  ||< q |du rJ| jj}|du rjdg|d  }|d |sg }	td|D ]6}|| }
|
r|	|
d d  q||	|| d  q||	d  t |7  < | jj}t	|	|kr|	S |}|t	||d  t
| 8 }|d s|d7 }|dkrd}d}td|D ]b}| || || |}|sRq.|rx||d krx|d |k rxq.||k rq.|}|}q.|r|| dd ||  }|| s||d kr|d8 }||  |7  < ||8 }qd}td|D ]}|| sq|d7 }q|r`|| }td|D ],}|| sDq2||  |7  < ||8 }q2|d8 }|| }td|D ]}||  |7  < qz||  |||  7  < d}q|S )a  Dynamically calculate the widths of the columns that the
        fields in data should be placed into for output.

        :param data: a list of dictionaries that represent the data to
           be output.  Each dictionary in the list corresponds to a
           column of output. The keys of the dictionary are the
           lengths of the items to be output, and the value associated
           with a key is the number of items of that length.
        :param columns: a list containing the minimum amount of space
           that must be allocated for each row. This can be used to
           ensure that there is space available in a column if, for
           example, the actual lengths of the items being output
           cannot be given in *data*
        :param remainder_column: number of the column to receive a few
           extra spaces that may remain after other allocation has
           taken place
        :param total_width: the total width of the output.
           self.term.real_columns is used by default
        :param indent: string that will be prefixed to a line of
           output to create e.g. an indent
        :return: a list of the widths of the columns that the fields
           in data should be placed into for output
        Nr   r      )r   rangesorteditemsr,   real_columnsappendr   r3   sumr   r\   pop)r.   datar3   remainder_columntotal_widthr>   rH   ZpdatadZfull_columnscolZdefault_widthZhelpsrG   ZthelpsdiffZoverflowed_columnsZnormr$   r$   r%   rA      s    



"


zOutput.calcColumnsc                 C   s   | dk rd|  fS d| fS )z$Returns tuple of (align_left, width)r   TFr$   )widthr$   r$   r%   _fmt_column_align_width  s    
zOutput._fmt_column_align_widthc                 C   sP   t |dkr|\}}d }}t |dkr@|\}}}| |\}}t||||fS )Nra   r   rM   )r   rU   r
   )r.   r5   rG   ro   rS   rT   rR   r$   r$   r%   	_col_data  s    
zOutput._col_datac                 C   sB  t |}t|}g }|dd D ]}| |\}}}	}
|sN|d7 }|| q | |\}}t|}||kr|d7 }|r||	|d||  |
g q||	d||  ||
g n(|dd|| d   7 }||	||
g ||7 }|d7 }q | |d \}}}	}
| |\}}t||||	|
d}|d	| 7 }|| |t| S )
a.  Return a row of data formatted into a string for output.
        Items can overflow their columns.

        :param columns: a list of tuples containing the data to
           output.  Each tuple contains first the item to be output,
           then the amount of space allocated for the column, and then
           optionally a type of highlighting for the item
        :param msg: a string to begin the line of output with
        :param end: a string to end the line of output with
        :return: a row of data formatted into a string for output
        Nr`   r0   z	%s%s%s%s r2   z%s%s%s
r   )r#   prefixsuffixz%%s%s)	r    r   rq   rf   rp   r   r   r   tuple)r.   r3   msgendrk   ri   r5   rG   ro   rS   rT   Z
align_leftZ	val_widthr$   r$   r%   r4   %  s8    


zOutput.fmtColumnsFc                 C   sP   |du rd}d||j |jf }|ddg}t||j|jf||}t| | dS )a  Print a package as a line.

        :param pkg: the package to be printed
        :param ui_overflow: unused
        :param indent: string to be prefixed onto the line to provide
           e.g. an indent
        :param highlight: highlighting options for the name of the
           package
        :param columns: tuple containing the space allocated for each
           column of output.  The columns are the package name, version,
           and repository
        N)iiz%s%s.%srK   )namearchr!   evr
_from_repoprintr4   )r.   pkgui_overflowr>   rR   r3   Znahi_colsr$   r$   r%   
simpleListT  s    
zOutput.simpleListc           	      C   sN   |du rd}d|t |f }|ddg}|j}t||f||}t| | dS )a(  Print a package as a line, with the package itself in envra
        format so it can be passed to list/install/etc.

        :param pkg: the package to be printed
        :param ui_overflow: unused
        :param indent: string to be prefixed onto the line to provide
           e.g. an indent
        :param highlight: highlighting options for the name of the
           package
        :param columns: tuple containing the space allocated for each
           column of output.  The columns the are the package envra and
           repository
        N)irw   %s%srK   )r
   ui_from_repor!   r|   r4   )	r.   r}   r~   r>   rR   r3   Zenvrar   Zridr$   r$   r%   simpleEnvraListj  s    
zOutput.simpleEnvraListc                 C   s   t t|j dS )z.Print a package as a line containing its name.N)r|   r
   rx   r.   r}   r$   r$   r%   simple_name_list  s    zOutput.simple_name_listc                 C   s   t t| dS )z/Print a package as a line containing its NEVRA.N)r|   r
   r   r$   r$   r%   simple_nevra_list  s    zOutput.simple_nevra_listc                 C   s   t |}| jj}|st}n|dk r&d}d|d  d }|s>|S t|}t||||d}|ddkr||d krt|||d	d}|S )
zReturn a key value pair in the common two column output
        format.

        :param key: the key to be formatted
        :param val: the value associated with *key*
        :return: the key value pair formatted in two columns for output
           r2   ra   z: )ro   Zinitial_indentZsubsequent_indent
r   rM   z
     ...: )r   r,   re   r   r
   r   count)r.   keyrG   ZkeylenrH   ZnxtrZ   r$   r$   r%   fmtKeyValFill  s$    zOutput.fmtKeyValFillr1   c                 C   sh   t |}| jjd }t|}||d kr6|d  }}n$||| d  }||| t|  }d|||f S )a  Format and return a section header.  The format of the
        header is a line with *name* centered, and *fill* repeated on
        either side to fill an entire line on the terminal.

        :param name: the name of the section
        :param fill: the character to repeat on either side of *name*
          to fill an entire line.  *fill* must be a single character.
        :return: a string formatted to be a section header
        ra      z%s %s %s)r
   r,   r3   r   r   )r.   rx   ZfillrH   Zname_lenZbegrv   r$   r$   r%   
fmtSection  s    
zOutput.fmtSectionc                    s  dd } fdd}g }  |\}}tdtddtdd}|||d	||j|f  |jrv||td
|j tdtddtdd}||||j ||td|j tdtddtdd}||||j	 tdtddtdd}|||t
t|j ||td|j tdtddtdd}||||j |jr j|}	|	r||td|	  jjr<||td|j ||tdtj|j |jr||tdtj|j  j|}
|
r<zt|
j }W n ty    d}Y n0 ||td | tdtddtdd}||||j  |j!r||tdt"|j! ||td|j# tdtddtdd}||||j$ d%|S )zPrint information about the given package.

        :param pkg: the package to print information about
        :param highlight: highlighting options for the name of the
           package
        c                 S   s   d t| dddt|gS )Nr2      :)joinr   strr   rG   r$   r$   r%   format_key_val  s    z)Output.infoOutput.<locals>.format_key_valc                    s     t| ddd |pdS )Nr   z : r   )r   r   r   r^   r$   r%   format_key_val_fill  s    z.Output.infoOutput.<locals>.format_key_val_fillr   shortNamer   z%s%s%sZEpochVersionZReleaseArchArchitectureSizeZSourceRepo
Repositoryz	From repoZPackagerZ	BuildtimezInstall timeNzInstalled byZSummaryZURLZLicenseZDescriptionr   )&rU   r   r   rf   rx   Zepochr   versionreleasery   r   float_sizeZ	sourcerpmrepoid_from_systemr]   Zrepor)   verboseZpackagerr   utilZnormalize_timeZ	buildtimeZinstalltimeZpackage_dataint_itemZgetInstalledBy
ValueError_pwd_ui_usernamesummaryurlr
   licensedescriptionr   )r.   r}   rR   r   r   Zoutput_listrS   rT   r   Zhistory_repoZhistory_pkguidr$   r^   r%   
infoOutput  s|    

zOutput.infoOutputc           
      C   s   |\}}|durV| j j}|jtjkr,| j j}| j|||d | j||d| j jd dS | }d|j	|j
f }|j}	td||	||f  dS )a{  Print a simple string that explains the relationship
        between the members of an update or obsoletes tuple.

        :param uotup: an update or obsoletes tuple.  The first member
           is the new package, and the second member is the old
           package
        :param changetype: a string indicating what the change between
           the packages is, e.g. 'updates' or 'obsoletes'
        :param columns: a tuple containing information about how to
           format the columns of output.  The absolute value of each
           number in the tuple indicates how much space has been
           allocated for the corresponding column.  If the number is
           negative, the text in the column will be left justified,
           and if it is positive, the text will be right justified.
           The columns of output are the package name, version, and repository
        N)r3   rR       )r3   r>   rR   %s.%sz%-35.35s [%.12s] %.10s %-20.20s)r)   color_update_remotereponamehawkeyZSYSTEM_REPO_NAMEcolor_update_localr   color_update_installedZcompactPrintrx   ry   r   r|   )
r.   ZuotupZ
changetyper3   Z	changePkgZinstPkgZchiZ	c_compactZ	i_compactZc_repor$   r$   r%   updatesObsoletesList  s     

zOutput.updatesObsoletesListc                 C   sd  |dv r`t |dkrXtd|  t }|dkr^i }|D ]}	|	|t|	t|	j < q:| }t|D ]}	|	j|	jf}
d}|
|vr|	dd}nD|	
||
 r|	dd}n(|	||
 r|	d	d
}n|	dd}|dkr| j|	d||d qf|dkr|| j|	|dd  qf|dkr*| |	 qf|dkrf| |	 qfqf|rXtdt| t |S dS )a  Prints information about the given list of packages.

        :param lst: a list of packages to print information about
        :param description: string describing what the list of
           packages contains, e.g. 'Available Packages'
        :param outputType: The type of information to be printed.
           Current options::

              'list' - simple pkg list
              'info' - similar to rpm -qi output
              'name' - simple name list
              'nevra' - simple nevra list
        :param highlight_na: a dictionary containing information about
              packages that should be highlighted in the output.  The
              dictionary keys are (name, arch) tuples for the package,
              and the associated values are the package objects
              themselves.
        :param columns: a tuple containing information about how to
           format the columns of output.  The absolute value of each
           number in the tuple indicates how much space has been
           allocated for the corresponding column.  If the number is
           negative, the text in the column will be left justified,
           and if it is positive, the text will be right justified.
           The columns of output are the package name, version, and
           repository
        :param highlight_modes: dictionary containing information
              about to highlight the packages in *highlight_na*.
              *highlight_modes* should contain the following keys::

                 'not_in' - highlighting used for packages not in *highlight_na*
                 '=' - highlighting used when the package versions are equal
                 '<' - highlighting used when the package has a lower version
                       number
                 '>' - highlighting used when the package has a higher version
                       number
        :return: number of packages listed
        )r    inforx   nevrar   r0   r    Fznot inrK   r1   >rJ   <T)r~   rR   r3   r   )rR   r   rx   r   N)r   r|   setr   r{   valuesrc   rx   ry   r@   Zevr_eqZevr_ltr   addr   r   r   r   )r.   r"   r   Z
outputTypeZhighlight_nar3   Zhighlight_modesZinfo_setZunique_item_dictr}   r   rR   r$   r$   r%   listPkgs3  sB    '


zOutput.listPkgsc                 C   s.  t tdt tdf}t tdt tdf}|| }|du rHtd}d}| jjrj|du rftd}n|}ztj|}W n* ty   Y n ty   |d	 }Y n0 t |	 }t
|d	kr| jjr|d	 n|d	 }||v rqd|krd|vr|d	 }qd|kr8d|vr8|d	 }qq8||v r*d
S dS )zGet a yes or no from the user, and default to No

        :msg: String for case with [y/N]
        :defaultyes_msg: String for case with [Y/n]
        :return: True if the user selects yes, and False if the user
           selects no
        yZyesnZnoNzIs this ok [y/N]: r   zIs this ok [Y/n]: r   TF)r
   r   r)   Z
defaultyesr   Zi18nZ	ucd_inputEOFErrorKeyboardInterruptlowerr   )r.   ru   Zdefaultyes_msgZyuiZnuiZauiZchoicer$   r$   r%   userconfirm  s<    

zOutput.userconfirmc                 C   sz   | j    }| j    }i }tjtt| d  D ]6}||v r\|| d ||< q>||v r>|| d ||< q>|S Nr   r   )	r_   query	installedZ
_name_dict	availabler   r   r    r!   )r.   sectionsr   r   rl   pkg_namer$   r$   r%   _pkgs2name_dict  s    zOutput._pkgs2name_dictc           	      C   s   i }i }t jtt| d  D ]d}||}|d u r6qtt|t| j }tt|j}||dd ||< ||dd ||< q||fS r   )	r   r   r    r!   r@   r   r
   GRP_PACKAGE_INDENTr   )	r.   r   	name_dictZnevra_lengthsZrepo_lengthsr   r}   Znevra_lZrepo_lr$   r$   r%   _pkgs2col_lengths  s    
zOutput._pkgs2col_lengthsc                 C   s    |D ]}t d| j|f  qd S )Nr   )r|   r   )r.   	pkg_namesrx   r$   r$   r%   _display_packages  s    zOutput._display_packagesc              	   C   sl   |D ]b}z|| }W n( t y<   td| j|f  Y qY n0 d}|jsP| jj}| j|d| j||d qd S )Nr   FT)r~   r>   rR   r3   )KeyErrorr|   r   r   r)   Zcolor_list_available_installr   )r.   r   r   r3   rx   r}   rR   r$   r$   r%   _display_packages_verbose  s    
z Output._display_packages_verbosec           
      C   sh  dd }t tdtj|j  | jj}|rDt tdt|j	  |j
rdt tdt|j
 p`d |jr|t td|j  td||jftd	||jftd
||jftd||jff}|r0| |}| ||}| |}|d  |d  f}|D ].\}}	t|	dk rqt | | |	|| qn4|D ].\}}	t|	dk rNq4t | | |	 q4dS )zOutput information about the packages in a given group

        :param group: a Group object to output information about
        c                 S   s   t dd | D S )Nc                 s   s   | ]}t j|jV  qd S r(   r   r   _name_unset_wrapperrx   r:   r}   r$   r$   r%   	<genexpr>  r<   z?Output.display_pkgs_in_groups.<locals>.names.<locals>.<genexpr>rc   )packagesr$   r$   r%   names  s    z,Output.display_pkgs_in_groups.<locals>.namesz	Group: %sz Group-Id: %s Description: %sr   z Language: %sz Mandatory Packages:z Default Packages:z Optional Packages:z Conditional Packages:r   r   N)r|   r   r   r   r   ui_namer)   r   r
   idui_descriptionZ	lang_onlyZmandatory_packagesZdefault_packagesZoptional_packagesZconditional_packagesr   r   rA   r   r   r   )
r.   groupr   r   r   r   Zcol_lengthsr3   section_namer   r$   r$   r%   display_pkgs_in_groups  s:    

zOutput.display_pkgs_in_groupsc                 C   s   dd }t tdtj|j  | jjr@t tdt|j	  |j
rdt|j
pRd}t td|  td||jftd||jff}|D ](\}}t|d	k rqt | | | qd
S )zOutput information about the packages in a given environment

        :param environment: an Environment object to output information about
        c                 S   s   t dd | D S )Nc                 s   s   | ]}t j|jV  qd S r(   r   )r:   r   r$   r$   r%   r   	  r<   zFOutput.display_groups_in_environment.<locals>.names.<locals>.<genexpr>r   )groupsr$   r$   r%   r     s    z3Output.display_groups_in_environment.<locals>.nameszEnvironment Group: %sz Environment-Id: %sr   r   z Mandatory Groups:z Optional Groups:r   N)r|   r   r   r   r   r   r)   r   r
   r   r   Zmandatory_groupsZoptional_groupsr   r   )r.   Zenvironmentr   r   r   r   r   r$   r$   r%   display_groups_in_environment  s    z$Output.display_groups_in_environmentc                    sH  d fdd	fdd}j jr4d }ndjjf }|jpRd}r| d	u rjj j j| d
d}t| |d	u rj j	}|sd	S tt
dj  d}d}	t|D ]F}
j|
krd
}	qj|
k rt
d}||
|d
d d
}qj|
kr(t
d}||
|dd d
}qj|
krRt
d}||
|dd d
}q||
|rdd
}qt
d}jD ]}t|}t||
r|||dd d
}n`| d }tdtfdd|
D r|
 d }n|
}t||rr|||dd d
}qrqt||	gs>t|D ]}
t
d}||
|dd qt  d	S )a  Output search/provides type callback matches.

        :param po: the package object that matched the search
        :param values: the information associated with *po* that
           matched the search
        :param matchfor: a list of strings to be highlighted in the
           output
        :param verbose: whether to output extra verbose information
        :param highlight: highlighting options for the highlighted matches
        Fc                    sd   |st td t|pd}|dkr(d S r>j| dd}|rTt | | nt | |  d S )NzMatched from:r   TZignore_case)r|   r   r
   rX   r   )r   itemZprinted_headlinecan_overflow)rR   matchforr.   r$   r%   print_highlighted_key_item'  s    z8Output.matchcallback.<locals>.print_highlighted_key_itemc                    sP   j | sdS td}d} jD ](}t|| r"|||p>|dd d}q"|S )NFzFilename    : %sr   T)FILE_PROVIDE_REmatchr   filesfnmatch)r   printed_matchr   Z
file_matchfilename)por   r.   r$   r%   print_file_provides4  s    
z1Output.matchcallback.<locals>.print_file_providesz%s : z%s.%s : r   NTr   zRepo        : %szDescription : r   zURL         : %szLicense     : %szProvide    : %sr   z=<>c                 3   s   | ]}| v V  qd S r(   r$   )r:   char)possibler$   r%   r   p  r<   z'Output.matchcallback.<locals>.<genexpr>zOther       : %s)F)r)   Zshowdupesfromreposrx   ry   r   r   Zcolor_search_matchrX   r|   r   r   r   r   r   r   r   Zprovidesr   r   rP   any)r.   r   r   r   r   rR   r   ru   r   Z
name_matchr   r   ZprovideZfirst_provideZitem_newr$   )rR   r   r   r   r   r.   r%   matchcallback  sr    



zOutput.matchcallbackc                 C   s   | j |||ddS )aq  Output search/provides type callback matches.  This will
        output more information than :func:`matchcallback`.

        :param po: the package object that matched the search
        :param values: the information associated with *po* that
           matched the search
        :param matchfor: a list of strings to be highlighted in the
           output
        T)r   )r   )r.   r   r   r   r$   r$   r%   matchcallback_verbose  s    
zOutput.matchcallback_verbosec           
   	   C   s  d}d}d}d}|D ]}zpt |j}||7 }z| r>||7 }W n tyR   Y n0 |s\W qzt |j}W n ty|   Y n0 ||7 }W q ty   d}td}	t|	 Y  qY q0 q|s|rttdt	| ||krttdt	||  |rttdt	| dS )	zReport the total download size for a set of packages

        :param packages: a list of package objects
        :param installonly: whether the transaction consists only of installations
        r   FTz2There was an error calculating total download sizezTotal size: %szTotal download size: %szInstalled size: %sN)
r   r   ZverifyLocalPkg	ExceptionZinstallsizer   loggererrorr   r   )
r.   r   ZinstallonlytotsizeZlocsizeZinsizer   r}   sizeru   r$   r$   r%   reportDownloadSize  sH    




zOutput.reportDownloadSizec              	   C   sp   d}d}|D ]F}z|j }||7 }W q tyP   d}td}t| Y  qTY q0 q|slttdt| dS )zmReport the total size of packages being removed.

        :param packages: a list of package objects
        r   FTz-There was an error calculating installed sizezFreed space: %sN)r   r   r   r   r   r   r   )r.   r   r   r   r}   r   ru   r$   r$   r%   reportRemoveSize  s    
zOutput.reportRemoveSizec                 C   s  |sd S g }g }|j r$|td |j D ]@}t||}||}|rP|jn|}	|tdd|	 | q*|j	r|td |j	D ]6}t|
|}|j|j}	|tdd|	 | q|r| |}
|D ]}|| t||
d q| |
tdtdddf|d	d	< d
|S )Nz+Marking packages as installed by the group:r   @z)Marking packages as removed by the group:r2   ZGroupPackagesr   r   r   )Z
new_groupsrf   r   r    Zadded_packagesZ_group_by_idr   r   r&   Zremoved_groupsZremoved_packagesr   r@   rI   r4   r!   r8   r   )r.   compsr]   rn   outrE   Zgrp_idZpkgsZgroup_objectZgrp_namer5   r6   r$   r$   r%   list_group_transaction  s.    



$zOutput.list_group_transactionc           Q         sz  t jt jB t jB t jB t jB t jB }t }t }|du r<g }tj	
|}g }i i i d}d}	g f fdd	}
tjjr|tdntd}tdd	|jftdd
|jftdd|jf||jftd|jftd|jftd|jftd|jftd|jftdd|jff
D ]\}}g }i }|D ]@}|jtjjkr0q|j D ]}||t  | q:qt!|dd dD ]H}|jtjj"tjj#g vrqjt!|$|jg }|
|||	|j%|}	qj|&||f qt!t' jj() * }|r>td}g }|D ]:\}}t+|D ]&}|&d||f ddddddf qq|&||f t!t' jj(, * }|rtd}g }|D ]:\}}t+|D ]&}|&d||f ddddddf q|ql|&||f t!t' jj(- * }|rtd}g }|D ]"\}}|&|d|ddddf q|&||f t!t' jj(. * }|rtd}g }|D ]2\}}|&|dd|d |d f ddddf qD|&||f t!t+ jj(/ }|rtd}g }|D ]}|&|ddddddf q|&||f t!t+ jj(0 }|r6td}g }|D ]}|&|ddddddf q|&||f  jj1rdd  } jj1j2j3}|rtd!}g }|4 D ]}|&|| qn|&||f  jj1j2j5} | rtd"}g }| 4 D ]}|&|| q|&||f  jj1j2j6}!|!r&td#}g }|!4 D ]}|&|| q|&||f  jj1j7j3}"|"rptd$}g }|"4 D ]}|&|| qL|&||f  jj1j7j5}#|#rtd%}g }|#4 D ]}|&|| q|&||f  jj1j7j6}$|$rtd&}g }|$4 D ]}|&|| q|&||f  j8j9r j8j:s, jj;j<|@ r,g } jj=d'|d(\}}t'd)d* |D }t!|D ]}%|
|||	|%g }	qZd+g}& jj>s|&&d, td-d.?|& }'d/d0 |D }|&|'|f g }t!|* D ]\}(}%|
|||	|%g }	qtd1}' jj8j@r|'d }'n|'td2 }'d3d0 |D }|&|'|f  jAjB})|d4 sr jj(C sr jj1rn jj1j7sr jj1j2srdS |d4 i |d5 |d6 i g}d|	ddd7g}* jD|d8|*d9|d:}*|*\}+}	},}-}.tE|*d7 }/|)|/kr|)n|/})tF|+td;d<td=d<}0tF|	td;d>td=d?}1tF|,td;d@td=d@}2tF|-td;dAtd=dB}3tF|.td;dCtd=dC}4dDdE|)  G|0|+ f|1|	 f|2|, f|3|- f|4|.ffd.dE|) f g}5|D ]\}}|rdF| }6|D ]\}7}8}9}:};}<}=|7|+ |=f|8|	 f|9|, f|:|- f|;|.ff}* G|*d.dG}> H j8jI\}?}@t!|<D ]6}AdHtdI dJ }B|B|?|AjJ|@|AjK|AjLf; }B|>|B7 }>	q|6|> }6q|r|5&|6 q|5&tdKdE|)   tdLtM|jtM|j tM|j tM|j dftdMtM|jdftdNtM|jtM|j tM|j dftdOtM|jdftdPtM|tM| dff}Cd}Dd}Ed}Fd}G|CD ]\}}H}I|H
sN|I
sN
q4tNd<dQ|H}JtO|}KtOtP|H}LtO|J}M|I
rtOtP|I}Nnd}NtQ|K|D}DtQ|L|E}EtQ|M|F}FtQ|N|G}G
q4|CD ]\}}H}ItNd<dQ|H}J|IrFtNdRdS|I}OtR||D}P|Hr dT}>|5&|>|P|E|HdU|F|Jf |G|I|Of  n$dV}>|5&|>|P|E|F d. |G|I|Of  n&|H
rdW}>|5&|>tR||D|E|H|Jf  
qd?|5S )Xz]Return a string representation of the transaction in an
        easy-to-read format.
        N)r   vrr   c              	      s   |j \}}}}}	|j}
|j}t|j}|d u r2d}|jrB jj}n|jrR jj	}n jj
}| |||
||||f dt|fdt|
fdt|ffD ],\}}|| |d || |  d7  < qt|t|}|S )NZnoarchr   r  r  r   r   )Zpkgtuprz   r{   r   r   r   r)   r   Z_from_cmdliner   r   rf   r   
setdefaultmax)linesri   a_widr   	obsoletesr   aer  r  rz   r   r   hirl   r^   r$   r%   	_add_line  s"    


*z*Output.list_transaction.<locals>._add_linez Installing group/module packageszInstalling group packagesr   Z
InstallingZ	UpgradingZReinstallingzInstalling dependencieszInstalling weak dependenciesZRemovingzRemoving dependent packageszRemoving unused dependenciesZDowngradingc                 S   s   | j S r(   r}   )xr$   r$   r%   <lambda>4  r<   z)Output.list_transaction.<locals>.<lambda>)r   zInstalling module profilesz%s/%sr   zDisabling module profileszEnabling module streamszSwitching module streamsz%s -> %sr   zDisabling moduleszResetting modulesc                 S   s   t j|  ddddddfS )Nr   )r   r   r   ZgetName)r   r$   r$   r%   format_lineq  s    z,Output.list_transaction.<locals>.format_linezInstalling Environment GroupszUpgrading Environment GroupszRemoving Environment GroupszInstalling GroupszUpgrading GroupszRemoving GroupsT)Zreport_problemstransactionc                 s   s   | ]}t ||fV  qd S r(   r   r   r$   r$   r%   r     r<   z*Output.list_transaction.<locals>.<genexpr>z--bestz--allowerasingzSSkipping packages with conflicts:
(add '%s' to command line to force their upgrade)r2   c                 S   s   g | ]}|d d d qS Nr`   r   r$   r:   rF   r$   r$   r%   r;     r<   z+Output.list_transaction.<locals>.<listcomp>z,Skipping packages with broken dependencies%sz or part of a groupc                 S   s   g | ]}|d d d qS r  r$   r  r$   r$   r%   r;     r<   r   r  r     r=   ra   )r>   r3   rj   rk   r   ZPackager   r   r   r   r   r   r   z	%s
%s
%s
r1   z%s:
r   z     Z	replacingz  %s%s%s.%s %s
z
Transaction Summary
%s
InstallUpgradeZRemove	DowngradeZSkipr   zDependent packagezDependent packagesz%s  %*d %s (+%*d %s)
z%-*sz%s  %s  ( %*d %s)
z%s  %*d %s
)Sr   ZUPGRADEZUPGRADE_ALLZDISTUPGRADEZDISTUPGRADE_ALLZ	DOWNGRADEZINSTALLr   r   r   Z_make_listsr*   ZWITH_MODULESr   r   r   ZupgradedZreinstalledZinstalled_groupZinstalled_depZinstalled_weakZerasedZ
erased_depZerased_cleanZ
downgradedactionlibdnfr  ZTransactionItemAction_OBSOLETEDr   ZgetReplacedByr  r   rc   ZFORWARD_ACTIONSZTransactionItemAction_REMOVEr@   r}   rf   r9   Z_moduleContainerZgetInstalledProfilesrd   r    ZgetRemovedProfilesZgetEnabledStreamsZgetSwitchedStreamsZgetDisabledModulesZgetResetModulesZ_historyenvZ
_installedr   Z	_upgradedZ_removedr   r)   ZbeststrictZ_goalactionsZ_skipped_packagesZ_allow_erasingr   Zupgrade_group_objects_upgrader,   r3   Z	isChangedrA   rg   r   r4   rU   r   rx   ry   rz   r   r	   r   r   r  r   )Qr.   r  rk   Zforward_actionsZskipped_conflictsZskipped_brokenZ
list_bunchZpkglist_linesri   r  r  Zins_group_msgr  Zpkglistr  ZreplacestsirF   Z	obsoletedZinstalledProfilesrx   ZprofilesZprofileZremovedProfilesZenabledStreamsstreamZswitchedStreamsZdisabledModulesZresetModulesr  Zinstall_env_groupr   Zupgrade_env_groupZremove_env_groupZinstall_groupZupgrade_groupZremove_groupr}   ZrecommendationsZskip_strr   Zoutput_widthr3   Zn_widZv_widZr_widZs_widZ
real_widthZmsg_packageZmsg_archZmsg_versionZmsg_repositoryZmsg_sizer   Ztotalmsgr   r	  rz   r   r   r  r  ru   rS   rT   ZobspoZappendedZsummary_dataZmax_msg_actionZmax_msg_countZmax_msg_pkgsZmax_msg_depcountr   ZdepcountZmsg_pkgsZlen_msg_actionZlen_msg_countZlen_msg_pkgsZlen_msg_depcountZmsg_deppkgsZ
action_msgr$   r^   r%   list_transaction  s8   ((,
$




	









zOutput.list_transactionc           
   	      s    fdd}|sdS g }g }| d| |D ]}| t| q0dD ]}|||}|rH q`qH|st jjd  g}|r|d t| }	| d t|	| |t|d  }qt|S )Nc                    s   t | |k rg S  jj|d d  }|dkr0g S dg| }d}| D ]\}t ||| krt |||  }||krvg   S ||8 }t |||< |d7 }|t |; }qBtt |D ](}||  || 7  < ||  d9  < q|S )zb Work out how many columns we can use to display stuff, in
                the post trans output. r   ra   r   r`   )r   r,   r3   rb   )msgsnumr#   Zcol_lensrm   ru   rn   r^   r$   r%   _fits_in_colsJ  s(    
z+Output._pto_callback.<locals>._fits_in_colsr   z{}:)         r  r   rM   ra   ra   z  {})rf   formatr   r,   r3   r   r4   r!   )
r.   r  Ztsisr#  r   r!  r  r"  rH   Zcurrent_msgsr$   r^   r%   _pto_callbackG  s&    
zOutput._pto_callbackc                 C   s   t j| j|| jS )z{
        Return a human-readable summary of the transaction. Packages in sections
        are arranged to columns.
        )r   r   Z_post_transaction_outputr*   r(  )r.   r  r$   r$   r%   post_transaction_outputy  s    zOutput.post_transaction_outputc                 C   s@   d}| j jdkr6tjjjtjd}tjjjtjd| _|t fS )z_Set up the progress callbacks and various
           output bars based on debug level.
        Nra   )Zfo)	r)   Z
debuglevelr   r+   r-   ZMultiFileProgressMetersysstdoutDepSolveProgressCallBack)r.   progressbarr$   r$   r%   setup_progress_callbacks  s
    zOutput.setup_progress_callbacksc                 C   sz   |dkrdS | j j}td|  tdt | }dt|| t|t|f }tt	d|t
| | }t| dS )a!  Outputs summary information about the download process.

        :param remote_size: the total amount of information that was
           downloaded, in bytes
        :param download_start_timestamp: the time when the download
           process started, in seconds since the epoch
        r   N-g{Gz?z %5sB/s | %5sB %9s     ZTotal)r,   r3   r   r   r  timer   r   r   r   r   )r.   Zremote_sizeZdownload_start_timestampro   Zdl_timeru   r$   r$   r%   download_callback_total_cb  s    
z!Output.download_callback_total_cbc                 C   s   t  }t  }d}|D ]<}|jtjjtjjfv r0q||j ||j |d7 }qt	|dkrp|d
t|fS |d
t|fS )Nr   r   , r   )r   r  r  r  ZTransactionItemAction_UPGRADEDZ TransactionItemAction_DOWNGRADEDr   action_nameZaction_shortr   r   rc   r    )r.   Zhpkgsr  Zactions_shortr   r}   r$   r$   r%   _history_uiactions  s    
zOutput._history_uiactionsc           	         s  t |tr fdd|D S |d u s.|dv rftd}tdd | } d ur^t| kr^|}t|S dd }zttt|}|t|jd	d
}t|j	}d||f } d urt| krd|||f }t| krd| }|W S  t
 y   t| Y S 0 d S )Nc                    s   g | ]} | qS r$   r   )r:   ulimitr.   r$   r%   r;     r<   z+Output._pwd_ui_username.<locals>.<listcomp>)l    iz<unset>ZSystemr2   c                 W   s   | j | }|sdS |d S )zf Split gives us a [0] for everything _but_ '', this function
                returns '' in that case. r   r   )rP   )textargsrZ   r$   r$   r%   _safe_split_0  s    
z.Output._pwd_ui_username.<locals>._safe_split_0;ra   z%s <%s>z%s ... <%s>z<%s>)rN   r    r   r   r
   pwdgetpwuidr   Zpw_gecospw_namer   )	r.   r   r8  Zloginidrx   r;  userfullnameZ	user_namer$   r7  r%   r     s*    

zOutput._pwd_ui_usernamec              
   C   sb  | j |}| jjdkr"ddg}nR| jjdkr6dg}n>t }d}d}|D ]*}|d7 }|jdu rf|d7 }||j qHd}t|dkrt	d}	| j
j}
|
du rtjj
d}
|
du rd	}
|
d
kr|
d nd	}nt	d}	d	}t|tt	dddt|	||tt	dddtt	dddtt	dddf  d| d d d d d d }td|  d}|du rht|}|D ]}t|dkr|jpd}	n| |jd	}	t|	}	tdt|j}| | \}}t|	||}	t|dd}d }}|jdu rd }}n"|jrd }}n|jr d }}|jr,d }|jr8d!}t||j|	|||f d"||f  qldS )#zOutput a list of information about the history of yum
        transactions.

        :param tids: transaction Ids; lists all transactions if empty
        Zusersr   ra   Zcommandsr   Nz%s | %s | %s | %s | %szCommand line   O   7   z	User nameZIDr&  zDate and time   z	Action(s)   ZAlteredr%  	   rM   r/  z%6u | %s | %-16.16s | %s | %4uTr   z%Y-%m-%d %H:%Mr2   *#Er   r   r   )r]   oldr)   Zhistory_list_viewr   cmdliner   loginuidr   r   r,   re   r   r+   Z_real_term_widthr|   r   reversedr   r
   r0  strftime	localtimebeg_timestampr4  ri   return_codeZ	is_outputaltered_lt_rpmdbaltered_gt_rpmdbtid)r.   tidsreversetransactionsZuidsdoneZblanksr  fmtrx   Z	real_colsZ
name_widthZtable_widthZtmr"  ZuiactsZrmarkZlmarkr$   r$   r%   historyListCmd  st    


 



zOutput.historyListCmdc                 C   s  t |}| j }|du r8ttd tjtd|j	}|j
}g }|sz| jjdd}|dur||j	 || n| j|}|sttd tjtdd\}}	d}
d}|rt|}| \}}	|D ]}|dur|j	|kr| jj }|t| d}d}|j	|krL|j	|	krL|
du r<t|}
n
|
| d}n\|
dur|rdtd	 d}| |
 d}
|r| \}}	|j	|kr|j	|	kr|}
d}|s|rtd	 d}| || q|
dur|rtd	 | |
 dS )
zOutput information about a transaction in history

        :param tids: transaction Ids; prints info for the last transaction if empty
        :raises dnf.exceptions.Error in case no transactions were found
        NzNo transactionszFailed history infoF)Zcomplete_transactions_onlyz$No transaction ID, or package, given)r`   r`   TzO-------------------------------------------------------------------------------)r   r]   lastr   criticalr   r   
exceptionsErrorrU  end_rpmdb_versionr   rf   rK  rc   rh   r*   Z_tsZdbCookieZcompare_rpmdbvr   r   merger|   _historyInfoCmd)r.   rV  patsZmtidsr\  ZlasttidZlastdbvrX  ZbmtidZemtidZmobjrY  ZtransZrpmdbvZmergedr$   r$   r%   historyInfoCmd"  sl    






zOutput.historyInfoCmdc                    s\  |j }t|tr|g}fdd|D }tdtdtdtddtdtdtd	td
d tdd t t   D }|d< | d< d8 fdd	}| }t|dkrt	tdd|d |d f  nt	td|d  t
|j}tdt|}	t	td|	 |jd urT|jrDt	td|jd nt	td|j |jd ur|j}
tdt|
}|
| }|dk rtd| }nH|dk rtd|d  }n,|dk rtd |d!  }ntd"|d#  }t	td$|| |jd ur(|jrt	td%|jd nt	td%|j t|ttfrrt }|D ],}||v rTqB|| t	td&| qBnt	td&| t|jttfr|j}|d d u rt	td'dtd(d |dd  }nHt|st	td'td) n*|rjt	td'td*d+d,d |D  nV|jd u r8t	td'dtd(d n2|jrXt	td'td-|j nt	td'td) t|jttfrt }|jD ]}||v rq|| qt	td.| nt	td.|j |jd urt|jttfr|jD ]}t	td/| qnt	td/|j |jd ur`t|jttfrP|jD ]}t	td0| q8nt	td0|j | }|rzt	td1 d}|D ] }tt|}||kr|}q|D ]}||d2d|d3 qt	td4 || |  }|rt	td5 d}|D ]}|d7 }t	d6| | q|! }|rXt	td7 d}|D ]}|d7 }t	d6| | q:d S )9Nc                    s   g | ]}  |qS r$   r5  )r:   r   r^   r$   r%   r;   s  r<   z*Output._historyInfoCmd.<locals>.<listcomp>Z	InstalledZErasedUpgraded
Downgraded)rF   r
  or   zNot installedZOlderZNewerc                 S   s   g | ]}t |qS r$   )r   )r:   r  r$   r$   r%   r;   y  r<   maxlenFr   Tc              	      s   d| }|r}n }|d }j   j| jd }	|	sH|d }nBj|	d }
|
r| |
}|dkrpn|dkr|d }n|d }|r	d\}}n	d	\}}t
||d
 }d}|r|  }td|||||t| |f  d S )Nr2   rF   )rx   r
  r   rg  r   rJ   rK   rh  r   %s%s%s%s %-*s %s)r_   r   r   Zfiltermrx   runr]   packageZcomparerU   r   r   r|   r   )r}   
prefix_lenwas_installedrR   pkg_max_lenZ	show_reporr   Z_pkg_statesstateZipkgsZinst_pkgresrS   rT   Zui_repoZ_pkg_states_availableZ_pkg_states_installedr.   r$   r%   _simple_pkg}  s4    



z+Output._historyInfoCmd.<locals>._simple_pkgr   zTransaction ID :z%u..%ur`   z%czBegin time     :zBegin rpmdb    :z**i,  z(%u seconds)iPF  z(%u minutes)<   i z
(%u hours)i  z	(%u days)iQ zEnd time       :zEnd rpmdb      :zUser           :zReturn-Code    :ZAbortedZSuccessz	Failures:r2  c                 S   s   g | ]}t |qS r$   r  r  r$   r$   r%   r;     r<   zFailure:zReleasever     :zCommand Line   :zComment        :zTransaction performed with:r   )rm  rn  zPackages Altered:zScriptlet output:z%4dzErrors:)FFr   T)"rM  rN   r   r   r  r    r   rV  r   r|   r   rQ  r0  rO  rP  Zbeg_rpmdb_versionrS  Zend_timestampr`  rT  rt   r   r   rR  allr   Z
releaseverrL  commentZperformed_withr   historyInfoCmdPkgsAlteredoutputr   )r.   rK  rc  rM  rx   rh  rr  rV  ZbegtZbegtmZendtZendtmrn   seenrF   ZcodesrL  ru  Z	perf_withZmax_lenZwith_pkgZstr_lenZt_outr"  lineZt_errr$   rq  r%   rb  o  s    


  ) 






&




zOutput._historyInfoCmdr  Dep-Install	Obsoleted
ObsoletingErase	Reinstallr  rf  r  re  )zTrue-Installr  rz  r{  r|  r}  r~  r  rf  ZUpdateZUpdatedc                    s   | j }d}d}| }|D ]@ | j j}|t|k rBt|}tt }||k r|}q|D ] d}	 jtjj	krzd}	d}
|rt
 fdd|D rd}
| |
\}}| j j}tt||}td|	||||t   f  q`d	S )
a  Print information about how packages are altered in a transaction.

        :param old: the :class:`DnfSwdbTrans` to
           print information about
        :param pats: a list of patterns.  Packages that match a patten
           in *pats* will be highlighted in the output
        r   r   z ** rK   c                    s   g | ]}  |qS r$   )r   )r:   patr  r$   r%   r;   A  r<   z4Output.historyInfoCmdPkgsAltered.<locals>.<listcomp>rJ   ri  N)_history_state2uistater   r@   r3  r   r   ro  r  r  ZTransactionItemState_DONEr   rU   r   r
   r|   r   )r.   rK  rc  Zall_uistatesrh  rn  r   ZuistateZpkg_lenrr   rR   rS   rT   r$   r  r%   rv  !  s4    z Output.historyInfoCmdPkgsAltered)Nr   Nr   )r   r   )Fr   FN)Fr   FN)r1   )F)N)NN)NNN)N)F)N)N)F)9__name__
__module____qualname____doc__r   recompiler   r/   r8   rI   rU   rX   staticmethodr\   propertyr]   r_   rA   rp   rq   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r(  r)  r.  r1  r4  r   r[  r   rd  rb  r   r  rv  r$   r$   r$   r%   r'   C   s   

	

  
 


/  
  


V
$
O
-'  
d

/
  ^2
"
MM 'r'   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r,  zGProvides text output callback functions for Dependency Solver callback.c                 C   s   d}|dkrt d}n||dkr(t d}nj|dkr:t d}nX|dkrLt d	}nF|d
kr^t d}n4|dkrpt d}n"|dkrt d}n|dkrt d}|rt||j|j|j dS )a  Print information about a package being added to the
        transaction set.

        :param pkgtup: tuple containing the package name, arch,
           version, and repository
        :param mode: a short string indicating why the package is
           being added to the transaction set.

        Valid current values for *mode* are::

           i = the package will be installed
           u = the package will be an update
           e = the package will be erased
           r = the package will be reinstalled
           d = the package will be a downgrade
           o = the package will be obsoleting another package
           ud = the package will be updated
           od = the package will be obsoleted
        NrF   z'---> Package %s.%s %s will be installedr6  z(---> Package %s.%s %s will be an upgrader
  z$---> Package %s.%s %s will be erasedr  z)---> Package %s.%s %s will be reinstalledrl   z)---> Package %s.%s %s will be a downgraderg  z(---> Package %s.%s %s will be obsoletingZudz&---> Package %s.%s %s will be upgradedZodz'---> Package %s.%s %s will be obsoleted)r   r   debugrx   ry   rz   )r.   r}   moderw  r$   r$   r%   	pkg_addedO  s&    






z"DepSolveProgressCallBack.pkg_addedc                 C   s   t td dS )zRPerform setup at the beginning of the dependency solving
        process.
        z"--> Starting dependency resolutionNr   r  r   r^   r$   r$   r%   startx  s    zDepSolveProgressCallBack.startc                 C   s   t td dS )zAOutput a message stating that dependency resolution has finished.z"--> Finished dependency resolutionNr  r^   r$   r$   r%   rv   ~  s    zDepSolveProgressCallBack.endN)r  r  r  r  r  r  rv   r$   r$   r$   r%   r,  L  s   )r,  c                   @   s   e Zd Zdd Zdd ZdS )CliKeyImportc                 C   s   || _ || _d S r(   )r*   rw  )r.   r*   rw  r$   r$   r%   r/     s    zCliKeyImport.__init__c                 C   sb   dd }t d|||tj||ddf }td| | jjj	rJdS | jjj
rXdS | j S )	Nc                 S   s$   t jjrdnd}| dd  d|S )N0   0ir$  )r   ZpycompZPY3rjust)r   Zrjr$   r$   r%   short_id  s    z'CliKeyImport._confirm.<locals>.short_idzLImporting GPG key 0x%s:
 Userid     : "%s"
 Fingerprint: %s
 From       : %szfile://r   r0   TF)r   r   ZcryptoZ_printable_fingerprintrO   r   r]  r*   r)   Z	assumeyesZassumenorw  r   )r.   r   ZuseridZfingerprintr   Z	timestampr  ru   r$   r$   r%   _confirm  s    



zCliKeyImport._confirmN)r  r  r  r/   r  r$   r$   r$   r%   r    s   r  c                       sN   e Zd ZdZedd Z fddZdd Zdd	 Zd
d Z	dddZ
  ZS )CliTransactionDisplayz1A YUM specific callback class for RPM operations.c                 C   s   t jj S r(   )r   r+   r,   _term_widthr^   r$   r$   r%   r    r<   zCliTransactionDisplay.<lambda>c                    s0   t t|   d| _d | _d| _d| _d| _d S )Nr   Tr1      )superr  r/   lastmsglastpackagerw  markmarksr^   	__class__r$   r%   r/     s    zCliTransactionDisplay.__init__c              
   C   sj   t jj|}|du rdS |  }t|}	|| _|dkr>d}
n|td | }
| |||||
||	| dS )a  Output information about an rpm operation.  This may
        include a text progress bar.

        :param package: the package involved in the event
        :param action: the type of action that is taking place.  Valid
           values are given by
           :func:`rpmtrans.TransactionDisplay.action.keys()`
        :param ti_done: a number representing the amount of work
           already done in the current transaction
        :param ti_total: a number representing the total amount of work
           to be done in the current transaction
        :param ts_done: the number of the current transaction in
           transaction set
        :param ts_total: the total number of transactions in the
           transaction set
        Nr   d   )	r   r  ACTIONSr@   _max_action_widthr
   r  r   _out_progress)r.   rk  r  ti_doneti_totalts_donets_totalZ
action_strwid1pkgnamepercentr$   r$   r%   r-     s    zCliTransactionDisplay.progressc                 C   sD   t | ds:d}tjj D ]}t|}||k r|}q|| _| j}|S )N_max_action_wid_cacher   )hasattrr   r  r  r   r   r  )r.   r  rG   Zwid_valr$   r$   r%   r    s    
z'CliTransactionDisplay._max_action_widthc	                 C   s   | j rtj s||kr| j|||tj ||d\}	}}
t|}|	t|||t||
|
f }|| jkrtj	
d|tj || _||krtd d S )N)r-   r  r  Zwrite_flushr2   )rw  r*  r+  isatty_makefmtr
   r   r  r   r   _terminal_messengerr|   )r.   r  r  r  r  r  Zprocessr  r  rZ  wid2ru   r$   r$   r%   r    s    


z#CliTransactionDisplay._out_progressTN   c                 C   s  t t|}d||f }d| d | d }	|	||f }
|d u rFd}nt|}d| d }|d| d 7 }|d7 }|d7 }|d7 }| j}||k r|}||8 }||d kr|d }| j||  }d||f }d| d	 }|| d }|r|d
krd|
 }|}n|rD|dkr*|| jt||d   f }nd}d| d |
 }|}nL|d
kr\d|
 }|}n4|dkrx|| j| f }nd}d| d |
 }|}|||fS )Nr   %zs/%sr  ra   r   z[%-zs]r  z  %s: %s   r  g      Y@r   z
  %s: %s r2   z  %s: %s   z	  %s: %s )r   r   r   ro   r  r   )r.   r  r  r  r-   r  r  lr   Zfmt_donerY  ZpnlZoverheadro   r  Zfmt_barZfull_pnlrZ  r  Zbarr$   r$   r%   r    sP    


zCliTransactionDisplay._makefmt)TNr  )r  r  r  r  r  ro   r/   r-   r  r  r  __classcell__r$   r$   r  r%   r    s   
   r  c           
      C   s  d}t j sdS | dkr d}n|dkr6t| | }nd}tjj }|du rZ| |krZd}d| |f }|t|d 8 }|dk rd}|du r|d8 }|dk rd}|t	||  }d|||f }n| |krd	t
||||f }nb|d
8 }|dk rd}|d }	|	t|krt|}	||	8 }|t	||  }dt
||	|	|||f }| |krZtjd|t j | |krvtjddt j tjjdt jd dS )aI  Output the current status to the terminal using a simple
    text progress bar consisting of 50 # marks.

    :param current: a number representing the amount of work
       already done
    :param total: a number representing the total amount of work
       to be done
    :param name: a name to label the progress bar with
    rI  Nr   r/  z %d/%dr   ra   z	[%-*s]%sz%s%sr   z%s: [%-*s]%swriter   flush)r   )r*  r+  r  r   r   r+   r,   r  r   r   r   r   r   r  )
rY   totalrx   r  r  ro   rv   Zhashbarrw  Znwidr$   r$   r%   r-    sN    


r-  )N)<r  Z
__future__r   r   r   r   r   r   Zlibdnf.transactionr  ZloggingrC   r=  r  r*  r0  Zdnf.cli.formatr   r   Zdnf.i18nr   r   r	   r
   r   r   r   r   Z
dnf.pycompr   r   r   r   r   Zdnf.yum.rpmtransr   Zdnf.db.historyr   Zdnf.baser   Zdnf.callbackZdnf.cli.progressZdnf.cli.termZdnf.confZ
dnf.cryptoZdnf.transactionZdnf.utilZdnf.yum.miscZ	getLoggerr   r&   objectr'   callbackZDepsolver,  Z	KeyImportr  r  r-  r$   r$   r$   r%   <module>   sb   (
              7