<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
gt`,                 @   sj   d dl mZ d dl mZ d dlZd dlmZ d dlZd dlm	Z	 G dd dej
ZG dd	 d	ejjZdS )
    )absolute_import)unicode_literalsN)OptionParser)_c                   s    e Zd ZdZ fddZ  ZS )RepoDiffrepodiffc                s,   t t| j|| |d krd S |jt d S )N)superr   __init__Zregister_commandRepoDiffCommand)selfbasecli)	__class__ /usr/lib/python3.6/repodiff.pyr	   $   s    zRepoDiff.__init__)__name__
__module____qualname__namer	   __classcell__r   r   )r   r   r       s   r   c               @   sL   e Zd ZdZedZedd Zdd Zdd Z	d	d
 Z
dd Zdd ZdS )r
   r   z1List differences between two sets of repositoriesc          	   C   s   | j ddg ddtdd | j ddg dd	td
d | j dddg tjdtdd | j dddtdd | j ddtdd | j ddtdd | j ddtdd d S )Nz
--repo-oldz-oappendoldz2Specify old repository, can be used multiple times)defaultactiondesthelpz
--repo-newz-nnewz2Specify new repository, can be used multiple timesz--archz
--archlistz-aarcheszhSpecify architectures to compare, can be used multiple times. By default, only source rpms are compared.z--sizez-s
store_truez5Output additional data about the size of the changes.)r   r   z--compare-archzMCompare packages also by arch. By default packages are compared just by name.z--simplez7Output a simple one line message for modified packages.z--downgradezNSplit the data for modified packages between upgraded and downgraded packages.)add_argumentr   r   Z_SplitCallback)parserr   r   r   set_argparser/   s    

zRepoDiffCommand.set_argparserc             C   s   | j j}d|_d|_d|_dg| jj_| jj	 s:| jj
 rNtd}tjj|x<| jjj D ],}|j| jj	| jj
 kr|j  q\|j  q\W | jjsdg| j_d S )NTallz*Both old and new repositories must be set.src)r   demandsZsack_activationZavailable_repos
changelogsr   ZconfZdisable_excludesoptsr   r   r   dnf
exceptionsErrorZreposr"   idenabledisabler   )r   r$   msgZrepor   r   r   	configureM   s    
zRepoDiffCommand.configurec             C   s   | j jr|j|jfS |jS )N)r&   compare_archr   arch)r   pkgr   r   r   _pkgkey`   s    zRepoDiffCommand._pkgkeyc                s6  t fdd|D tj }t fdd|D  t j }t  }x:|j|dD ]*}x$|j|jdD ]}||j|< qlW qXW jjj}t  fdd|| D fdd|| D |g g d}	xj|j	|D ]\}
|
 } |
 }|j
|j
krq||j
|j
d	kr|	d
 j||f q|	d j||f qW |	S )aN  compares packagesets old and new, returns dictionary with packages:
        added: only in new set
        removed: only in old set
        upgraded: in both old and new, new has bigger evr
        downgraded: in both old and new, new has lower evr
        obsoletes: dictionary of which old package is obsoleted by which new
        c                s   g | ]} j ||fqS r   )r2   ).0p)r   r   r   
<listcomp>m   s    z-RepoDiffCommand._repodiff.<locals>.<listcomp>c                s   g | ]} j ||fqS r   )r2   )r3   r4   )r   r   r   r5   o   s    )	obsoletes)Zprovidesc                s   g | ]} | qS r   r   )r3   k)new_dr   r   r5   z   s    c                s   g | ]} | qS r   r   )r3   r7   )old_dr   r   r5   {   s    )addedremovedr6   upgraded
downgradedr   r=   r<   )dictsetkeysfilterr6   r2   r   sackevr_cmpintersectionevrr   )r   r   r   Zold_keysZnew_keysr6   Z	obsoleterZ	obsoletedrC   r   r7   pkg_oldpkg_newr   )r8   r9   r   r   	_repodiffe   s0    
zRepoDiffCommand._repodiffc       
         sh  fdd dd } fdd}t ddddd}x<t|d	 D ],}ttd
j | |d	  |j7  < q@W xjt|d D ]Z}ttdj | |d jj|}|rttdj | |d  |j7  < q~W jj	r|d r:ttd x<t|d D ],\}}|d  |j|j 7  < ||| q
W |d rttd xt|d D ],\}}|d  |j|j 7  < ||| q^W n\|d |d  }	|	rttd x8t|	D ],\}}|d  |j|j 7  < ||| qW ttd ttdjt
|d	  ttdjt
|d  jj	rlttdjt
|d  ttdjt
|d  n&ttdjt
|d t
|d   jjrdttdj||d	  ttdj||d  jj	sttdj||d |d   n4ttdj||d  ttdj||d  ttdj||d	 |d  |d  |d   d S ) Nc                s     j jrt| S d| j| jf S )Nz%s-%s)r&   r/   strr   rE   )r1   )r   r   r   pkgstr   s    z'RepoDiffCommand._report.<locals>.pkgstrc             S   sX   t | }| dkr.|djtjjj| j 7 }n&| dk rT|djtjjj|  j 7 }|S )Nr   z ({})z (-{}))rI   formatr'   r   Zformat_numberstrip)Znumr-   r   r   r   sizestr   s    z(RepoDiffCommand._report.<locals>.sizestrc                sB  g }j jr*|jd |  |f  n|jd |jd |  |f  |jdt|d   | jrv| jd }nd }x|jD ]}|r|d |d k rP n2|d |d kr|d |d kr|d |d krP |jd	|d jd
tjj|d tjj|d f  qW j j	r0|jt
dj|j	| j	  tdj| d S )Nz%s -> %s -   r   Z	timestampZauthortextz
* %s %s
%sz%a %b %d %YzSize change: {} bytes
)r&   Zsimpler   lenr%   Zstrftimer'   Zi18nZucdsizer   rK   printjoin)rF   rG   ZmsgsZ	old_chlogZchlog)rJ   r   r   r   report_modified   s2    

z0RepoDiffCommand._report.<locals>.report_modifiedr   )r:   r;   r<   r=   r:   zAdded package  : {}r;   zRemoved package: {}r6   zObsoleted by   : {}r<   z
Upgraded packagesr=   z
Downgraded packagesz
Modified packagesz
SummaryzAdded packages: {}zRemoved packages: {}zUpgraded packages: {}zDowngraded packages: {}zModified packages: {}zSize of added packages: {}zSize of removed packages: {}zSize of modified packages: {}zSize of upgraded packages: {}zSize of downgraded packages: {}zSize change: {})r>   sortedrV   r   rK   rU   getr2   r&   Z	downgraderT   )
r   r   rM   rX   Zsizesr1   ZobsoletedbyrF   rG   Zmodifiedr   )rJ   r   r   _report   sf    










zRepoDiffCommand._reportc             C   s   | j jjtjj| jjd}| j jjtjj| jjd}| jj	rld| jj	krl|j
| jj	d |j
| jj	d | jjr|j
dd |j
dd n|j
dd |j
dd |j  |j  | j| j|| d S )N)Zreponame*)r0   rP   )Zlatest_per_arch)Zlatest)r   rB   ZqueryhawkeyZIGNORE_EXCLUDESrA   r&   r   r   r   Zfiltermr/   Zapplyr[   rH   )r   Zq_newZq_oldr   r   r   run   s    zRepoDiffCommand.runN)r   )r   r   r   aliasesr   Zsummarystaticmethodr!   r.   r2   rH   r[   r^   r   r   r   r   r
   +   s   &ar
   )Z
__future__r   r   Zdnf.clir'   Zdnf.cli.option_parserr   r]   Zdnfpluginscorer   ZPluginr   r   ZCommandr
   r   r   r   r   <module>   s   