ó
œçƒQc           @   sê   d  Z  d d l Z d d l m Z m Z m Z d d l m Z d d l Z d e	 f d „  ƒ  YZ
 d e f d „  ƒ  YZ d d l Z d d l Z i e j g d	 6e j g d
 6e j g d 6e j g d 6Z e j d ƒ Z d e d „ Z d S(   sC   base class for store implementations and store-related utility codeiÿÿÿÿN(   t   utilt   nodet   hg(   t   _t
   StoreErrorc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sZ   Raised when there is a problem getting files from or putting
    files to a central store.c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   filenamet   hasht   urlt   detail(   t   selfR   R   R   R   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   __init__   s    			c         C   s&   t  d ƒ |  j |  j |  j |  j f S(   Ns0   error getting id %s from url %s for file %s: %s
(   R   R   R   R   R   (   R	   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   longmessage   s    	c         C   s   d |  j  |  j f S(   Ns   %s: %s(   R   R   (   R	   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R
   R   R   (    (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR      s   		t	   basestorec           B   sJ   e  Z d  „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z	 RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   uit   repoR   (   R	   R   R   R   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR
   #   s    		c         C   s   t  d ƒ ‚ d S(   s>   Put source file into the store so it can be retrieved by hash.s   abstract methodN(   t   NotImplementedError(   R	   t   sourceR   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   put(   s    c         C   s   t  d ƒ ‚ d S(   s€   Check to see if the store contains the given hashes. Given an
        iterable of hashes it returns a mapping from hash to bool.s   abstract methodN(   R   (   R	   t   hashes(    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   exists,   s    c      	   C   sC  g  } g  } |  j  } t j t j |  j d ƒ ƒ d } |  j t d „  | Dƒ ƒ ƒ } xÊ| D]Â\ } } | j t	 d ƒ | d d d t
 | ƒ ƒ| d 7} | j t	 d	 ƒ | | f ƒ | j | ƒ sý | j t	 d
 ƒ | | |  j f ƒ | j | ƒ q] n  t j |  j | ƒ }	 t j |	 d d |  j j j ƒ}
 y |  j |
 | | ƒ } Wn, t k
 r{} | j | j ƒ  ƒ d } n X|
 j ƒ  | | k rå| d k rÁ| j t	 d ƒ | | | f ƒ n  t j |	 d ƒ | j | ƒ q] n  t j |	 d |	 ƒ t j |  j | ƒ | j | | f ƒ q] W| j t	 d ƒ d ƒ | | f S(   sú  Get the specified largefiles from the store and write to local
        files under repo.root.  files is a list of (filename, hash)
        tuples.  Return (success, missing), lists of files successfully
        downloaded and those not found in the store.  success is a list
        of (filename, hash) tuples; missing is a list of filenames that
        we could not get.  (The detailed error message will already have
        been presented to the user, so missing is just supplied as a
        summary.)t    i    c         s   s   |  ] \ } } | Vq d  S(   N(    (   t   .0t	   _filenameR   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pys	   <genexpr>A   s    s   getting largefilest   unitt   lfilet   totali   s   getting %s:%s
s'   %s: largefile %s not available from %s
s   .tmpt
   createmodes*   %s: data corruption (expected %s, got %s)
N(   R   R    t   makedirst   lfutilt	   storepathR   R   t   sett   progressR   t   lent   notet   gett   warnR   t   appendt   atomictempfilet   storeR   t   _getfileR   R   t   closet   unlinkt   renamet   linktousercachet   None(   R	   t   filest   successt   missingR   t   att	   availableR   R   t   storefilenamet   tmpfilet   hhasht   err(    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR&   1   sJ    		


c         C   s1  t  } |  j j t d ƒ t | ƒ ƒ t ƒ  } xu | D]m } |  j | } d | j ƒ  t j	 | j ƒ  ƒ f } x2 | D]* } |  j
 | | | | | ƒ ru t } qu qu Wq6 Wt | ƒ }	 t t g  | D] \ }
 } |
 ^ qÀ ƒ ƒ } | r|  j j t d ƒ |	 | f ƒ n  |  j j t d ƒ |	 | f ƒ t | ƒ S(   s³   Verify the existence (and, optionally, contents) of every big
        file revision referenced by every changeset in revs.
        Return 0 if all is well, non-zero on any errors.s'   searching %d changesets for largefiles
s   %d:%ss3   verified contents of %d revisions of %d largefiles
s4   verified existence of %d revisions of %d largefiles
(   t   FalseR   t   statusR   R$   R"   R   t   revR   t   shortt   _verifyfilet   Truet   int(   R	   t   revst   contentst   failedt   verifiedR<   t   cctxt   csett   standint   numrevst   fnamet   fnodet	   numlfiles(    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   verifyh   s(    	%+				c         C   s   t  d ƒ ‚ d S(   s  Fetch one revision of one file from the store and write it
        to tmpfile.  Compute the hash of the file on-the-fly as it
        downloads and return the hash.  Close tmpfile.  Raise
        StoreError if unable to download the file (e.g. it does not
        exist in the store).s   abstract methodN(   R   (   R	   R7   R   R   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR+   †   s    c         C   s   t  d ƒ ‚ d S(   sp  Perform the actual verification of a file in the store.
        'cset' is only used in warnings.
        'contents' controls verification of content hash.
        'standin' is the standin path of the largefile to verify.
        'verified' is maintained as a set of already verified files.
        Returns _true_ if it is a standin and any problems are found!
        s   abstract methodN(   R   (   R	   RE   RF   RB   RG   RD   (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR>   Ž   s    (
   R   R   R
   R   R   R&   R:   RL   R+   R>   (    (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyR   "   s   				7	t   filet   httpt   httpst   sshs   ^([a-zA-Z0-9+-.]+)://c      	   C   s‡  |  j  } | sŸ t |  d d  ƒ } | r9 | j | ƒ } n | j d d ƒ } | d k sc | d k rr d } |  } qŸ t j | ƒ \ } } t j |  i  | ƒ } n  t j | d ƒ r½ | j	 ƒ  pÃ | j
 } t j | ƒ } | sä d } n | j d ƒ } y t | }	 Wn* t k
 r-t j t d ƒ | ƒ ‚ n Xx9 |	 D]1 }
 y |
 | |  | ƒ SWq5t j k
 req5Xq5Wt j t d	 ƒ | ƒ ‚ d  S(
   Nt   lfpullsources   default-pusht   defaultR   R   RM   i   s   unsupported URL scheme %rs*   %s does not appear to be a largefile store(   R   t   getattrR0   t
   expandpathR   t   parseurlt   peerR    t   safehasattrR   t   patht
   _scheme_ret   matcht   groupt   _storeprovidert   KeyErrort   AbortR   R    t   storeprotonotcapable(   R   t   remoteR   R   RQ   RX   t	   _branchesRZ   t   schemet   storeproviderst   classobj(    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt
   _openstore¦   s4    		'	(   R   t   ret	   mercurialR    R   R   t   mercurial.i18nR   R    t	   ExceptionR   t   objectR   t
   localstoret	   wirestoreR\   t   compileRY   R0   R:   Re   (    (    (    s>   /sys/lib/python2.7/site-packages/hgext/largefiles/basestore.pyt   <module>	   s   v