B
    Kkdw                 @   s   d dl m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eZG dd	 d	eZee dS )
    )absolute_importN)configparser)path_to_url)display_pathmake_vcs_requirement_url)TempDirectory)VersionControlvcsc               @   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edd Zedd Zedd Zedd Zdd ZdS )	Mercurialhgz.hgclone)r   zhg+httpzhg+httpszhg+sshzhg+static-httpc             C   s   |gS )N )selfrevr   r   </tmp/pip-install-gxxfd9b7/pip/pip/_internal/vcs/mercurial.pyget_base_rev_args   s    zMercurial.get_base_rev_argsc          	   C   s<   t dd(}| |j | jd|gd|jd W dQ R X dS )z?Export the Hg repository at the url to the destination locationexport)kindarchiveF)show_stdoutcwdN)r   unpackpathrun_command)r   locationtemp_dirr   r   r   r      s    zMercurial.exportc             C   sR   |  }td||t| | ddd||g ddg|  }| j||d d S )NzCloning hg %s%s to %sr   z
--noupdatez-qupdate)r   )
to_displayloggerinfor   r   to_args)r   desturlrev_optionsrev_displaycmd_argsr   r   r   	fetch_new"   s    
zMercurial.fetch_newc       	   
   C   s   t j|| jd}t }y<|| |dd| t|d}|	| W d Q R X W n6 t
tjfk
r } ztd|| W d d }~X Y n X ddg|  }| j||d d S )	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr   z-q)r   )osr   joindirnamer   SafeConfigParserreadsetopenwriteOSErrorNoSectionErrorr   warningr    r   )	r   r!   r"   r#   repo_configconfigconfig_fileexcr%   r   r   r   switch.   s    
zMercurial.switchc             C   s4   | j ddg|d ddg|  }| j ||d d S )Npullz-q)r   r   )r   r    )r   r!   r"   r#   r%   r   r   r   r   >   s    zMercurial.updatec             C   s2   | j ddgd|d }| |r*t|}| S )N
showconfigzpaths.defaultF)r   r   )r   strip_is_local_repositoryr   )clsr   r"   r   r   r   get_remote_urlC   s    
zMercurial.get_remote_urlc             C   s   | j ddgd|d }|S )Nparentsz--template={rev}F)r   r   )r   r=   )r?   r   current_revisionr   r   r   get_revisionL   s    zMercurial.get_revisionc             C   s   | j ddgd|d }|S )NrA   z--template={node}F)r   r   )r   r=   )r?   r   current_rev_hashr   r   r   get_revision_hashS   s    zMercurial.get_revision_hashc             C   s6   |  |}| ds d| }| |}t|||S )Nzhg:zhg+)r@   lower
startswithrE   r   )r?   r   project_namereporD   r   r   r   get_src_requirementZ   s
    

zMercurial.get_src_requirementc             C   s   dS )z&Always assume the versions don't matchFr   )r   r!   namer   r   r   is_commit_id_equalb   s    zMercurial.is_commit_id_equalN)__name__
__module____qualname__rK   r-   	repo_nameschemesr   r   r&   r:   r   classmethodr@   rC   rE   rJ   rL   r   r   r   r   r
      s   		r
   )
__future__r   loggingr+   Zpip._vendor.six.movesr   pip._internal.downloadr   pip._internal.utils.miscr   r   pip._internal.utils.temp_dirr   pip._internal.vcsr   r	   	getLoggerrM   r   r
   registerr   r   r   r   <module>   s   
W