ó
È”Mc           @   sÉ   d  d l  m Z m Z m Z d  d l  m Z m Z d  d l m Z m Z d  d l	 m
 Z
 d  d l Td  d l Z d  d l Z d  d l Z e d ƒ Z e d ƒ Z e d	 ƒ Z d
 „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   Transactiont   PolicyInstallt   sortUpgrades(   t   INSTALLt	   REINSTALL(   t   OptionParsert
   append_all(   t   Package(   t   *Ns$   smart download [options] package ...s=   
This command allows downloading one or more given packages.
s‰  
smart download pkgname
smart download '*kgna*'
smart download pkgname-1.0
smart download pkgname-1.0-1
smart download pkgname1 pkgname2
smart download pkgname --urls 2> pkgname-url.txt
smart download pkgname --metalink 2> pkgname.metalink
smart download --from-urls pkgname-url.txt
smart download --from-urls http://some.url/some/path/somefile
smart download --from-metalink pkgname.metalink
c       	   C   s=  t  d t d t d t ƒ }  g  |  j d <g  |  j d <t j ƒ  |  j d <|  j d d d	 d
 d d t d ƒ ƒ|  j d d d d t d ƒ ƒ|  j d d d	 d
 d d t d ƒ ƒ|  j d d d d t d ƒ ƒ|  j d d d d t d ƒ ƒ|  j d d d d t	 d t d ƒ ƒ|  j d d d d t	 d t d ƒ ƒ|  S(   Nt   usaget   descriptiont   examplest	   from_urlst   from_metalinkt   targets   --targett   actiont   storet   metavart   DIRt   helps)   packages will be saved in given directorys   --packt
   store_trues)   pack all downloaded packages in a tarballs   --outputt   FILEs)   redirect tarball output to given filenames   --urlss,   dump needed urls and don't download packagess
   --metalinks-   dump metalink xml and don't download packagess   --from-urlst   callbacksQ   download files from the given urls and/or from the given files with lists of urlss   --from-metalinks+   download files from the given metalink file(
   R   t   USAGEt   DESCRIPTIONt   EXAMPLESt   defaultst   ost   getcwdt
   add_optiont   _R   (   t   parser(    (    s;   /usr/lib/python2.7/dist-packages/smart/commands/download.pyt   option_parser2   s*    	c         C   sX   t  ƒ  } | j |  ƒ \ } } | | _ t j j | j ƒ sT t t d ƒ | j ‚ n  | S(   Ns   Directory not found:(	   R    t
   parse_argst   argsR   t   patht   isdirR   t   ErrorR   (   t   argvR   t   optsR"   (    (    s;   /usr/lib/python2.7/dist-packages/smart/commands/download.pyt   parse_optionsJ   s    		c      
   C   s­  g  } | j  rft j d ƒ rP d d l m } | j g  ƒ } | j |  | ƒ n
 |  j ƒ  |  j ƒ  } i  } xu| j  D]j} |  j	 | ƒ \ } } }	 | sM|	 r7i  }
 xL |	 D]D \ } } t
 | t ƒ rÕ t |
 | <q­ |
 j t j | j t ƒ ƒ q­ Wt t d ƒ | d j g  |
 D] } d t | ƒ ^ qƒ f ‚ qMt t d ƒ | ‚ n  g  } x- | D]% } t
 | t ƒ rZ| j | ƒ qZqZW| skt } i  } xp | D]h } x^ | j D]P } | j rât j t d ƒ | | f ƒ t } Pq¬| j | ƒ t | | j <q¬WqœPqœW| rqv n  t | ƒ d	 k rkt t d
 ƒ | d j g  | D] } d t | ƒ ^ qBƒ f ‚ qkn  t | ƒ d	 k rŠt | ƒ n  i  } x* | D]" } | j | j g  ƒ j | ƒ q—Wx  | D] } t | | | d <qÄWqv W| j ƒ  } | j r	|  j | ƒ q©| j  r"|  j! | ƒ q©|  j" | d | j# ƒ| j$ r©|  j% | d | j# d | j& ƒq©nC| j' rjg  } xÇ | j' D]¼ } d | k r¡| j | ƒ qt( j) j* | ƒ r(t+ | ƒ j, ƒ  } | j- d ƒ rù|  j. | t d ƒ d | j# ƒqn  | j/ g  t+ | ƒ D] } | j0 ƒ  ^ qƒ qt t d ƒ | ‚ qW| r©|  j1 | t d ƒ d | j# ƒq©n? | j2 r©x3 | j2 D]% } |  j. | t d ƒ d | j# ƒq}Wn  d  S(   Ns   auto-updateiÿÿÿÿ(   t   updates)   '%s' matches no packages. Suggestions:
%ss   
s       s   '%s' matches no packagess    %s (for %s) is already installedi   s'   There are multiple matches for '%s':
%si    t	   targetdirt
   outputnames   :/s   <?xmlt   Metalinks"   Argument is not a file nor url: %st   URLs(3   R"   t   sysconft   gett   smart.commandsR)   R(   t   maint   reloadChannelst   getCachet   searcht
   isinstanceR   t   Truet   dictt   fromkeyst   packagesR%   R   t   joint   strt   appendt   Falset	   installedt   ifacet   warningt   namet   lenR   t
   setdefaultt   keyst   urlst   dumpURLst   metalinkt   dumpMetalinkt   downloadPackagesR   t   packt   packPackagest   outputR   R   R#   t   isfilet   opent   readlinet
   startswitht   downloadMetalinkt   extendt   stript   downloadURLsR   (   t   ctrlR'   R9   R)   t
   updateoptst   cachet   argt   ratiot   resultst   suggestionst   dctt   rt   objt   xt   pkgsR>   t   namest   pkgRA   RE   t   line(    (    s;   /usr/lib/python2.7/dist-packages/smart/commands/download.pyR1   R   sš    	
 6	9 				/%	(   t   smart.transactionR    R   R   R   R   t   smart.optionR   R   t   smart.cacheR   t   smartt   stringt   reR   R   R   R   R   R    R(   R1   (    (    (    s;   /usr/lib/python2.7/dist-packages/smart/commands/download.pyt   <module>   s   
				