
^V!                 @   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 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 j d  Z e j d  Z e j e  Z Gd d   d e  Z d d   Z e j e  d S)    )absolute_importN)parse)Link)rmtreedisplay_path)
indent_log)vcsVersionControlzurl="([^"]+)"zcommitted-rev="(\d+)"z	URL: (.+)zRevision: (.+)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 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   | j  d  j |  j  s, t d |   |  j d | g d d d i d d 6} t j |  } | s t j d	 t	 |   t j
 d
 |  d S| j d  j   } t j |  } | s t j d t	 |   t j
 d
 |  | d f S| | j d  f S)z/Returns (url, revision), where both are strings/zBad directory: %sinfoshow_stdoutFextra_environCLANGz'Cannot determine URL of svn checkout %sz!Output that cannot be parsed: 
%sN   z,Cannot determine revision of svn checkout %s)NN)rstripendswithdirnameAssertionErrorrun_command_svn_url_researchloggerwarningr   debuggroupstrip_svn_revision_re)selflocationoutputmatchurl r*   1/tmp/pip-build-9m6vxulb/pip/pip/vcs/subversion.pyget_info   s,    
zSubversion.get_infoc             C   s   |  j    \ } } t | |  } t j d | |  t   H t j j |  r] t |  n  |  j	 d g | | | g d d Wd QXd S)z@Export the svn repository at the url to the destination locationz!Exporting svn repository %s to %sexportr   FN)
get_url_revget_rev_optionsr   r   r   ospathexistsr   r   )r%   r&   r)   revrev_optionsr*   r*   r+   r-   ;   s    
zSubversion.exportc             C   s"   |  j  d g | | | g  d  S)Nswitch)r   )r%   destr)   r4   r*   r*   r+   r5   I   s    zSubversion.switchc             C   s   |  j  d g | | g  d  S)Nupdate)r   )r%   r6   r4   r*   r*   r+   r7   L   s    zSubversion.updatec             C   s   |  j    \ } } t | |  } | r4 d | } n d } |  j | | | |  r t j d | | t |   |  j d d g | | | g  n  d  S)Nz (to revision %s) zChecking out %s%s to %sr   z-q)r.   r/   check_destinationr   r   r   r   )r%   r6   r)   r3   r4   rev_displayr*   r*   r+   obtainO   s    zSubversion.obtainc             C   s   x | D] } t  |  j } | s( q n  d | k r_ d j | j d  d  d   j   } n | } | | j k r | j d d  d Sq Wd  S)N-r   #r   )r   egg_fragmentjoinsplitlowerkey)r%   distdependency_linksr)   r?   rC   r*   r*   r+   get_location_   s    +zSubversion.get_locationc       
      C   s   d } x t  j |  D] \ } } } |  j | k rJ g  | d d  <q n  | j |  j  t  j j | |  j d  } t  j j |  s q n  |  j |  \ } } | | k r | d }	 n- | s | j |	  r g  | d d  <q n  t	 | |  } q W| S)zR
        Return the maximum revision for all files under a given location
        r   Nentriesr   )
r0   walkr   remover1   r@   r2   _get_svn_url_rev
startswithmax)
r%   r&   revisionbasedirsfiles
entries_fndirurllocalrevbase_urlr*   r*   r+   get_revisionm   s"    zSubversion.get_revisionc                sA   t  t |   j   \ } } | j d  r7 d | } n  | | f S)Nzssh://zsvn+)superr
   r.   rK   )r%   r)   r3   )	__class__r*   r+   r.      s    zSubversion.get_url_revc             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   )r0   r1   r2   r@   r   r   r    rJ   )r%   r&   orig_locationlast_locationr*   r*   r+   get_url   s    $zSubversion.get_urlc             C   s  d d l  m } t j j | |  j d  } t j j |  ra t |   } | j   } Wd  QXn 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  rWt j |  } | s"t d |   n  | j d  } d d   t j |  D d g } nx yV |  j d d | g d d }	 t j |	  j d  } d d   t j |	  D } Wn | k
 rd  g  } } Yn X| rt |  }
 n d }
 | |
 f S)Nr   )InstallationErrorrG   r8   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: %rr   c             S   s%   g  |  ] } t  | j d     q S)r   )rb   r"   )rc   mr*   r*   r+   re      s   	 r   z--xmlr   Fc             S   s%   g  |  ] } t  | j d     q S)r   )rb   r"   )rc   rf   r*   r*   r+   re      s   	 )pip.exceptionsr[   r0   r1   r@   r   r2   openreadrK   listmapstr
splitlinesrA   _svn_xml_url_rer   
ValueErrorr"   _svn_rev_refinditerr   _svn_info_xml_url_re_svn_info_xml_rev_rerL   )r%   r&   r[   entries_pathfdatar)   revsr(   xmlr3   r*   r*   r+   rJ      s>    !&	 zSubversion._get_svn_url_revc             C   s[   |  j  |  } | d  k r d  S| j   j d d  d } |  j |  } d | | | f S)Nr<   r   r   zsvn+%s@%s#egg=%s)rZ   egg_namerA   rU   )r%   rD   r&   repoegg_project_namer3   r*   r*   r+   get_src_requirement   s    zSubversion.get_src_requirementc             C   s   d S)z&Always assume the versions don't matchFr*   )r%   r6   r4   r*   r*   r+   check_version   s    zSubversion.check_version)zsvnr   r   r   r   )__name__
__module____qualname__namer   	repo_nameschemesr,   r-   r5   r7   r;   rF   rU   r.   rZ   rJ   r|   r}   r*   r*   )rW   r+   r
      s    ,	r
   c             C   s   | r d | g } n g  } t  j |   } t | d  rO | j | j } } nl | d } d | k r | j d  d } d | k r | j d d  \ } } q | d  } } n d	 \ } } | r | d | g 7} n  | r | d | g 7} n  | S)
Nz-rusernamer   @r   :z
--usernamez
--password)NN)urllib_parseurlsplithasattrr   passwordrA   )r)   r3   r4   rr   r   netlocauthr*   r*   r+   r/      s$    
r/   )
__future__r   loggingr0   reZpip._vendor.six.moves.urllibr   r   	pip.indexr   	pip.utilsr   r   pip.utils.loggingr   pip.vcsr   r	   compilern   rp   r   r$   rs   rr   	getLoggerr~   r   r
   r/   registerr*   r*   r*   r+   <module>   s$   