ó
<¾^Yc           @@  s÷   d  Z  d d l m 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
 d d l m Z d d l m Z m Z m Z m Z m Z d d g Z e j e ƒ Z d	 e f d
 „  ƒ  YZ e ƒ  Z d e f d „  ƒ  YZ d „  Z d S(   s)   Handles all VCS (version control) supporti    (   t   absolute_importN(   t   parse(   t
   BadCommand(   t   display_patht
   backup_dirt   call_subprocesst   rmtreet   ask_path_existst   vcst   get_src_requirementt
   VcsSupportc           B@  s˜   e  Z i  Z d  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   sftpt   svnc         C@  sR   t  j j |  j ƒ t t  d d  ƒ r; t  j j |  j ƒ n  t t |  ƒ j	 ƒ  d  S(   Nt   uses_fragment(
   t   urllib_parset   uses_netloct   extendt   schemest   getattrt   NoneR   t   superR
   t   __init__(   t   self(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR      s    c         C@  s   |  j  j ƒ  S(   N(   t	   _registryt   __iter__(   R   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR   $   s    c         C@  s   t  |  j j ƒ  ƒ S(   N(   t   listR   t   values(   R   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   backends'   s    c         C@  s   g  |  j  D] } | j ^ q
 S(   N(   R   t   dirname(   R   t   backend(    (    s-   /tmp/pip-build-YOdFBd/pip/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!   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   all_schemes/   s    c         C@  sb   t  | d ƒ s& t j d | j ƒ d  S| j |  j k r^ | |  j | j <t j d | j ƒ n  d  S(   Nt   names   Cannot register VCS %ss   Registered VCS backend: %s(   t   hasattrt   loggert   warningt   __name__R$   R   t   debug(   R   t   cls(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   register6   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$   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt
   unregister>   s
    c         C@  sJ   xC |  j  j ƒ  D]2 } | j | ƒ r t j d | | j ƒ | 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')
        s   Determine that %s uses VCS: %sN(   R   R   t   controls_locationR&   R)   R$   R   (   R   t   locationt   vc_type(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   get_backend_nameF   s    	c         C@  s*   | j  ƒ  } | |  j k r& |  j | Sd  S(   N(   t   lowerR   (   R   R$   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   get_backendR   s    c         C@  s&   |  j  | ƒ } | r" |  j | ƒ Sd  S(   N(   R0   R2   R   (   R   R.   R/   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   get_backend_from_locationW   s    N(   R(   t
   __module__R   R   R   R   t   propertyR   R"   R#   R+   R   R,   R0   R2   R3   (    (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR
      s   						t   VersionControlc           B@  sà   e  Z d  Z d  Z d Z d 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 „  Z d „  Z d „  Z d „  Z e d d d d d d „ Z e d „  ƒ Z RS(   t    c         O@  s&   | |  _  t t |  ƒ j | | Ž  d  S(   N(   t   urlR   R6   R   (   R   R8   t   argst   kwargs(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR   g   s    	c         C@  s1   t  j j | ƒ \ } } | j t  j j ƒ p0 | S(   sy   
           posix absolute paths start with os.path.sep,
           win32 ones start with drive (like c:\folder)
        (   t   ost   patht
   splitdrivet
   startswitht   sep(   R   t   repot   drivet   tail(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   _is_local_repositoryk   s    c         C@  s   | j  d d ƒ S(   Nt   /t   _(   t   replace(   R   t   surname(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   translate_egg_surnameu   s    c         C@  s
   t  ‚ d S(   s   
        Export the repository at the url to the destination location
        i.e. only download the files, without vcs informations
        N(   t   NotImplementedError(   R   R.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   exporty   s    c   	      C@  s´   d } d |  j  k s( t | |  j  ƒ ‚ |  j  j d d ƒ d } t j | ƒ \ } } } } } d } d | k rŒ | j d d ƒ \ } } n  t j | | | | d f ƒ } | | f S(   sm   
        Returns the correct repository URL and revision by parsing the given
        repository URL
        sv   Sorry, '%s' is a malformed VCS url. The format is <vcs>+<protocol>://<url>, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppt   +i   t   @R7   N(   R8   t   AssertionErrort   splitR   t   urlsplitR   t   rsplitt
   urlunsplit(	   R   t   error_messageR8   t   schemet   netlocR<   t   queryt   fragt   rev(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   get_url_rev€   s    "c         C@  sH   | j  d ƒ j |  j ƒ s, t d | ƒ ‚ |  j | ƒ |  j | ƒ f S(   sA   
        Returns (url, revision), where both are strings
        RD   s   Bad directory: %s(   t   rstript   endswithR    RM   t   get_urlt   get_revision(   R   R.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   get_info“   s    c         C@  s   t  j | ƒ j d ƒ S(   si   
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        RD   (   R   t   unquoteRY   (   R   R8   (    (    s-   /tmp/pip-build-YOdFBd/pip/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(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   compare_urls¢   s    c         C@  s
   t  ‚ d S(   sx   
        Called when installing or updating an editable package, takes the
        source path of the checkout.
        N(   RI   (   R   t   dest(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   obtain¨   s    c         C@  s
   t  ‚ d S(   sB   
        Switch the repo at ``dest`` to point to ``URL``.
        N(   RI   (   R   Rc   R8   t   rev_options(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   switch¯   s    c         C@  s
   t  ‚ d S(   sO   
        Update an already-existing repo to the given ``rev_options``.
        N(   RI   (   R   Rc   Re   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   updateµ   s    c         C@  s
   t  ‚ d S(   sp   
        Return True if the version is identical to what exists and
        doesn't need to be updated.
        N(   RI   (   R   Rc   Re   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   check_version»   s    c   
      C@  sm  t  } t } t j j | ƒ rAt } t j j t j j | |  j ƒ ƒ r|  j | ƒ } |  j | | ƒ râ t	 j
 d |  j j ƒ  t | ƒ | ƒ |  j | | ƒ sÒ t	 j d t | ƒ |  j | ƒ |  j | | ƒ qt	 j d ƒ q>t	 j d |  j |  j t | ƒ | ƒ d d f } qAt	 j d
 | |  j |  j ƒ d d f } n  | rit	 j d |  j | ƒ t d | d | d ƒ } | d k r¼t	 j d |  j t | ƒ | | ƒ |  j | | | ƒ qi| d k rËqi| d k r t	 j d t | ƒ ƒ t | ƒ t  } qi| d	 k rJt | ƒ }	 t	 j d t | ƒ |	 ƒ t j | |	 ƒ t  } qi| d k rit j d ƒ qi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$   Skipping because already up-to-date.s   %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 %st   aiÿÿÿÿ(   Ri   Rj   Rk   Rl   (   Rj   Rk   Rl   (   t   Truet   FalseR;   R<   t   existst   joinR    R[   Rb   R&   R)   t	   repo_namet   titleR   Rh   t   infoRg   R'   R$   R   Rf   R   R   t   shutilt   movet   syst   exit(
   R   Rc   R8   Re   t   rev_displayt   checkoutt   promptt   existing_urlt   responset   dest_dir(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   check_destinationÂ   s‚    $		
	
	
		c         C@  s0   t  j j | ƒ r t | ƒ n  |  j | ƒ d S(   sq   
        Clean up current location and download the url repository
        (and vcs infos) into location
        N(   R;   R<   Rp   R   Rd   (   R   R.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   unpack  s    c         C@  s
   t  ‚ d S(   sê   
        Return a string representing the requirement needed to
        redownload the files currently present in location, something
        like:
          {repository_url}@{revision}#egg={project_name}-{version_identifier}
        N(   RI   (   R   t   distR.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR	      s    c         C@  s
   t  ‚ d S(   s_   
        Return the url used at location
        Used in get_info or check_destination
        N(   RI   (   R   R.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR[   )  s    c         C@  s
   t  ‚ d S(   s_   
        Return the current revision of the files at location
        Used in get_info
        N(   RI   (   R   R.   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR\   0  s    t   raisec   	      C@  su   |  j  g | } y  t | | | | | | | ƒ SWn> t k
 rp } | j t j k rj t d |  j  ƒ ‚ qq ‚  n Xd S(   s«   
        Run a VCS subcommand
        This is simply a wrapper around call_subprocess that adds the VCS
        command name, and checks that the VCS is available
        s   Cannot find command %rN(   R$   R   t   OSErrort   errnot   ENOENTR   (	   R   t   cmdt   show_stdoutt   cwdt   on_returncodet   command_desct   extra_environt   spinnert   e(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   run_command7  s    	c         C@  sD   t  j d | |  j |  j ƒ t j j | |  j ƒ } t j j | ƒ S(   s¨   
        Check if a location is controlled by the vcs.
        It is meant to be overridden to implement smarter detection
        mechanisms for specific vcs.
        s   Checking in %s for %s (%s)...(   R&   R)   R    R$   R;   R<   Rq   Rp   (   R*   R.   R<   (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR-   N  s    	(    N(   R(   R4   R$   R    R   R   R   RC   RH   RJ   RX   R]   R_   Rb   Rd   Rf   Rg   Rh   R   R€   R	   R[   R\   Rn   RŽ   t   classmethodR-   (    (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR6   a   s2   	
											U						c         C@  sz   t  j | ƒ } | r` y | ƒ  j |  | ƒ SWq` t k
 r\ t j d | | j ƒ |  j ƒ  SXn  t j d | ƒ |  j ƒ  S(   NsP   cannot determine version of editable source in %s (%s command not found in path)st   cannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch)(   R   R3   R	   R   R&   R'   R$   t   as_requirement(   R   R.   t   version_control(    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyR	   [  s    
(   t   __doc__t
   __future__R    R„   t   loggingR;   Ru   Rw   t   pip._vendor.six.moves.urllibR   R   t   pip.exceptionsR   t	   pip.utilsR   R   R   R   R   t   __all__t	   getLoggerR(   R&   t   objectR
   R   R6   R	   (    (    (    s-   /tmp/pip-build-YOdFBd/pip/pip/vcs/__init__.pyt   <module>   s   (G	ú