ó
È”Mc           @   s›   d  d l  Z  d  d l 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 m Z d  d l Td e	 f d	 „  ƒ  YZ d
 „  Z d S(   iÿÿÿÿN(   t   DebTagFileLoader(   t   getFileDigest(   t   getArchitecture(   t   PackageChannel(   t	   SUCCEEDEDt   NEVER(   t   *t   APTDEBChannelc           B   sw   e  Z d	 Z d	 Z d	 Z d	 Z d  „  Z d d	 e d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d	 d	 d „ Z d „  Z RS(
   c         G   s‰   t  t |  ƒ j | Œ  | j d ƒ } | |  _ | |  _ | |  _ | ra d j | j ƒ  ƒ |  _	 n  | rs | |  _
 n  | r… | |  _ n  d  S(   Nt   /t    (   t   superR   t   __init__t   lstript   _baseurlt   _distrot   _compst   joint   splitt   _fingerprintt   _keyringt   _trustdb(   t   selft   baseurlt   distrot   compst   fingerprintt   keyringt   trustdbt   args(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyR   *   s    			R	   c         C   s£   |  j  d  k r t ƒ  |  _  n  | r- d } n? |  j sQ t j |  j |  j ƒ } n t j |  j d |  j ƒ } | r t j | | d |  j  | ƒ St j | | ƒ Sd  S(   NR	   t   distss   binary-(   t   _archt   NoneR   R   t	   posixpathR   R   R   (   R   t   filenamet	   componentt   subpatht	   distrourl(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   _getURL8   s    		c         C   s   |  j  d ƒ g S(   Nt   Release(   R%   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   getCacheCompareURLsG   s    c         C   s"   |  j  r t |  j  ƒ d Sd Sd  S(   Ni   i   (   R   t   len(   R   (    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   getFetchStepsJ   s    	c         C   s'  t  |  j p |  j ƒ } t  | p' |  j ƒ } | j ƒ  } | ra | ra t t d ƒ |  | f ‚ n  | r#| j ƒ  } | r• t t d ƒ |  | f ‚ n  d d d d d g } |  j rÏ | j d d	 |  j g ƒ n  |  j rñ | j d
 |  j g ƒ n  | j d | j	 ƒ  | j	 ƒ  g ƒ d j
 | ƒ } t j | ƒ \ }	 }
 t } t } d  } xƒ |
 j ƒ  D]u } | j d ƒ rV| d j ƒ  } | d } | d k rž| d } qË| d k r³t } qË| d k rËt } qËqVqVW| rët t d ƒ |  ‚ n  | s
|  j r#| |  j k r#t t d ƒ |  ‚ q#n  d  S(   Ns/   Download of Release failed for channel '%s': %ss:   Download of Release.gpg failed for secure channel '%s': %st   gpgs   --batchs   --no-secmem-warnings   --status-fdt   1s   --no-default-keyrings	   --keyrings   --trustdb-names   --verifyt    s   [GNUPG:]i   i    t   VALIDSIGi   t   GOODSIGt   BADSIGs   Channel '%s' has bad signatures$   Channel '%s' signed with unknown key(   t   boolR   R   R   t   getFailedReasont   Errort   _t   extendR   t   getTargetPathR   t   commandst   getstatusoutputt   FalseR   t
   splitlinest
   startswithR   t   True(   R   t   release_itemt   release_gpg_itemt   is_secure_channelt   need_releaset   release_failedt   release_gpg_failedt	   argumentst   commandt   statust   outputt   badsigt   goodsigt   validsigt   linet   tokenst   first(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   _checkReleaseU   sT    							
	c         C   s7  i  } t  } t  } t  } xt | j ƒ  ƒ D]} | sR | j d ƒ rÛ t } qÛ n‰ | j d ƒ sj t  } nq | rÛ y | j ƒ  \ } } }	 Wn t k
 rœ qÛ X|	 | k r¶ i  | |	 <n  | | |	 d <t | ƒ | |	 d <n  | sü | j d ƒ r…t } q…n‰ | j d ƒ st  } nq | r…y | j ƒ  \ }
 } }	 Wn t k
 rFq…X|	 | k r`i  | |	 <n  |
 | |	 d <t | ƒ | |	 d <n  | s¦| j d ƒ r/t } q/q+ | j d ƒ s¾t  } q+ | r+ y | j ƒ  \ } } }	 Wn t k
 rðq/X|	 | k r
i  | |	 <n  | | |	 d <t | ƒ | |	 d <q+ q+ W| S(	   Ns   MD5Sum:R,   t   md5t   sizes   SHA1:t   sha1s   SHA256:t   sha256(   R8   t   openR5   R:   R;   R   t
   ValueErrort   int(   R   R<   t   checksumt   insidemd5sumt
   insidesha1t   insidesha256RI   RM   RN   t   pathRO   RP   (    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   _parseRelease‰   s`    			c         C   s3  i  } |  j  d | ƒ } |  j  d | d t ƒ} | d  k	 r| d | k rc | d } | d 7} ng | d | k rŠ | d } | d 7} n@ | d | k r± | d } | d 7} n | | k rÆ d  } n d  S| r¬t | d <| | j d d  ƒ | d <| | j d d  ƒ | d <| | j d	 d  ƒ | d	 <| | d
 | d
 <| | k r| | j d d  ƒ | d <| | j d d  ƒ | d <| | j d	 d  ƒ | d <| | d
 | d <qq#| | j d d  ƒ | d <| | j d d  ƒ | d <| | j d	 d  ƒ | d	 <| | d
 | d
 <n t | d <| d 7} | j | |  S(   Nt   PackagesR#   s   .lzmas   .bz2s   .gzt   uncompRM   RO   RP   RN   t
   uncomp_md5t   uncomp_sha1t   uncomp_sha256t   uncomp_size(   R%   R;   R   t   gett   enqueue(   R   t   fetcherRT   R"   t   infot   urlR#   t   compressed_subpath(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   _enqueuePackages¾   sD    


	


c         C   s³  | j  ƒ  | j |  j d ƒ ƒ } | j |  j d ƒ ƒ } | j d | ƒ y |  j | | ƒ WnP t k
 r° } | j |  j ƒ  d ƒ | j ƒ  | j	 ƒ  t
 k r© ‚  q± t Sn X| j ƒ  st | j ƒ  ƒ } | |  j k r| j |  j ƒ  d ƒ | j ƒ  t S|  j ƒ  |  j | ƒ } n d  } d  } | j  ƒ  |  j sV|  j | | ƒ g } nb g  } xY |  j D]N }	 |  j | | |	 ƒ }
 |
 r—| j |
 ƒ qft j t d ƒ |	 |  f ƒ qfW| j d | ƒ g  } x | D]y }
 |
 j ƒ  t k r+|
 j ƒ  } t | |  j ƒ } | j |  ƒ |  j j | ƒ qÕ| j d |
 j  ƒ  |
 j ƒ  f ƒ qÕW| r| j	 ƒ  t
 k r™| j! d t d ƒ |  ƒ t d	 j" | ƒ ‚ n  t S| r¯| |  _ n  t S(
   NR&   s   Release.gpgt   progressi   s6   Component '%s' is not in Release file for channel '%s'u   %s: %si    s&   Failed acquiring information for '%s':s   
(#   t   resetRa   R%   t   runRL   R2   t   addR)   t   showt
   getCachingR   R8   R1   R   R5   t   _digestR;   t   removeLoadersRY   R   R   Rf   t   appendt   ifacet   warningR3   t	   getStatusR   R    R   t
   setChannelt   _loaderst   getURLt   insertR   (   R   Rb   Rg   R<   R=   t   et   digestRT   t   packages_itemsR"   t   itemt
   errorlinest	   localpatht   loader(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   fetchæ   sf    




	N(   t   __name__t
   __module__R   R   R   R   R   R   R8   R%   R'   R)   RL   RY   Rf   R~   (    (    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyR   !   s   				4	5(c         C   s]   t  | d | d | d j ƒ  | d | d | d | d |  | d | d	 | d
 | d ƒ S(   NR   t   distributiont
   componentsR   R   R   t   typet   namet   manualt	   removablet   priority(   R   R   (   t   aliast   data(    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   create-  s    
(   R    R6   t   smart.backends.deb.loaderR    t   smart.util.filetoolsR   t   smart.backends.deb.baseR   t   smart.channelR   t   smart.constR   R   t   smartR   RŠ   (    (    (    s:   /usr/lib/python2.7/dist-packages/smart/channels/apt_deb.pyt   <module>   s   
ÿ 