ó
È”Mc           @   sò   d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z d  d l Te j d k  r€ d  d l	 m
 Z d d „ Z e e d	 <n  d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   INSTALLt   REMOVE(   t   PreRequires(   t   *i   i   (   t   Setc            s@   t  |  ƒ } ˆ  r2 ‡  f d †  } | j | ƒ n
 | j ƒ  | S(   Nc            s   t  ˆ  |  ƒ ˆ  | ƒ ƒ S(   N(   t   cmp(   t   at   b(   t   key(    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   mycmp#   s    (   t   listt   sort(   t   iterableR   t   mylistR	   (    (   R   s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   sorted    s    
R   t   DisableErrorc           B   s   e  Z d  Z RS(   sD   Raised on a request to break a non-existent or unbreakable relation.(   t   __name__t
   __module__t   __doc__(    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   ,   s   t   EnableErrorc           B   s   e  Z d  Z RS(   s6   Raised on a request to enable a non-disabled relation.(   R   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   /   s   t   ElementGroupc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  ƒ  |  _ d  S(   N(   t   sett
   _relations(   t   self(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   __init__5   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   getRelations8   s    c         C   s   |  j  j | | f ƒ d  S(   N(   R   t   add(   R   t   succt   pred(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   addPredecessor;   s    c         C   s   |  j  j | | f ƒ d  S(   N(   R   R   (   R   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   addSuccessor>   s    (   R   R   R   R   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   3   s   			t   ElementSorterc           B   s•   e  Z d  „  Z d „  Z d „  Z d „  Z d d d „ Z d „  Z d „  Z	 d d „ Z
 d „  Z d	 „  Z d
 „  Z d d „ Z d d „ Z d „  Z RS(   c         C   s4   i  |  _  i  |  _ i  |  _ t ƒ  |  _ d |  _ d  S(   Ni    (   t   _successorst   _prioritiest
   _predcountR   t	   _disabledt   _maximum_priority(   R   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   D   s
    			c         C   sA   |  j  j ƒ  |  j j ƒ  |  j j ƒ  |  j j ƒ  d |  _ d  S(   Ni    (   R    t   clearR!   R"   R#   R$   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   resetK   s
    c         C   sg   |  j  j | ƒ } | d k r1 t d | ƒ ‚ n  | |  j k rS t d | ƒ ‚ n  |  j j | ƒ d S(   s:   Disable the optional ordering between C{pred} and C{succ}.s)   Ordering between %r and %r doesn't exist.s/   Ordering between %r and %r is already disabled.N(   R!   t   gett   NoneR   R#   R   (   R   t   relationt   priority(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   disableRelationR   s    c         C   s6   | |  j  k r" t d | ƒ ‚ n  |  j  j | ƒ d  S(   Ns+   Ordering between %r and %r is not disabled.(   R#   R   t   remove(   R   R)   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   enableRelation]   s    c         C   s†  |  j  } | g } t ƒ  } t ƒ  } t ƒ  }	 xL| r{| d }
 x5| j |
 d ƒ D]} |
 | f } | |  j k rS | d k sŒ | | k rS | d k s« |  j | | k rS | | k sÃ | | k r=| j | ƒ | j | ƒ g  } x= t t	 | ƒ d ƒ D]% } | j | | | | d f ƒ qú W|	 j | ƒ | j
 ƒ  qj| | k rj| j | ƒ | j | ƒ PqjqS qS W| j
 ƒ  q0 W| |	 f S(   s+  Return all elements and relations leading from C{start} to C{end}.

        The result is a tuple where the first item is the set of elements
        which are involved in paths from C{start} to C{end}, and the second
        item is the relations involved in paths from C{start} to C{end}.
        iÿÿÿÿi   (    N(   R    R   R'   R#   R(   R!   t   appendt   updatet   ranget   lent   popR   (   R   t   startt   endt   follow_relationst   maximum_priorityt
   successorst   patht   seent   elementst	   relationst   lastR   R)   t   relpatht   i(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   getPathDatac   s8    						
#c         C   s  t  ƒ  } g  } xì |  j D]á } | | k r |  j | | ƒ \ } } | rú t  | g ƒ } | | } xo | rÓ | j ƒ  } |  j | | ƒ \ }	 }
 | j |	 ƒ | j |
 ƒ | j | ƒ |	 j | ƒ | j |	 ƒ qe W| j | | f ƒ | j | ƒ qú q q W| S(   sÏ   Return all elements and relations participating in loops.

        The result is the same as for L{getPathData()}, except that only
        elements and relations involved in loops will be returned.
        (   R   R    R?   R2   R/   R   t   difference_updateR.   (   R   t   all_loop_elementst   loopst   elemt   loop_elementst   loop_relationst   donet   todot	   loop_elemt   more_elementst   more_relations(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   getLoops‰   s&    	
	c         C   s;   x4 | D], } |  j  | | d | ƒ} | d r t Sq Wt S(   NR5   i    (   R?   t   Truet   False(   R   R:   R;   RC   t   data(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   hasLoop¤   s
    
c         C   sƒ   d } t  ƒ  } xm | D]e } | | k r |  j | | d | d | ƒ} | d r{ | j | d ƒ | t | d ƒ 7} q{ q q W| S(   Ni    R5   R6   i   (   R   R?   R/   R1   (   R   R:   R;   R6   RE   RD   RC   RN   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   countRelationsInLoop«   s    		
c         C   s«   t  | ƒ } i  } xƒ | D]{ } | j | ƒ |  j | g } x8 t |  j d ƒ D]# } | j |  j | | | ƒ ƒ qP Wt | ƒ | | <| j | ƒ q Wt	 | d | j
 ƒS(   Ni   R   (   R   R,   R!   R0   R$   R.   RP   t   tupleR   R   R'   (   R   R:   R;   R5   t   sort_keyR)   t
   sort_tupleR*   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   _getReenableOrder¸   s    	c   
      C   sÇ   |  j  j ƒ  |  j ƒ  } x§ | D]Ÿ \ } } |  j | | ƒ } x | D] } |  j | ƒ qE Wx` | D]X } | |  j  k rc | \ } } |  j | | d | ƒ\ } }	 | s» |  j | ƒ q» qc qc Wq  Wd  S(   NR5   (   R#   R%   RK   RT   R+   R?   R-   (
   R   RB   RD   RE   t   reenable_orderR)   R   R   R:   R;   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt
   breakLoopsÎ   s    		c         C   s3   | |  j  k r/ t ƒ  |  j  | <d |  j | <n  d  S(   Ni    (   R    R   R"   (   R   RC   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt
   addElementï   s    i    c         C   s   |  j  | | | ƒ d  S(   N(   R   (   R   R   R   R*   (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   ô   s    c         C   s  | | f } |  j  } |  j } | | k rD t ƒ  | | <d | | <n  | | k r€ t | g ƒ | | <d | | <| | c d 7<n4 | | | k r´ | | j | ƒ | | c d 7<n  | |  j k sÖ |  j | | k ræ | |  j | <n  | |  j k r| |  _ n  d  S(   Ni    i   (   R    R"   R   R   R!   R$   (   R   R   R   R*   t   pairR7   t	   predcount(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   ÷   s"    		
"c   	      C   s:  |  j  } |  j j ƒ  } |  j ƒ  x' |  j D] \ } } | | c d 8<q, Wg  | D] } | j | ƒ sS | ^ qS } x˜ | D] } x‡ | j | d ƒ D]s } | | f |  j k r” | j | ƒ } | d  k	 r| d d k rñ | | =| j | ƒ q| | c d 8<qq” q” Wq{ Wt | ƒ t | ƒ k r6t	 d ƒ ‚ n  | S(   Ni   i    s   There are remaining loops(    (
   R    R"   t   copyRV   R#   R'   R(   R.   R1   t   RuntimeError(	   R   R7   RY   R   R   t   xt   resultRC   t   left(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt	   getSorted
  s$    	
(N(   R   R   R   R&   R+   R-   R(   R?   RK   RO   RP   RT   RV   RW   R   R   R_   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   B   s   				%				!	t   ChangeSetSorterc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s'   t  j |  ƒ | r# |  j | ƒ n  d  S(   N(   R   R   t   setChangeSet(   R   t	   changeset(    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR   (  s    c            s   |  j  ƒ  xî| D]æ} | | } | | f } |  j | ƒ g  ‰  ‡  f d †  } xÞ | j D]Ó } t | t ƒ rw d } n d } x¬ | j D]ƒ } xy | j D]k }	 |	 | k r¯ q— n  | j |	 ƒ t k rÝ | |	 t f | | ƒ q— |	 j	 r— | j |	 ƒ t
 k	 rPqq— q— Wq‡ Pq‡ Wx ˆ  D] }
 |  j |
 Œ  qWqY W| t k r g  | j D], } | j D] } | j D] } | ^ q`qSqF} | j g  | j D], } | j D] } | j D] }	 |	 ^ q¢q•qˆƒ xN | D]F } | | k rÚqÂn  | j | ƒ t
 k rÂ|  j | t
 f | ƒ qÂqÂWg  | j D]8 } | j D]( } | j D] }	 |	 | k	 r0|	 ^ q0q#q} | j g  | j D]8 } | j D]( } | j D] } | | k	 r~| ^ q~qqqdƒ xQ | D]F } | | k rÂqªn  | j | ƒ t
 k rª|  j | t
 f | ƒ qªqªWq q Wt |  j ƒ t | ƒ k st ‚ d  S(   Nc            s   ˆ  j  |  | | f ƒ d  S(   N(   R.   (   R   R   R*   (   R;   (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   add_relation5  s    i    i   (   R&   RW   t   requirest
   isinstanceR   t
   providedbyt   packagesR'   R    t	   installedR   R   t   providest
   upgradedbyt   extendt   upgradest	   conflictst   conflictedbyR1   R    t   AssertionError(   R   Rb   t   pkgt   opRC   Rc   t   reqt   req_type_priorityt   prvt   prvpkgt   argst   upgt   upgpkgt   upgpkgst   cnft   cnfpkgst   cnfpkg(    (   R;   s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyRa   -  sf    

	
	 $N(   R   R   R(   R   Ra   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyR`   &  s   (   i   i   (   t   ost   syst   smart.constR    R   t   smart.cacheR   t   smartt   version_infot   setsR   R   R(   R   t   __builtins__t   ErrorR   R   t   objectR   R   R`   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/sorter.pyt   <module>   s   
	ä