3
ÀÞL]±-  ã               @   sÜ   d dl m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	m
Z
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mZ d dlmZ ejeƒZG dd„ deƒZejeƒ dS )é    )Úabsolute_importN)Ú
indent_log)Údisplay_pathÚrmtreeÚsplit_auth_from_netloc)ÚMYPY_CHECK_RUNNING)ÚVersionControlÚvcszurl="([^"]+)"zcommitted-rev="(\d+)"z\s*revision="(\d+)"z<url>(.*)</url>)ÚListÚOptionalÚTuple)Ú
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‡  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-69lrc5qx/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r2g |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ÚfilesÚ
entries_fnÚdirurlÚlocalrevr   r   r   Úget_revision*   s"    

zSubversion.get_revisionc                s"   |dkrt t| ƒj||ƒS t|ƒ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   r2   F   s    zSubversion.get_netloc_and_authc                s2   t t| ƒj|ƒ\}}}|jdƒr(d| }|||fS )Nzssh://zsvn+)r1   r   Úget_url_rev_and_authr%   )r   Úurlr   Ú	user_pass)r5   r   r   r6   S   s    
zSubversion.get_url_rev_and_authc             C   s(   g }| r|d| g7 }|r$|d|g7 }|S )Nz
--usernamez
--passwordr   )ÚusernameÚpasswordÚ
extra_argsr   r   r   Úmake_rev_args[   s    zSubversion.make_rev_argsc             C   sV   |}xBt jjt jj|dƒƒsF|}t jj|ƒ}||krtjd|ƒ d S q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_urle   s    zSubversion.get_remote_urlc             C   sp  ddl m} tjj|| jdƒ}tjj|ƒrHt|ƒ�}|jƒ }W d Q R X nd}|j	dƒsj|j	dƒsj|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dƒ}dd„ tj|ƒD ƒdg }n^y<| jdd|gdd�}	tj|	ƒjdƒ}dd„ tj|	ƒD ƒ}W n  |k
�rR   d g  }}Y nX |�rdt|ƒ}
nd}
||
fS )Nr   )ÚInstallationErrorr   Ú Ú8Ú9Ú10z

é   c             S   s,   g | ]$}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: %ré   c             S   s   g | ]}t |jd ƒƒ‘qS )rN   )rJ   Úgroup)rK   Úmr   r   r   rM   ‘   s    Úinfoz--xmlF)Úshow_stdoutc             S   s   g | ]}t |jd ƒƒ‘qS )rN   )rJ   rO   )rK   rP   r   r   r   rM       s    )Zpip._internal.exceptionsrB   r   r!   r"   r   r#   ÚopenÚreadr%   ÚlistÚmapÚstrÚ
splitlinesÚsplitÚ_svn_xml_url_reÚsearchÚ
ValueErrorrO   Ú_svn_rev_reÚfinditerÚrun_commandÚ_svn_info_xml_url_reÚ_svn_info_xml_rev_rer&   )r   r'   rB   Úentries_pathÚfÚdatar7   ÚrevsÚmatchÚxmlr   r   r   r   r$   z   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                s0   |d krt jjƒ }|| _d | _tt| ƒjƒ  d S )N)ÚsysÚstdinÚisattyÚuse_interactiveÚ_vcs_versionr1   r   Ú__init__)Úselfrn   )r5   r   r   rp   ±   s
    
zSubversion.__init__c             C   sp   d}| j dgdd�}|j|ƒs"f S |t|ƒd… jƒ d }|jdƒ}yttt|ƒƒ}W n tk
rj   f S 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	--versionF)rR   Nr   Ú.)r_   r%   rI   rY   ÚtuplerV   rJ   r\   )rq   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)ro   rv   )rq   Zvcs_versionr   r   r   Úget_vcs_versionÛ   s
    
zSubversion.get_vcs_versionc             C   s&   | j sdgS | jƒ }|dkr"dgS g 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-interactiverN   é   z--force-interactive)rN   rx   )rn   rw   )rq   Zsvn_versionr   r   r   Úget_remote_call_optionsð   s    	z"Subversion.get_remote_call_optionsc             C   sr   | j |ƒ\}}tjd||ƒ tƒ �F tjj|ƒr8t|ƒ dg| jƒ  |j	ƒ  ||g }| j
|dd� W dQ R X dS )z@Export the svn repository at the url to the destination locationz!Exporting svn repository %s to %sÚexportF)rR   N)Zget_url_rev_optionsr=   rQ   r   r   r!   r#   r   ry   Úto_argsr_   )rq   r'   r7   Úrev_optionsÚcmd_argsr   r   r   rz     s    zSubversion.exportc             C   sJ   |j ƒ }tjd||t|ƒƒ ddg| jƒ  |jƒ  ||g }| j|ƒ d S )NzChecking out %s%s to %sr   z-q)Z
to_displayr=   rQ   r   ry   r{   r_   )rq   rh   r7   r|   Úrev_displayr}   r   r   r   Ú	fetch_new  s    
 zSubversion.fetch_newc             C   s,   dg| j ƒ  |jƒ  ||g }| j|ƒ d S )NÚswitch)ry   r{   r_   )rq   rh   r7   r|   r}   r   r   r   r€   -  s    zSubversion.switchc             C   s*   dg| j ƒ  |jƒ  |g }| j|ƒ d S )NÚupdate)ry   r{   r_   )rq   rh   r7   r|   r}   r   r   r   r�   3  s    zSubversion.update)r   r   r   r   r   )N)Ú__name__Ú
__module__Ú__qualname__ri   r   Ú	repo_nameÚschemesÚclassmethodr   Ústaticmethodr   r/   r2   r6   r<   rA   r$   rj   rp   rv   rw   ry   rz   r   r€   r�   Ú__classcell__r   r   )r5   r   r      s*   
2!r   ) Ú
__future__r   Úloggingr   Úrerk   Zpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r   r   Zpip._internal.utils.typingr   Z pip._internal.vcs.versioncontrolr   r	   ÚcompilerZ   r]   ra   r`   Útypingr
   r   r   r   Ú	getLoggerr‚   r=   r   Úregisterr   r   r   r   Ú<module>   s(   




   