
0c@_o0                 @   s`  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z m Z e j d  Z e j d	  Z e j d
  Z e j d  Z e r*d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z m Z e j e   Z! Gd d   d e  Z" e j# e"  d S)    )absolute_importN)
indent_log)display_pathis_console_interactivermtreesplit_auth_from_netloc)make_command)MYPY_CHECK_RUNNING)VersionControlvcszurl="([^"]+)"zcommitted-rev="(\d+)"z\s*revision="(\d+)"z<url>(.*)</url>)OptionalTuple)CommandArgs)
HiddenText)AuthInfo
RevOptionsc                   s?  e  Z d  Z d Z d Z d Z d+ Z e d d	    Z e	 d
 d    Z
 e d d    Z e   f d d    Z e   f d d    Z e	 d d    Z e d d    Z e d d    Z e d d    Z d   f d d  Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z   S),
Subversionsvnz.svncheckoutsvn+sshsvn+http	svn+httpssvn+svnc             C   s   d S)NT )clsZ
remote_urlr   r   ;/tmp/pip-build-jynh7p1z/pip/pip/_internal/vcs/subversion.pyshould_add_vcs_url_prefix+   s    z$Subversion.should_add_vcs_url_prefixc             C   s
   d |  g S)Nz-rr   )revr   r   r   get_base_rev_args/   s    zSubversion.get_base_rev_argsc       	      C   s   d } x t  j |  D] \ } } } |  j | k rG g  | d d  <q | j |  j  t  j j | |  j d  } t  j j |  s q |  j |  \ } } | | k r | d } n* | s | j |  r g  | d d  <q t	 | |  } q W| S)zR
        Return the maximum revision for all files under a given location
        r   Nentries/)
oswalkdirnameremovepathjoinexists_get_svn_url_rev
startswithmax)	r   locationrevisionbasedirs_
entries_fndirurllocalrevr   r   r   get_revision3   s"    zSubversion.get_revisionc                s/   | d k r% t  t |   j | |  St |  S)z
        This override allows the auth information to be passed to svn via the
        --username and --password options instead of via the URL.
        ssh)superr   get_netloc_and_authr   )r   netlocscheme)	__class__r   r   r6   O   s    zSubversion.get_netloc_and_authc                sG   t  t |   j |  \ } } } | j d  r: d | } | | | f S)Nzssh://zsvn+)r5   r   get_url_rev_and_authr)   )r   urlr   	user_pass)r9   r   r   r:   \   s    !
zSubversion.get_url_rev_and_authc             C   s6   g  } |  r | d |  g 7} | r2 | d | g 7} | S)Nz
--usernamez
--passwordr   )usernamepassword
extra_argsr   r   r   make_rev_argse   s    zSubversion.make_rev_argsc             C   sw   | } x] t  j j t  j j | d   se | } t  j j |  } | | k r	 t j d |  d  Sq	 W|  j |  d S)Nzsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)r   )r!   r%   r'   r&   r#   loggerwarningr(   )r   r+   orig_locationlast_locationr   r   r   get_remote_urlp   s    $zSubversion.get_remote_urlc             C   s  d d l  m } t j j | |  j d  } t j j |  rb t |   } | j   } Wd  QRXn d } | j	 d  s | j	 d  s | j	 d  r t
 t t j | j d    } | d d =| d d	 } d
 d   | D d g } n | j	 d  r]t j |  } | s(t d j t       | j d  } d d   t j |  D d g } nr yP |  j d d | g  }	 t j |	  j d  } d d   t j |	  D } Wn | k
 rd  g  } } Yn X| rt |  }
 n d }
 | |
 f S)Nr   )SubProcessErrorr    8910z

   c             S   s<   g  |  ]2 } t  |  d  k r | d  r t | d    q S)	   )lenint).0dr   r   r   
<listcomp>   s   	 z/Subversion._get_svn_url_rev.<locals>.<listcomp>z<?xmlzBadly formatted data: {data!r}   c             S   s%   g  |  ] } t  | j d     q S)rR   )rN   group)rO   mr   r   r   rQ      s   	 infoz--xmlc             S   s%   g  |  ] } t  | j d     q S)rR   )rN   rS   )rO   rT   r   r   r   rQ      s   	 )Zpip._internal.exceptionsrF   r!   r%   r&   r#   r'   openreadr)   listmapstr
splitlinessplit_svn_xml_url_research
ValueErrorformatlocalsrS   _svn_rev_refinditerrun_command_svn_info_xml_url_re_svn_info_xml_rev_rer*   )r   r+   rF   entries_pathfdatar;   revsmatchxmlr   r   r   r   r(      s>    !& zSubversion._get_svn_url_revc             C   s   d S)z&Always assume the versions don't matchFr   )r   destnamer   r   r   is_commit_id_equal   s    zSubversion.is_commit_id_equalNc                s>   | d  k r t    } | |  _ d  |  _ t t |   j   d  S)N)r   use_interactive_vcs_versionr5   r   __init__)selfrp   )r9   r   r   rr      s
    			zSubversion.__init__c             C   s   d } |  j  d g  } | j |  s+ f  S| t |  d  j   d } | j d  d j d  } y t t t |   } Wn t k
 r f  SYn X| S)a  Query the version of the currently installed Subversion client.

        :return: A tuple containing the parts of the version information or
            ``()`` if the version returned from ``svn`` could not be parsed.
        :raises: BadCommand: If ``svn`` is not installed.
        zsvn, version z	--versionNr   -.)	rd   r)   rM   r\   	partitiontuplerY   rN   r_   )rs   Zversion_prefixversionZversion_listparsed_versionr   r   r   call_vcs_version   s     	zSubversion.call_vcs_versionc             C   s/   |  j  d k	 r |  j  S|  j   } | |  _  | S)a  Return the version of the currently installed Subversion client.

        If the version of the Subversion client has already been queried,
        a cached value will be used.

        :return: A tuple containing the parts of the version information or
            ``()`` if the version returned from ``svn`` could not be parsed.
        :raises: BadCommand: If ``svn`` is not installed.
        N)rq   rz   )rs   Zvcs_versionr   r   r   get_vcs_version   s
    	zSubversion.get_vcs_versionc             C   s3   |  j  s d g S|  j   } | d k r/ d g Sg  S)aX  Return options to be used on calls to Subversion that contact the server.

        These options are applicable for the following ``svn`` subcommands used
        in this class.

            - checkout
            - export
            - switch
            - update

        :return: A list of command line arguments to pass to ``svn``.
        z--non-interactiverR      z--force-interactive)rR   r|   )rp   r{   )rs   Zsvn_versionr   r   r   get_remote_call_options   s    		z"Subversion.get_remote_call_optionsc             C   s   |  j  |  \ } } t j d | |  t   R t j j |  rN t |  t d |  j	   | j
   | |  } |  j |  Wd QRXd S)z@Export the svn repository at the url to the destination locationz!Exporting svn repository %s to %sexportN)Zget_url_rev_optionsrA   rU   r   r!   r%   r'   r   r   r}   to_argsrd   )rs   r+   r;   rev_optionscmd_argsr   r   r   r~     s    

zSubversion.exportc             C   s`   | j    } t j d | | t |   t d d |  j   | j   | |  } |  j |  d  S)NzChecking out %s%s to %sr   z-q)Z
to_displayrA   rU   r   r   r}   r   rd   )rs   rm   r;   r   rev_displayr   r   r   r   	fetch_new0  s    zSubversion.fetch_newc             C   s5   t  d |  j   | j   | |  } |  j |  d  S)Nswitch)r   r}   r   rd   )rs   rm   r;   r   r   r   r   r   r   ?  s    zSubversion.switchc             C   s2   t  d |  j   | j   |  } |  j |  d  S)Nupdate)r   r}   r   rd   )rs   rm   r;   r   r   r   r   r   r   G  s    	zSubversion.update)zsvnr   r   r   r   )__name__
__module____qualname__rn   r#   	repo_nameschemesclassmethodr   staticmethodr   r3   r6   r:   r@   rE   r(   ro   rr   rz   r{   r}   r~   r   r   r   r   r   )r9   r   r   %   s*   	2!r   )$
__future__r   loggingr!   reZpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r   r   r   Zpip._internal.utils.subprocessr   Zpip._internal.utils.typingr	   Z pip._internal.vcs.versioncontrolr
   r   compiler]   rb   rf   re   Ztypingr   r   r   r   r   r   	getLoggerr   rA   r   registerr   r   r   r   <module>   s*   " ,