
ȔMc           @   s  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	 m
 Z
 m Z d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l  m! Z! d  d l" Td  d l# Td  d l$ Td  d l% Te j& d d f k  rrd  d l' m( Z) n  d e* f d     YZ+ d e* f d     YZ, d e* f d     YZ- d   Z. d S(   iN(   t	   ChangeSett   ChangeSetSplittert   INSTALLt   REMOVE(   t   compareFilest   setCloseOnExecAll(   t   getObjectDigest(   t	   PathLocks(   t	   strToBool(   t   Metalinkt   Metafile(   t   Searcher(   t   MediaSet(   t   Progress(   t   Fetcher(   t   Report(   t   *i   i   (   t   Sett   Controlc           B   s  e  Z d* e d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d Z d* d  Z d* d  Z d   Z d   Z d   Z d* e d  Z d* d  Z d* d  Z d* d  Z d* d  Z d* d  Z e e d* d  Z d* e d* d  Z d* e d* d  Z  e! e" d  Z# e! d* e" d  Z$ e! d* d  Z% d* d* d  Z& d* d* d  Z' d    Z( e! e" d!  Z) e! e" d"  Z* e! e" d#  Z+ e! e" d$  Z, e! d* d%  Z- d& d' d& d( e" d)  Z. RS(+   c         C   s   d  |  _ i  |  _ i  |  _ i  |  _ t |  |  _ t   |  _ |  j	 |  t
   |  _ |  j j   |  _ t |  j  |  _ t |  _ d  S(   N(   t   Nonet	   _confpatht	   _channelst   _sysconfchannelst   _dynamicchannelsR   t
   _pathlockst   Cachet   _cachet   loadSysConfR   t   _fetchert   getMediaSett	   _mediasett   AvailableChannelSett	   _achansett   Falset   _cachechanged(   t   selft   confpatht
   forcelocks(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   __init__4   s    				c         C   s   |  j  j   S(   N(   R   t   values(   R#   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   getChannelsC   s    c         C   so   |  j  | } t | t  r) | j   n  |  j  | =| |  j k rO |  j | =n  | |  j k rk |  j | =n  d  S(   N(   R   t
   isinstancet   PackageChannelt   removeLoadersR   R   (   R#   t   aliast   channel(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   removeChannelF   s    
c         C   s/   g  |  j  j   D] } t | t  r | ^ q S(   N(   R   R'   R)   t   FileChannel(   R#   t   x(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   getFileChannelsP   s    c         C   su   t  j j |  rq t d  t j d |   r1 t St  j j |  rq t  j j	 |  d k rq t
 j |  rq t Sn  t S(   Ns   check-package-filei    (   t   ost   patht   existst   filterR   t   hookst   callt   Truet   isfilet   getsizet   tarfilet
   is_tarfileR!   (   R#   t   arg(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   checkPackageFileT   s    *c         C   s  |  j  s |  j   n  t } xm t j d |  D]Y } | r/ | j   |  j k rl t t d  | j    n  | |  j | j   <t	 } q/ q/ W| rt
 j |  rt j   } t j d | | f  t
 j | d  } | j   } x! | D] } | j | d | q W| j   t j |  } x | D] }	 t j j | |	  }
 t j j |
  r|	 d k rx6 t j |
  D]" } | j t j j |
 |   qpWn  t j j |
  r'|  j |
  r'|  j |
  t	 } q'q'Wn  | st t d  |  n  d  S(   Ns   create-file-channels'   There's another channel with alias '%s's   Extracting from %s to %st   rR3   t   RPMSs%   Unable to create channel for file: %s(   R   t   rebuildSysConfChannelsR!   R6   R7   t   getAliasR   t   Errort   _R8   R;   R<   t   tempfilet   mkdtempt   ifacet   debugt   opent   getnamest   extractt   closeR2   t   listdirR3   t   joint   isdirt   appendR9   R>   t   addFileChannel(   R#   t   filenamet   foundR-   t   tempdirt   tarballt   namest   namet   filest   fileR3   t   rpm(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyRQ   ]   s:    	
#!c         C   sr   t  j j |  } xY |  j j   D]5 } t | t  r" | j   | k r" | j   Pq" q" Wt	 t
 d  |  d  S(   Ns   Channel not found for '%s'(   R2   R3   t   abspathR   R'   R)   R/   t   getFileNameR+   RC   RD   (   R#   RR   R-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   removeFileChannel~   s    
c         C   s   g  | D]$ } | j    r t |  | f ^ q } | s; t S| j   g  | D] \ } } | ^ qL } |  j j   t j |  s t S|  j j	   t S(   N(
   t   isRemovablet   strR8   t   sortR   t	   umountAllRG   t   insertRemovableChannelsR!   t   mountAll(   R#   t   channelsR0   t	   removableRW   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   askForRemovableChannels   s    1
c         C   s   |  j  S(   N(   R   (   R#   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   getCache   s    c         C   s   |  j  S(   N(   R   (   R#   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt
   getFetcher   s    c         C   s   |  j  S(   N(   R   (   R#   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR      s    c         C   s   |  j  j   d  S(   N(   R   t   restoreState(   R#   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   restoreMediaState   s    i   c         C   sA  t  j d  } | r_ t j j |  } t j j |  sO t t d  |  n  t  j |  n7 t j j	 | t
  } t j j |  r t  j |  n  | |  _ t j j |  r t j | t j  } n> y t j |  t } Wn$ t k
 rt t d  |  n X| r/|  j j | d t r/t } n  t  j |  d  S(   Ns   data-dirs    Configuration file not found: %ss   Can't create datadir at %st	   exclusive(   t   sysconft   getR2   R3   t
   expanduserR9   RC   RD   t   loadRN   t   CONFFILER   RO   t   accesst   W_OKt   makedirsR8   t   OSErrorR   t   lockR!   t   setReadOnly(   R#   R$   t   datadirt   writable(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR      s(    	
	c         C   s  |  j  j   } | j   rA t j   rA t j d | j    n  | r\ t j j	 |  } nt j   rl d  S|  j
 rLt j j t j d  d  } t j d t  r't j t d   t | d d  } |  j |  j |  j |  j f } t j | | d  | j   t j | d |  t j   qLt j j |  rLt j |  qLn  t j   s\d  St j   |  j } t j  |  d  S(	   Ns   mirrors-historys   data-dirt   caches
   disk-caches   Saving cache...s   .newt   wi   (!   R   t   getMirrorSystemt   getHistoryChangedRl   t   getReadOnlyt   sett
   getHistoryR2   R3   Rn   R"   RN   Rm   R8   RG   t
   showStatusRD   RI   t   __stateversion__R   R   R   t   cPicklet   dumpRL   t   renamet
   hideStatusR9   t   unlinkt   getModifiedt   resetModifiedR   t   save(   R#   R$   t   msyst	   cachepatht	   cachefilet   state(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   saveSysConf   s6    	

	c         C   s   t  j d i   } x |  j j   D] } t | t  r" | j   } | r xV | D]K } t j | |  } | j	 t j | j | g     | j
   | | <qP Wq q" q" W|  j j   } | j |  | j   s | j t  j d g    n  d  S(   Nt   mirrorss   mirrors-history(   Rl   Rm   R   R'   R)   t   MirrorsChannelt
   getMirrorst   dictt   fromkeyst   updatet   keysR   R{   t
   setMirrorsR   t
   setHistory(   R#   R   R-   t   cmirrorst   originR~   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   reloadMirrors   s    "c            s  t  j d d  } t  j d d      r<   j d    n    f d   } | r|  j rt j j t  j d  d  } t j j |  rt  j d t  rt	 j
 t d	   t |  } y/ t j |  } | d
 |  j k r t  n  Wnf t  j d  t k rd d  l } | j   n  t j t j j |  t j  rt j |  qnf X| \ } |  _ |  _ |  _ xG |  j j   D]6 } | | k s| | | |  r|  j |  qqW| j   t	 j   qn  x | D] } | | }	 | | |	  sqn  | |  j j   k rm|  j | |	 k r-qqm|  j | }
 t |
 t  rV|
 j    n  |  j | =|  j | =n  t! | |	  }
 |	 |  j | <|
 |  j | <qWxF |  j j   D]5 } | | k s| | j d  r|  j |  qqWd  S(   NRd   s   force-channelst    t   ,c            s     r |    k S| j  d  S(   Nt   disabled(   Rm   (   R,   t   data(   t   forcechannels(    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt	   isEnabled   s    
s   data-dirRy   s
   disk-caches   Loading cache...i    s	   log-leveliR   (    ("   Rl   Rm   t   splitR   R2   R3   RN   R9   R8   RG   R   RD   RI   R   Ro   R   t   StateVersionErrort   DEBUGt	   tracebackt	   print_excRq   t   dirnameRr   R   R   R   R   R.   RL   R   R)   R*   R+   t   createChannel(   R#   Rd   R   R   R   R   R   R   R,   R   R-   (    (   R   s1   /usr/lib/python2.7/dist-packages/smart/control.pyRA      sZ    $!


c         C   s   x$ |  j  j   D] } |  j |  q Wi  } xl t j d  D][ } | r= xL | D]A } | j   } | |  j k r t t d  |  n  | | | <qP Wq= q= W|  j j	 |  |  j  j	 |  d  S(   Ns   rebuild-dynamic-channelss'   There's another channel with alias '%s'(
   R   R   R.   R6   R7   RB   R   RC   RD   R   (   R#   R,   t   newchannelsRd   R-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   rebuildDynamicChannels-  s    
c      	   C   s  | d  k rH t } |  j   |  j   |  j j   } t j d |  n t } t	 j
 j t j d  d  } t	 j
 j t j d  d  } t	 j
 j |  s y t	 j |  Wq t k
 r t t d   q Xn  | t k rPt j   r)t	 j | t	 j  r)t j t d   t j t d   n  |  j j |  st t d   qnH t j   rnt t d	   n* |  j j | d
 t st t d   n  |  j j | d t | t k rt   } nK t j |  j t  } i  } x- |  j j    D] } t | | j! | j" f <qW| j#   d }	 x | D] }
 |	 |
 j$   7}	 q(W| j% d |	  |  j&   |  j j' t  |  j j(   t } x| D]}
 |
 j)   } | r|
 j*   r|  j j+ t  nX |  j j+ |  |
 j$   d k r| j, t d  |
 j-   p|
 j.    | j/   n  |  j j0 |
 j1    |  j j2 |
 j.   d  y9 |
 j3 |  j |  s~t j4 t d  |
  t } n  WnC t k
 r} t j5 t6 |   t j4 t d  |
  t } n X|
 j)   | k rt7 |
 t8  r|
 j9 |  j  |
 j.   |  j: k rt |  _; qqqW| rI| t k	 rIt j% d t< j<    n  |  j j' t  |  j j0 t  |  j j2 d   | j=   | j/   | j>   |  j j?   | t k	 rt@ jA d  xQ |  j j    D]= } | j! | j" f | k rt@ jB d | j! d | j"  qqWn  x | | f D] } t	 j | t	 j  r|  j jC   } | jD tE jF t j d d    xd t	 jG |  D]P } | jH d  } | d k s| |  | k rzt	 jI t	 j
 j | |   qzqzWqqW|  j j |  | S(   Ns   reload-channelss   data-dirs	   channels/s   user-data-dirs#   Unable to create channel directory.s7   The Smart library is already in use by another process.s"   Configuration is in readonly mode!s*   Channel information is locked for writing.s'   Can't update channels in readonly mode.Rk   s*   Can't update channels with active readers.t   manglei    s    Fetching information for '%s'...s   %%s   Failed fetching channel '%s's   last-updatet   newt   =Rd   i(    (J   R   R!   RA   R   R   R'   R6   R7   R8   R2   R3   RN   Rl   Rm   RO   Rs   Rt   RC   RD   t   ALWAYSR}   Rq   Rr   RG   t   warningR   Ru   R   t   setLocalDirR   t   getProgressR   t   getPackagesRW   t   versiont   startt   getFetchStepsR~   R   t   setForceMountedCopyt   resett	   getDigestt   hasManualUpdatet
   setCachingt   setTopict   getNameRB   t   showt   setForceCopyR^   t   setLocalPathPrefixt   fetchRH   t   errort   unicodeR)   R*   t
   addLoadersR   R"   t   timet
   setStoppedt   stopRo   t   pkgconft	   clearFlagt   setFlagt   copyR   R   R   RM   t   findR   (   R#   Rd   t   cachingt   manualt   channelsdirt   userchannelsdirt   progresst   oldpkgst   pkgt   stepsR-   t   resultt   digestt   et   dirt   aliasest   entryt   sep(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   reloadChannels<  s    

	!





&"*c         C   si  | d  k r i  } n  |  j j   } t j d |  } i  } xE | D]= } | j rC | | k rC | j |  t k rC t | | <qC qC W| j	   } x | r"| j
 d  } xt | j D]i } x` | j D]U } xL | j D]A }	 |	 j r |	 | k r |	 | k r t | |	 <| j |	  q q Wq Wq Wq Wt |  j  }
 x0 | D]( } | j r9| | k r9t |
 | <q9q9W|
 S(   Nt   autoi    (   R   R   R   R   t   filterByFlagt	   installedRm   R   R8   R   t   popt   requirest
   providedbyt   packagesRP   R    (   R#   t	   changesett   allR   t   markedR   t   queuet   reqt   prvt   prvpkgt   suggestions(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   markAndSweep  s2    			
 	c         C   s@   | j    } |  j g  | D] } | | t k r | ^ q  d  S(   N(   t   getChangeSett   dumpURLsR   (   R#   t   transt   outputR   R0   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   dumpTransactionURLs  s    c   	      C   s   | d  k r t j } n  g  } xx | D]p } g  | j D] } | j   s5 | ^ q5 } | so t t d  |  n  | d j |  } | j | j	    q% Wx | D] } | | IJq Wd  S(   Ns+   Package %s is not available for downloadingi    (
   R   t   syst   stderrt   loaderst   getInstalledRC   RD   t   getInfot   extendt   getURLs(	   R#   R   R   t   urlsR   R0   R   t   infot   url(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR     s    (
c         C   s@   | j    } |  j g  | D] } | | t k r | ^ q  d  S(   N(   R   t   dumpMetalinkR   (   R#   R   R   R   R0   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   dumpTransactionMetalink  s    c         C   s  | d  k r t j } n  t   } |  j j   } xY| D]Q} g  | j D] } | j   sG | ^ qG } | s t t	 d  |  n  | d j
 |  } | j   s t t	 d  |  n  x | j   D] }	 t | j | j | j    }
 | j |	  } g  } | j   } x# | r-| j |  | j   } qW|
 j | d | j |	  d | j |	  d | j |	  d | j |	  | j |
  q Wq7 W| r| j |  n  d  S(   Ns+   Package %s is not available for downloadingi    t   sizet   md5t   shat   sha256(   R   R   R   R	   R   R{   R   R   RC   RD   R   R   R
   RW   R   t
   getSummaryRm   t   getNextRP   t   getSizet   getMD5t   getSHAt	   getSHA256t   write(   R#   R   R   t   metalinkR   R   R0   R   R   R   t   metafilet   mirrort
   mirrorurlst	   mirrorurl(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR     s:    	(

	c   	      C   s   | d  k r t j } n  t   } | r7 | j t  n  | rM | j t  n  g  | j   j   D] \ } } | | k r` | ^ q` } | j	   x: | D]2 } t
 j d t  r | | IJq | | j IJq Wd  S(   Ns   dump-versions(   R   R   R   R~   t   addR   R   R   t   itemsR`   Rl   Rm   R8   RW   (	   R#   R   t   installt   removeR   t   opsR   t   opt   pkgs(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   dumpTransactionPackages  s    	7
c         C   s   |  j  } | j   |  j   | d  k r t j j t j d  d  } t j j	 |  si t j
 |  n  | j | d t n | j | d t | j |  x | D] } | j |  q W| j d |  | j   | j   f S(   Ns   data-dirs   tmp/R   t   what(   R   R   R   R   R2   R3   RN   Rl   Rm   RO   Rs   R   R8   R!   R   t   enqueuet   runt   getSucceededSett   getFailedSet(   R#   t   urllstR  R   t	   targetdirt   fetchert   localdirR   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   downloadURLs  s    	

c   
      C   s  |  j  } | j   |  j   | d  k r t j j t j d  d  } t j j	 |  si t j
 |  n  | j | d t n | j | d t | j |  xO t j t |   j   D]2 } | j   } | j   }	 | j | d |	  q W| j d |  | j   | j   f S(   Ns   data-dirs   tmp/R   i    R  (   R   R   R   R   R2   R3   RN   Rl   Rm   RO   Rs   R   R8   R!   R   R	   t   parseRI   RX   R   R   R  R  R  R  (
   R#   R  R  R   R  R  R  R  R   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   downloadMetalink0  s     	

"c         C   s   |  j  | j   | d | S(   Nt   confirm(   t   downloadChangeSetR   (   R#   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   downloadTransactionD  s    c         C   sP   | r t  j |  r t S|  j g  | D] } | | t k r' | ^ q' | |  S(   N(   RG   t   confirmChangeSetR!   t   downloadPackagesR   (   R#   R   R   R  R   R0   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR!  H  s
    c         C   s   t  |  } d } x t r |  j |  s. t S|  j j |  g  } x4 | D], } |  j j |  rK | j | |  qK qK W|  j | | |  | t	 |  7} | t	 |  k r Pq q Wt S(   Ni    (
   t   getChannelsWithPackagesR8   Rf   R!   R    t   setChannelst   isAvailableR   t   fetchPackagest   len(   R#   R   R   R  Rd   t   fetchedt	   fetchpkgsR-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR$  P  s    	c         C   s   t  |  } d } i  } x t r |  j j |  g  } x4 | D], } |  j j |  r> | j | |  q> q> W| j |  j | t |   | t	 |  7} | t	 |  k r Pq q Wg  }	 x# | D] }
 |	 j
 | |
 d  q W|  j |	 | |  d  S(   Ni    (   R%  R8   R    R&  R'  R   R   R(  t   OPTIONALR)  RP   t	   packFiles(   R#   R   R  t
   outputnameRd   R*  t   pkgpathsR+  R-   RX   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   packPackagesa  s"    	c   
      C   sU  t  j |  t  } | j   | j t d   | r> | } n d } | j d  sk t j j	 | |  } n  t
 j | d  } t |  } d } x | D] }	 | j | |  | j |	 t j j |	   | j |	 d d  | j   | j |	 t j j |	  t  | j |	  | j   | d 7} q W| j   | j   | j   | j   d  S(   Ns   Creating pack...s   pack.tart   /Rz   i   i    (   RG   R   R8   R   R   RD   t
   startswithR2   R3   RN   R;   RI   R)  R~   t   setSubTopict   basenamet   setSubR   R  R!   t
   setSubDoneRL   t   setDoneR   (
   R#   RX   R  R.  t   progRR   RU   t   totalt   currentRY   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR-  t  s0    
	




c         C   s   t  j d d  } | d k r" d St j j t  j d  d  } t j j |  sb t j |  n  t | | d  } x2 | D]* } | j	 d t
 j   | | | f  q| W| j	 d  d S(   s    writes the operations performed in the current changeset
            to a log file specified with via the sysconf"commit-log"
            variable
        s
   commit-logNs   data-dirs   logs/t   as
   %s %s: %s
s   
(   Rl   Rm   R   R2   R3   RN   RO   Rs   RI   R  R   t   ctime(   R#   R   t   logfilet   logdirt   logR   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   writeCommitLog  s    (c         C   s   |  j  | j   | |  S(   N(   t   commitChangeSetR   (   R#   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   commitTransaction  s    c         C   su  | r t  j |  r t S| s0 t  j |  n  t j d  rC t St   i  } xD | D]< } | j } | | k r | g | | <qW | | j	 |  qW Wt
 g  | D] } | | t k r | ^ q  } t j d  }	 t |  }
 t |  j  } i  } xkt rc|  j |  st S|  j j |  |
 j   |
 j t j | t   | j   } xc | D][ } |  j j |  sXx@ | | D]1 } | | k r{| | k r{|
 j | |  q{q{WqXqXW| j |  } | j |  | r|  j g  | D]( } | | k r| | t k r| ^ q|  } x2 | D]* } | | k r!| | | | <| | =q!q!Wt j d  x | D] } t |  j  } xH | | D]< } | | k r| | | | <| j | | j |   qqWt j d t  rc| j    |  j! |  |   j" | |  qcqcWt j d  t j d t  rxT | D]I } x@ | | D]4 } | j# t$ j% j& |	 d   r=t$ j' |  q=q=Wq,Wqn  | | k rPn  g  } x | j(   D] } |  j j |  rg  | | D] } | | k r| ^ q} | s| | =q#| j)   r| j* |  | | =q#| | | <qqW|  j+ j, t  | j |  j | |   |  j+ j, t  q W|  j- j.   t S(   Ns   dry-runs   data-dirs
   pre-committ   commits   post-commits   remove-packagesR   (/   RG   R#  R!   t   showChangeSetRl   Rm   R8   R   t   packagemanagerRP   R%  R   R   R    R   Rf   R    R&  t   resetLockedt   setLockedSetR   R   R   R'  t   excludet
   differenceR   R(  R6   R7   t   setRequestedt   getRequestedt   markPackagesAutoInstalledR@  RC  R2  R2   R3   RN   R   R   R^   R   R   R   R   Ri   (   R#   R   R   R   t   pmpkgsR   t   pmclassR0   Rd   Rw   t   splittert   donecst   copypkgpathst   csR-   R/  t   pmcsR3   t   copypkgsR  (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyRA    s    		
	 
)

c         C   s   |  j  | j   | |  S(   N(   t   commitChangeSetSteppedR   (   R#   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   commitTransactionStepped  s    c         C   s>  | r t  j |  r t Sg  } x | D]} } d } x[ | j D]P } xG | j D]< } x3 | j D]( }	 | j |	  t k r] | d 7} q] q] WqM Wq= W| j | | f  q' W| j	   t
 |  }
 t |  j  } xj | D]b \ } } | | k r q n  t |  j |  } |
 j | |  | j |  } |  j | d | q Wt S(   Ni    i   R   (   RG   R#  R!   R   R   R   Rm   R   RP   R`   R   R    R   t   includeRI  RA  R8   (   R#   R   R   R   t   pkglstR   t   nR   R   R   RO  t   unioncsRR  (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyRU    s,    
c         C   s  |  j  } | j   | j |  |  j   | d  k r t j j t j	 d  d  } t j j
 |  sv t j |  n  | j | d t n | j | d t i  } x| D]} xX | j D]: } | j   r q n  | j   }	 |  j j |	  r Pq q Wt t d  |  | j |  }
 |
 j   } g  | | <x | D]} } |  j j |	  } | | j | j | d | d |
 j |  d |
 j |  d |
 j |  d	 |
 j |  d
 |
 j  q9Wq W| r| j t   n  | j! d t d   | j t  | j"   } | rIt t d  d j g  | D] } d | | | f ^ q"  n  i  } x5 | D]- } g  | | D] } | j#   ^ qg| | <qVW| S(   Ns   data-dirs	   packages/R   s#   No channel available for package %st   mediaR   R   R   R   t   validateR  R   s   Failed to download packages:
s   
u
       %s: %s($   R   R   R   R   R   R2   R3   RN   Rl   Rm   RO   Rs   R   R!   R   R   t
   getChannelR    R'  RC   RD   R   R   t   getMediaRP   R  R  R  R  R  R\  R   R8   R  R  t   getTargetPath(   R#   R   R   R  R  R  t   pkgitemsR   t   loaderR-   R   R   R   R[  t   failedR/  t   item(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR(  %  sV    	


	++g      ?gffffff?gffffff?c         C   s  d } g  } g  }	 g  }
 x[ |  j  j |  D]G } | j | k s\ d | j | j f | k r+ |
 j d | f  q+ q+ W|
 s d | k r | } | } n  t   } | j | |  | r | j | |  n  |  j  j |  | j	   }
 n  |
 rw|
 d d } | | k  r|
 }	 qwxQ t
 t |
   D]= } |
 | \ } } | | k rV| j |  q$|
 | }	 Pq$W| rw| } qwn  | | |	 f S(   Ni    s   %s-%sg      ?R   (   R   R   RW   R   RP   R   t   addAutot   addProvidest   searcht
   getResultst   rangeR)  (   R#   t   st   cutofft   suggestioncutofft
   globcutofft   globsuggestioncutofft   addprovidest   ratiot   resultsR   t   objectsR   t   searchert	   bestratiot   it   obj(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyRf  T  s<    +			
N(/   t   __name__t
   __module__R   R!   R&   R(   R.   R1   R>   RQ   R]   Rf   Rg   Rh   R   Rj   R   R   R   R   RA   R   R   R   R   R   R   R   R   R  t   NEVERR  R  R,  R8   R"  R!  R$  R0  R-  R@  RB  RA  RV  RU  R(  Rf  (    (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR   2   sX   		
				!	
					"		?	x%	a/R   c           B   s;   e  Z d d d   Z d   Z d   Z d   Z d   Z RS(   c         C   sV   | p	 g  |  _  | |  _ | p$ t   |  _ i  |  _ i  |  _ |  j  rR |  j   n  d  S(   N(   R   R   R   t	   _progresst
   _availablet   _mediat   compute(   R#   R  Rd   R   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR&     s    				c         C   s   | |  _  |  j   d  S(   N(   R   R|  (   R#   Rd   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR&    s    	c         C   s   | |  j  k S(   N(   Rz  (   R#   R-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR'    s    c         C   s   |  j  j |  S(   N(   R{  Rm   (   R#   R-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR^    s    c         C   sv  |  j  j   |  j j   |  j } |  j } | j   } d } x' |  j D] } | t | j    7} qH W| j	   | j
 d | d  x|  j D]} | j   s t |  j  | <| j d  q n  | j   } | s t |  j  | <| j d  q n  t j d  } t j j | d  } t j j |  s:t j |  n  t j j | d  }	 t j j |	  st |  j  | <| j d  q n  d  }
 t } x| D]} | j   | j |	 d t | j t  | j t  | j | j   d  | j |  } | j d d	 | | j t  | j d   | j    t! k rG| j d
  Pn  | j" d  r| j d
  | j#   } | j$ | d | }
 |
 s=Pq=q| j   | j | d t | j t%  | j |  } | j d d	 | | j    t! k rPn  | j#   } | j#   } t& | |  s| j" |  r9t j' |  n  PqqWt |  j  | <|
 r |
 |  j | <q q W| j(   d  S(   Ni    i   s   data-dirs   tmp/s	   channels/R   s   %%Rd   R   i   s   localmedia:/t   comparepatht   tmp()   Rz  t   clearR{  R   Ry  R   R   R)  t   getCacheCompareURLsR   R~   R^   R8   R  R!   Rl   Rm   R2   R3   RN   RO   Rs   R   R   R   R   R   R   R   RB   R  R  t	   getStatust   FAILEDR2  R_  t   findFileRx  R   R   R   (   R#   R  R   t   mediasetR   R-   R   Rw   t   tmpdirR   R[  t	   availableR   t   channelsitemt   channelspatht   tmpitemt   tmppath(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR|    s    		


N(   Rv  Rw  R   R&   R&  R'  R^  R|  (    (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR   ~  s
   				t   ChannelSorterc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R-   (   R#   R-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR&     s    c         C   s~   t  t |  j t  t | j t   } | d k rz t  |  j j   | j j    } | rz t j d  rz | d 9} qz n  | S(   Ni    s   prefer-removablei(   t   cmpR)   R-   R/   R^   Rl   Rm   (   R#   t   othert   rc(    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   __cmp__  s    !(   Rv  Rw  R&   R  (    (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR    s   	c         C   s   i  } x |  D] } g  | j  D]$ } | j   s t | j    ^ q } | sc t t d  |  n  | j   | d j } y | | j |  Wq t	 k
 r | g | | <q Xq W| S(   Ns#   %s is not available for downloadingi    (
   R   R   R  R]  RC   RD   R`   R-   RP   t   KeyError(   R   Rd   R   R0   t   sortersR-   (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyR%    s    $
(/   R   R   R2   R   R   RE   R;   t   smart.transactionR    R   R   R   t   smart.util.filetoolsR   R   t   smart.util.objdigestR   t   smart.util.pathlocksR   t   smart.util.strtoolsR   t   smart.util.metalinkR	   R
   t   smart.searcherR   t   smart.mediaR   t   smart.progressR   t   smart.fetcherR   t   smart.reportR   t   smart.channelt   smart.cachet   smart.constt   smartt   version_infot   setsR   R~   t   objectR   R   R  R%  (    (    (    s1   /usr/lib/python2.7/dist-packages/smart/control.pyt   <module>   s:   "



   Om