ó
'šMc           @   sÊ   d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z m Z m Z m Z d d g Z d	 e f d
 „  ƒ  YZ e ƒ  Z d e f d „  ƒ  YZ d „  Z d S(   s)   Handles all VCS (version control) supportiÿÿÿÿN(   t   urlparset   urllib(   t
   BadCommand(   t   logger(   t   display_patht
   backup_dirt   find_commandt   askt   rmtreet   vcst   get_src_requirementt
   VcsSupportc           B   s•   e  Z i  Z d  d d d d g Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z	 d
 „  Z
 d d d „ Z d „  Z d „  Z d „  Z RS(   t   ssht   gitt   hgt   bzrt   sftpc         C   s=   t  j j |  j ƒ t  j j |  j ƒ t t |  ƒ j ƒ  d  S(   N(   R    t   uses_netloct   extendt   schemest   uses_fragmentt   superR   t   __init__(   t   self(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR      s    c         C   s   |  j  j ƒ  S(   N(   t	   _registryt   __iter__(   R   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR      s    c         C   s   t  |  j j ƒ  ƒ S(   N(   t   listR   t   values(   R   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   backends   s    c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R   t   dirname(   R   t   backend(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   dirnames    s    c         C   s.   g  } x! |  j  D] } | j | j ƒ q W| S(   N(   R   R   R   (   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   all_schemes$   s    c         C   sP   t  | d ƒ s' t j d | j ƒ d  S| j |  j k rL | |  j | j <n  d  S(   Nt   names   Cannot register VCS %s(   t   hasattrR   t   warnt   __name__R!   R   (   R   t   cls(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   register+   s
    c         C   sR   | |  j  k r |  j  | =n2 | |  j  j ƒ  k rA |  j  | j =n t j d ƒ d  S(   Ns0   Cannot unregister because no class or name given(   R   R   R!   R   R#   (   R   R%   R!   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt
   unregister2   s
    c         C   sO   xH |  j  j ƒ  D]7 } t j j | | j ƒ } t j j | ƒ r | j Sq Wd S(   s—   
        Return the name of the version control backend if found at given
        location, e.g. vcs.get_backend_name('/path/to/vcs/checkout')
        N(	   R   R   t   ost   patht   joinR   t   existsR!   t   None(   R   t   locationt   vc_typeR)   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   get_backend_name:   s
    c         C   s*   | j  ƒ  } | |  j k r& |  j | Sd  S(   N(   t   lowerR   (   R   R!   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   get_backendE   s    c         C   s&   |  j  | ƒ } | r" |  j | ƒ Sd  S(   N(   R/   R1   R,   (   R   R-   R.   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   get_backend_from_locationJ   s    N(   R$   t
   __module__R   R   R   R   t   propertyR   R   R    R&   R,   R'   R/   R1   R2   (    (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR      s   					t   VersionControlc           B   s§   e  Z d  Z d  Z d d „ Z d „  Z d „  Z e d „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z RS(   t    c         O   s/   | |  _  d  |  _ t t |  ƒ j | | Ž  d  S(   N(   t   urlR,   t   _cmdR   R5   R   (   R   R7   t   argst   kwargs(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR   X   s    		c         C   s   t  j | f S(   N(   R   t   INFO(   R   t   line(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   _filter]   s    c         C   s1   t  j j | ƒ \ } } | j t  j j ƒ p0 | S(   s~   
           posix absolute paths start with os.path.sep,
           win32 ones ones start with drive (like c:\folder)
        (   R(   R)   t
   splitdrivet
   startswitht   sep(   R   t   repot   drivet   tail(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   _is_local_repository`   s    c         C   sn   |  j  d  k	 r |  j  St |  j ƒ } | d  k rG t d |  j ƒ ‚ n  t j d |  j | f ƒ | |  _  | S(   Ns   Cannot find command %rs   Found command %r at %r(   R8   R,   R   R!   R   R   t   info(   R   t   command(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   cmdh   s    	c         C   sŒ   |  j  j d d ƒ d } t j | ƒ \ } } } } } d } d | k rd | j d d ƒ \ } } n  t j | | | | d f ƒ } | | f S(   sm   
        Returns the correct repository URL and revision by parsing the given
        repository URL
        t   +i   t   @R6   N(   R7   t   splitR    t   urlsplitR,   t   rsplitt
   urlunsplit(   R   R7   t   schemet   netlocR)   t   queryt   fragt   rev(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   get_url_revs   s    c         C   sE   | j  d ƒ j |  j ƒ s) t d | ‚ |  j | ƒ |  j | ƒ f S(   sA   
        Returns (url, revision), where both are strings
        t   /s   Bad directory: %s(   t   rstript   endswithR   t   AssertionErrort   get_urlt   get_revision(   R   R-   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   get_info€   s    )c         C   s   t  j | ƒ j d ƒ S(   sa   
        Normalize a URL for comparison by unquoting it and removing any trailing slash.
        RT   (   R   t   unquoteRU   (   R   R7   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   normalize_url‡   s    c         C   s   |  j  | ƒ |  j  | ƒ k S(   sV   
        Compare two repo URLs for identity, ignoring incidental differences.
        (   R\   (   R   t   url1t   url2(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   compare_urls   s    c         C   s
   t  ‚ d S(   sÌ   
        Takes the contents of the bundled text file that explains how to revert
        the stripped off version control data of the given package and returns
        the URL and revision of it.
        N(   t   NotImplementedError(   R   t   content(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   parse_vcs_bundle_file“   s    c         C   s
   t  ‚ d S(   sx   
        Called when installing or updating an editable package, takes the
        source path of the checkout.
        N(   R`   (   R   t   dest(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   obtain›   s    c         C   s
   t  ‚ d S(   sB   
        Switch the repo at ``dest`` to point to ``URL``.
        N(   t   NotImplemented(   R   Rc   R7   t   rev_options(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   switch¢   s    c         C   s
   t  ‚ d S(   sO   
        Update an already-existing repo to the given ``rev_options``.
        N(   R`   (   R   Rc   Rf   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   update¨   s    c   
      C   sL  t  } t } t j j | ƒ r/t } t j j t j j | |  j ƒ ƒ r |  j | ƒ } |  j | | ƒ rÈ t	 j
 d |  j j ƒ  t | ƒ | f ƒ t	 j d t | ƒ |  j | f ƒ |  j | | ƒ q,t	 j d |  j |  j t | ƒ | f ƒ d d f } q/t	 j d	 | |  j |  j f ƒ d
 d f } n  | rHt	 j d |  j | f ƒ t d | d | d ƒ } | d k r²t	 j d |  j t | ƒ | | f ƒ |  j | | | ƒ qH| d k rÁqH| d k r÷t	 j d t | ƒ ƒ t | ƒ t  } qH| d k rHt | ƒ }	 t	 j d t | ƒ |	 f ƒ t j | |	 ƒ t  } qHn  | S(   s­   
        Prepare a location to receive a checkout/clone.

        Return True if the location is ready for (and requires) a
        checkout/clone, False otherwise.
        s)   %s in %s exists, and has correct URL (%s)s   Updating %s %s%ss   %s %s in %s exists with URL %ss%   (s)witch, (i)gnore, (w)ipe, (b)ackup t   st   it   wt   bs0   Directory %s already exists, and is not a %s %s.s   (i)gnore, (w)ipe, (b)ackup s+   The plan is to install the %s repository %ss   What to do?  %si    i   s   Switching %s %s to %s%ss   Deleting %ss   Backing up %s to %s(   Ri   Rj   Rk   Rl   (   Rj   Rk   Rl   (   t   Truet   FalseR(   R)   R+   R*   R   RX   R_   R   RE   t	   repo_namet   titleR   t   notifyRh   R#   R!   R   Rg   R   R   t   shutilt   move(
   R   Rc   R7   Rf   t   rev_displayt   checkoutt   promptt   existing_urlt   responset   dest_dir(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   check_destination®   sN    $	 		 			
		c         C   s0   t  j j | ƒ r t | ƒ n  |  j | ƒ d  S(   N(   R(   R)   R+   R   Rd   (   R   R-   (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   unpacká   s    c         C   s
   t  ‚ d  S(   N(   R`   (   R   t   distR-   t	   find_tags(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR
   æ   s    N(   R$   R3   R!   R   R,   R   R=   RD   R4   RG   RS   RZ   R\   R_   Rb   Rd   Rg   Rh   Rz   R{   Rn   R
   (    (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR5   T   s"   											3	c         C   sF   t  j | ƒ } | r+ | ƒ  j |  | | ƒ St j d | ƒ |  j ƒ  S(   Nst   cannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch)(   R	   R2   R
   R   R#   t   as_requirement(   R|   R-   R}   t   version_control(    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyR
   ê   s
    (   t   __doc__R(   Rr   t   pip.backwardcompatR    R   t   pip.exceptionsR   t   pip.logR   t   pip.utilR   R   R   R   R   t   __all__t   objectR   R	   R5   R
   (    (    (    s4   /usr/lib/python2.7/dist-packages/pip/vcs/__init__.pyt   <module>   s   (B	–