B
    ãUvgü  ã               @   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 d dl	m
Z
mZmZmZ d dlmZmZ e d¡Ze d¡Ze d	¡Ze d
¡Ze e¡ZG dd„ deƒZe e¡ dS )é    )Úabsolute_importN)ÚLink)Ú
indent_log)Údisplay_pathÚmake_vcs_requirement_urlÚrmtreeÚsplit_auth_from_netloc)ÚVersionControlÚvcszurl="([^"]+)"zcommitted-rev="(\d+)"z\s*revision="(\d+)"z<url>(.*)</url>c                   s˜   e Zd ZdZdZdZdZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Z‡  ZS )!Ú
SubversionÚsvnz.svnÚcheckout)r   zsvn+sshzsvn+httpz	svn+httpszsvn+svnc             C   s   d|gS )Nz-r© )ÚselfÚrevr   r   ú=/tmp/pip-install-r_9ig3yj/pip/pip/_internal/vcs/subversion.pyÚget_base_rev_args   s    zSubversion.get_base_rev_argsc          	   C   sl   |   | j¡\}}t d||¡ tƒ > tj |¡r:t|ƒ dg| 	¡  ||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)Úshow_stdoutN)Úget_url_rev_optionsÚurlÚloggerÚinfor   ÚosÚpathÚexistsr   Úto_argsÚrun_command)r   Úlocationr   Úrev_optionsÚcmd_argsr   r   r   r       s    zSubversion.exportc             C   sB   |  ¡ }t d||t|ƒ¡ ddg| ¡  ||g }|  |¡ d S )NzChecking out %s%s to %sr   z-q)Ú
to_displayr   r   r   r   r   )r   Údestr   r   Úrev_displayr    r   r   r   Ú	fetch_new-   s    
zSubversion.fetch_newc             C   s$   dg|  ¡  ||g }|  |¡ d S )NÚswitch)r   r   )r   r"   r   r   r    r   r   r   r%   8   s    zSubversion.switchc             C   s"   dg|  ¡  |g }|  |¡ d S )NÚupdate)r   r   )r   r"   r   r   r    r   r   r   r&   <   s    zSubversion.updatec             C   sf   x`|D ]X}t |ƒj}|sqd|kr@d | d¡d d… ¡ ¡ }n|}||jkr| dd¡d S qW d S )Nú-éÿÿÿÿú#é   r   )r   Úegg_fragmentÚjoinÚsplitÚlowerÚkey)r   ÚdistÚdependency_linksr   r+   r/   r   r   r   Úget_location@   s    


zSubversion.get_locationc       	      C   s¬   d}x¢t  |¡D ]”\}}}| j|kr2g |dd…< q| | j¡ t j || jd¡}t j |¡s^q|  |¡\}}||kr~|d }n|rŒ| |¡sšg |dd…< qt	||ƒ}qW |S )zR
        Return the maximum revision for all files under a given location
        r   NÚentriesú/)
r   ÚwalkÚdirnameÚremover   r,   r   Ú_get_svn_url_revÚ
startswithÚmax)	r   r   ÚrevisionÚbaseÚdirsÚfilesÚ
entries_fnÚdirurlÚlocalrevr   r   r   Úget_revisionN   s"    

zSubversion.get_revisionc                s"   |dkrt t| ƒ ||¡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   rE   i   s    
zSubversion.get_netloc_and_authc                s2   t t| ƒ |¡\}}}| d¡r(d| }|||fS )Nzssh://zsvn+)rD   r   Úget_url_rev_and_authr9   )r   r   r   Ú	user_pass)rH   r   r   rI   v   s    
zSubversion.get_url_rev_and_authc             C   s(   g }|r|d|g7 }|r$|d|g7 }|S )Nz
--usernamez
--passwordr   )r   ÚusernameÚpasswordÚ
extra_argsr   r   r   Úmake_rev_args}   s    zSubversion.make_rev_argsc             C   sV   |}xBt j t j |d¡¡sF|}t j |¡}||krt d|¡ d S qW |  |¡d S )Nzsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)r   )r   r   r   r,   r6   r   Úwarningr8   )r   r   Úorig_locationÚlast_locationr   r   r   Úget_url†   s    zSubversion.get_urlc          	   C   sp  ddl m} tj || jd¡}tj |¡rHt|ƒ}| ¡ }W d Q R X nd}| 	d¡sj| 	d¡sj| 	d¡r¬t
ttj| d¡ƒƒ}|d d= |d d	 }d
d„ |D ƒdg }n¨| 	d¡röt |¡}|sÐtd| ƒ‚| d¡}dd„ t |¡D ƒdg }n^y<| jdd|gdd}	t |	¡ d¡}dd„ t |	¡D ƒ}W n  |k
rR   d g  }}Y nX |rdt|ƒ}
nd}
||
fS )Nr   )ÚInstallationErrorr3   Ú Ú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: %rr*   c             S   s   g | ]}t | d ¡ƒ‘qS )r*   )r[   Úgroup)r\   Úmr   r   r   r^   °   s    r   z--xmlF)r   c             S   s   g | ]}t | d ¡ƒ‘qS )r*   )r[   r_   )r\   r`   r   r   r   r^   º   s    )Úpip._internal.exceptionsrS   r   r   r,   r6   r   ÚopenÚreadr9   ÚlistÚmapÚstrÚ
splitlinesr-   Ú_svn_xml_url_reÚsearchÚ
ValueErrorr_   Ú_svn_rev_reÚfinditerr   Ú_svn_info_xml_url_reÚ_svn_info_xml_rev_rer:   )r   r   rS   Úentries_pathÚfÚdatar   ÚrevsÚmatchÚxmlr   r   r   r   r8   š   s>    








zSubversion._get_svn_url_revc             C   sH   |   |¡}|d krd S d| }|  |¡}| ¡  dd¡d }t|||ƒS )Nzsvn+r'   r*   r   )rR   rB   Úegg_namer-   r   )r   r0   r   Úrepor   Úegg_project_namer   r   r   Úget_src_requirementÆ   s    

zSubversion.get_src_requirementc             C   s   dS )z&Always assume the versions don't matchFr   )r   r"   Únamer   r   r   Úis_commit_id_equalÐ   s    zSubversion.is_commit_id_equal)Ú__name__Ú
__module__Ú__qualname__ry   r6   Ú	repo_nameÚschemesr   r   r$   r%   r&   r2   rB   rE   rI   rN   rR   r8   rx   rz   Ú__classcell__r   r   )rH   r   r      s$   	,
r   )Ú
__future__r   Úloggingr   ÚreÚpip._internal.models.linkr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   r   Úpip._internal.vcsr	   r
   Úcompilerh   rk   rn   rm   Ú	getLoggerr{   r   r   Úregisterr   r   r   r   Ú<module>   s   




 ?