
N_c           @   sD   d  d l  Z  d  d l Z  d  d l Z  d   Z d d d     YZ d S(   iNc         C   s   t  j j |  |  S(   N(   t   rpmUtilst	   miscutilst
   compareEVR(   t   tup1t   tup2(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   _vertup_cmp   s    t   Updatesc           B   s  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d d  Z	 d   Z
 d   Z d	   Z d
 d  Z d   Z d   Z d   Z d   Z d d d  Z d d d  Z d d d  Z d d d d  Z d d d d  Z d d d d  Z d d d  Z d d d  Z d   Z RS(   sM  
    This class computes and keeps track of updates and obsoletes.
    initialize, add installed packages, add available packages (both as
    unique lists of name, arch, ver, rel, epoch tuples), add an optional dict
    of obsoleting packages with obsoletes and what they obsolete ie::
        foo, i386, 0, 1.1, 1: bar >= 1.1.
    c         C   s  | |  _  | |  _ i  |  _ d  |  _ i  |  _ i  |  _ d |  _ t d d d d d d d g  |  _	 t
 j j |  _ t
 j j |  j  |  _ t
 j j |  j  |  _ t
 j j |  j  |  _ |  j |  j  d  |  _ |  j |  j d	 d
 |  j |  _ i  |  _ i  |  _ d	 |  _ i  |  _ d  S(   Ni   t   kernels
   kernel-smpt   glibcs   kernel-hugemems   kernel-enterprises   kernel-bigmems   kernel-BOOTi    t   filter(   t	   installedt	   availablet   rawobsoletest   Nonet   _obsoletes_by_namet   obsoleted_dictt   obsoleting_dictt	   exactarcht   sett   exactarchlistR    t   archt	   canonArcht   myarcht   isMultiLibArcht   _is_multilibt   getArchListt	   _archlistt   getMultiArchInfot   _multilib_compat_archest
   makeNADictt   installdictt	   availdictt   updatesdictt   updating_dictt   debugt	   obsoletes(   t   selft   instlistt	   availlist(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   __init__    s,    										c         C   sU   xN | D]F } | | k r q n  t  | j | |  | | <| | s | | =q q Wd  S(   N(   R	   t   __ne__(   R$   t   dict_t   keyst   valuet   key(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   _delFromDictE   s    
c   	      C   s   | \ } } } } } xx | d  f D]j } | | f | k r" t | | | f j | | | f  | | | f <| | | f s | | | f =q q" q" Wd  S(   N(   R   R	   R(   (	   R$   R)   t   pkgtupt   nt   at   et   vt   rt   aa(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   _delFromNADictM   s    /c         C   s9  | |  j  k r d S|  j  j |  |  j |  j |  |  j |  j |  j j | g   |  |  j |  j |  j j | g   |  | |  j k r |  j	 r x@ |  j | D]1 \ } } } |  j |  j	 | g | | | f  q W|  j | =q n  |  j |  j
 |  j j | g   |  |  j |  j |  j
 j | g   |  d S(   s3   remove available pkgtup that is no longer availableN(   R   t   removeR5   R   R-   R!   R    t   getR   R   R   R   (   R$   R.   t   namet   flagt   version(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt
   delPackageU   s    %%	&%c         C   s   |  j  r | GHn  d  S(   N(   R"   (   R$   t   msg(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt
   debugprinth   s    	c   
      C   s+  i  } x| D]\ } } } } }	 | r@ | d f | k r@ q n  | | f | k re g  | | | f <n  | | |	 f | | | f k r q n  | | | f j | | |	 f  | r | d f | k r g  | | d f <n  | | | |	 f | | d f k r q n  | | d f j | | | |	 f  q q W| S(   s   return lists of (e,v,r) tuples as value of a dict keyed on (n, a)
            optionally will return a (n, None) entry with all the a for that
            n in tuples of (a,e,v,r)N(   R   t   append(
   R$   t   pkglistt	   NonelistsR	   t
   returndictR/   R0   R1   R2   R3   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyR   l   s      "*c   	      C   s   t  |  d k r! t j d  n  t  |  d k r; | d S| d \ } } } xc | d D]W \ } } } t j j | | | f | | | f  } | d k rY | } | } | } qY qY W| | | f S(   s;   takes a list of (e, v, r) tuples and returns the newest onei    s%   Zero Length List in returnNewest calli   (   t   lenR    t   RpmUtilsErrorR   R   (	   R$   t   evrlistt   new_et   new_vt   new_rR1   R2   R3   t   rc(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   returnNewest   s    'c         C   s   g  } d } x | D] } | \ } } }	 }
 } | | k r | | k r |	 |
 | f } | d k sv t | |  d k  r | } g  } n  | | k r | j |  q q q W| S(   s   returns a list of package tuples in a list (n, a, e, v, r)
           takes a package name, a list of archs, and a list of pkgs in
           (n, a, e, v, r) form.i    N(   R   R   R>   (   R$   R8   t   archlistR?   t
   returnlistt   high_vertupR.   R/   R0   R1   R2   R3   t   vertup(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt"   returnHighestVerFromAllArchsByName   s    	c         C   sZ   xS |  j  D]H } t |  j  |  d k r
 |  j  | } t j j |  |  j  | <q
 q
 Wd S(   s+   remove any accidental duplicates in updatesi   N(   R    RB   R    R   t   unique(   R$   t   tupt   mylist(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   condenseUpdates   s    i   c         C   s  |  j  d k rz i  |  _  x_ |  j j   D]K \ } } x< | D]4 \ } } } |  j  j | g   j | | | f  q; Wq( Wn  i  } x | D] } | d } x |  j  j | g   D]k \ }	 }
 } |	 d k r | | d k r q n  t j j	 | |	 |
 f |  r | j | g   j |  q q Wq W| s*i  S| j
   } | rN|  j |  } n  i  } xM | D]E } x< | | D]0 } | | k rg  | | <n  | | j |  qlWq[W| S(   s   accept a list of packages to check to see if anything obsoletes them
           return an obsoleted_dict in the format of makeObsoletedDicti    N(   Ni    (   R   R   R   t	   iteritemst
   setdefaultR>   R7   R    R   t
   rangeCheckR*   t   _reduceListNewestByNameArch(   R$   R?   t   newestR.   R#   R8   R9   R:   t   obsdictt   obs_flagt   obs_versiont
   obsoletingt   obslistRA   t   newt   old(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   checkForObsolete   s4    	
% $c         C   s<  i  } i  } xJ |  j  D]? \ } } } } } | | k rD g  | | <n  | | j |  q Wx|  j  D]} | \ }	 }
 } } } x|  j  | D]\ } } \ } } } | d f |  j k r xa|  j | d f D]I\ } } } } | d k s!t j j | | | | | f f | | | | | f  r d } |	 d f |  j k rxm |  j |	 d f D]U \ } } } } | | | f } | | | f } |  j | | f  | k rPd } PqPqPWn  | |
 k r| | |	 k rd } n  | r| | k rg  | | <n  | | j | | | | | f  qq q Wq q Wqc W| |  _ |  j	   d S(   sv   figures out what things available obsolete things installed, returns
           them in a dict attribute of the class.i    i   N(   Ni    (
   R   R>   R   R   R    R   RU   RI   R#   t   makeObsoletedDict(   R$   RX   t
   obs_archesR/   R0   R1   R2   R3   R.   R8   R   t   epocht   vert   relt   obs_nR9   t   obs_et   obs_vt   obs_rt   rpm_at   rpm_et   rpm_vt   rpm_rt   willInstallt   ins_at   ins_et   ins_vt   ins_rt   pkgvert   installedver(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   doObsoletes   s<    
&&&	5	c         C   s   i  |  _  x\ |  j D]Q } xH |  j | D]9 } | |  j  k rL g  |  j  | <n  |  j  | j |  q' Wq Wi  |  _ xJ |  j  j   D]9 \ } } x* | D]" } |  j j | g   j |  q Wq Wd S(   s   creates a dict of obsoleted packages -> [obsoleting package], this
           is to make it easier to look up what package obsoletes what item in 
           the rpmdbN(   R   R#   R>   R   RS   RT   (   R$   R]   R^   t	   obsoletedt   obsoletingsR[   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyR`     s    		c   "   
      s
  g  } g  } i  } |  j  } |  j } x9 | j   D]+ \ } } | | k r1 | | | f =q1 q1 q1 Wx | D] \ } } |  j | | | f  \ } }	 }
 xc | | | f D]P \ } } } | |	 |
 f | | | f k r | | | f j | | | f  q q Wqg Wx| D] \ } } | | f |  j k rx |  j | | f D] \ } } } y& |  j | | | f  \ } } } Wn t j k
 rq;q;Xt j j	 | | | f | | | f  } | d k r;y$ | | | f j | | | f  Wqt
 k
 rqXq;q;WqqWxS | j   D]E   t   f d   |    } | j   d d
 f g   j |  qWx4 | j   D]& } t | |  d k rf| | =qfqfWx| D]\ } } | d
 k rqn  | d
 f |  j k rg  } g  } x1 | | d
 f D] \ } } } } | j |  qWx4 |  j | d
 f D] \ } } } } | j |  qWt |  d k set |  d k r|  j d |  | j |  q|  j d |  | j | | f  qqWx1| D])\ } } | |  j k r| | f |  j k r|  j |  j | | f  \ } } } | | f | k r|  j | | | f  \ } } } t j j	 | | | f | | | f  } | d k r| | | | | f | k rg  | | | | | | f <n  | | | | | | f j | | | | | f  qqqq|  j | d
 f d \ } } } } | d
 f | k rx | | d
 f D] \ } } } } t j j	 | | | f | | | f  } | d k r,| | | | | f | k rg  | | | | | | f <n  | | | | | | f j | | | | | f  q,q,WqqWg  } |  j r{|  j t j j k r|  j g } n |  j t j j |  j g } | j d  |  j d } t j j |  } t |  t |  g } n t |  g } x2| D]*} x!| D]} g  } xC |  j | d
 f D]. \ } } } } | j | | | | | f  qW|  j | | |  } |  j | d  } | |  j k rg  } x@ | | d
 f D]. \ } } } } | j | | | | | f  q=W|  j | | |  } |  j | d  }  x| D]\ } } | | f |  k r|  j d | | f  | | | f d \ } } } |  | | f d \ } } } t j j	 | | | f | | | f  } | d k r| | | | | f | k rvg  | | | | | | f <n  | | | | | | f j | | | | | f  qqqWq|  j d |  g  }! x! | D] \ } } |! j |  qWt j j |! d	 |  j } | d
 k r	qn  g  } x@ | | d
 f D]. \ } } } } | j | | | | | f  q1	W|  j | | |  } |  j | d  }  g  } x! |  D] \ } } | j |  q	Wt j j | d	 |  j } | d
 k r	qn  | | | f d \ } } } |  | | f d \ } } } t j j	 | | | f | | | f  } | d k r| | | | | f | k r
g  | | | | | | f <n  | | | | | | f j | | | | | f  qqWqW| |  _ |  j   d
 S(   s   check for key lists as populated then commit acts of evil to
           determine what is updated and/or obsoleted, populate self.updatesdict
        i    c            s      d |  d |  d |  d f S(   Ni   i    i   (    (   t   x(   t   na(    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   <lambda>Q  s    i   s   putting %s in complex updates   putting %s in simple updatet   noarchs   processing %s.%ss   processing %sR   N(    R   R   R*   RI   R6   R   R    RC   R   R   t
   ValueErrort   mapRT   R   t   extendRB   R>   R=   R   R   R   R   t   multilibArchest   archesR   R   R   RN   R   t   getBestArchFromListR    t   makeUpdatingDict("   R$   t   simpleupdatet   complexupdatet
   updatedictt   newpkgsRJ   R/   R0   RE   RF   RG   R1   R2   R3   Rj   Rk   Rl   RH   t
   all_archest   nakeyt   installarchst
   availarchsRi   t	   archlistst   biarchest   multicompatt   multiarchlistt   thisarchlistt   tmplistt   highestinstalledpkgst   hipdictt   highestavailablepkgst   hapdictt	   instarchs(    (   Rx   s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt	   doUpdates  s   		
"!+#&'$'#&$%"';##'=	& 	# 	'<# 	':	c         C   sl   i  |  _  x\ |  j D]Q } xH |  j | D]9 } | |  j  k rL g  |  j  | <n  |  j  | j |  q' Wq Wd S(   s   creates a dict of available packages -> [installed package], this
           is to make it easier to look up what package  will be updating what
           in the rpmdbN(   R!   R    R>   (   R$   R^   R]   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyR     s    	c   
      C   s   g  } | s | r x | D] \ } } } } }	 | re | | k re | j  | | | | |	 f  q qe n  | r | | k r | j  | | | | |	 f  q q q q Wn | } | S(   s?   returns a set of pkg naevr tuples reduced based on name or arch(   R>   (
   R$   R?   R8   R   RK   R/   R0   R1   R2   R3   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   reduceListByNameArch  s    	c         C   sE  g  } x< |  j  D]1 } x( |  j  | D] } | j | | f  q$ Wq Wg  } | r xW | D]L \ \ } } }	 }
 } } | | k rX | j | | |	 |
 | f | f  qX qX Wn  | rxW | D]L \ \ } } }	 }
 } } | | k r | j | | |	 |
 | f | f  q q Wn  x3 | D]+ } y | j |  Wqt k
 r<qXqW| S(   s`   returns updates for packages in a list of tuples of:
          (updating naevr, installed naevr)(   R    R>   R6   R{   (   R$   R8   R   RK   t   oldtupt   newtupR   R/   R0   R1   R2   R3   t   item(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getUpdatesTuples  s&    ",",c         C   sX   g  } x6 |  j  D]+ } x" |  j  | D] } | j |  q$ Wq W|  j | | |  } | S(   s5   returns updating packages in a list of (naevr) tuples(   R    R>   R   (   R$   R8   R   RK   R   R   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getUpdatesList,  s    i    c      	   C   s(  g  } |  j  j   } | r- |  j |  } n  x9 | D]1 } x( |  j  | D] } | j | | f  qH Wq4 Wg  } | s{ | rx | D] \ } \ }	 }
 } } } | r | |	 k r | j | |	 |
 | | | f f  q q n  | r | |
 k r| j | |	 |
 | | | f f  q qq q Wn | } | S(   sA  returns obsoletes for packages in a list of tuples of:
           (obsoleting naevr, installed naevr). You can specify name and/or
           arch of the installed package to narrow the results.
           You can also specify newest=1 to get the set of newest pkgs (name, arch)
           sorted, that obsolete something(   R#   R*   RV   R>   (   R$   RW   R8   R   R   R\   t   obstupt   rpmtupRK   R/   R0   R1   R2   R3   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getObsoletesTuples:  s(    ""	"c         C   s(  g  } |  j  j   } | r- |  j |  } n  x9 | D]1 } x( |  j  | D] } | j | | f  qH Wq4 Wg  } | s{ | rx | D] \ \ }	 }
 } } } } | r | |	 k r | j |	 |
 | | | f | f  q q n  | r | |
 k r| j |	 |
 | | | f | f  q qq q Wn | } | S(   sB  returns obsoletes for packages in a list of tuples of:
           (obsoleting naevr, installed naevr). You can specify name and/or
           arch of the obsoleting package to narrow the results.
           You can also specify newest=1 to get the set of newest pkgs (name, arch)
           sorted, that obsolete something(   R#   R*   RV   R>   (   R$   RW   R8   R   R   R\   R   R   RK   R/   R0   R1   R2   R3   t   insttup(    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getObsoletersTuples]  s(    ""	"c         C   s@   |  j  j   } | r' |  j |  } n  |  j | | |  } | S(   s^  returns obsoleting packages in a list of naevr tuples of just the
           packages that obsolete something that is installed. You can specify
           name and/or arch of the obsoleting packaging to narrow the results.
           You can also specify newest=1 to get the set of newest pkgs (name, arch)
           sorted, that obsolete something(   R#   R*   RV   R   (   R$   RW   R8   R   R   RK   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getObsoletesList  s
    c         C   sj   g  } x] |  j  D]R } xI |  j  | D]: } | \ } } } }	 }
 | | k r$ | j |  q$ q$ q$ Wq W| S(   s:   returns a list of pkgtuples obsoleting the package in name(   R#   R>   (   R$   RW   R8   RK   R]   R   R/   R0   R1   R2   R3   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getObsoletedList  s    c         C   s   i  } i  } g  } x |  j    D] } d | | <q Wx |  j D] } d | | <q= Wx9 |  j D]. } | | k r[ | | k r[ | j |  q[ q[ W|  j | | |  } | S(   s   returns a naevr tuple of the packages that are neither installed
           nor an update - this may include something that obsoletes an installed
           packagei   (   R   R
   R   R>   R   (   R$   R8   R   t   updatest   instR   R.   RK   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   getOthersList  s    c         C   s   i  } t  } x | D] } | \ } } } } }	 | | f | k rS | | | | f <q | | | f }
 t } |
 \ } } } } } t j j | | |	 f | | | f  } | d k r | | | | f <q q W| s | S| j   S(   s   return list of newest packages based on name, arch matching
           this means(in name.arch form): foo.i386 and foo.noarch are not 
           compared to each other for highest version only foo.i386 and 
           foo.i386 will be comparedi    (   t   Falset   TrueR    R   R   t   values(   R$   t	   tuplelistt   highdictt   doneR.   R/   R0   R1   R2   R3   t   pkgtup2t   n2t   a2t   e2t   v2t   r2RH   (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyRV     s    'N(   t   __name__t
   __module__t   __doc__R'   R-   R5   R;   R=   R   R   RI   RN   RR   R_   Rt   R`   R   R   R   R   R   R   R   R   R   R   RV   (    (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyR      s0   	%								#	.			##(    (   R    t   rpmUtils.miscutilst   rpmUtils.archR   R   (    (    (    s4   /usr/lib/python2.7/site-packages/rpmUtils/updates.pyt   <module>   s   	