B
    Uvg                 @   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               @   sl   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dd Z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-r_9ig3yj/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   )r   r   r"   r   r   r   get_urlC   s    
zMercurial.get_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_revisionK   s    zMercurial.get_revisionc             C   s   | j ddgd|d }|S )Nr@   z--template={node}F)r   r   )r   r=   )r   r   current_rev_hashr   r   r   get_revision_hashQ   s    zMercurial.get_revision_hashc             C   sJ   |  |}| ds d| }| |}| ddd }t|||S )Nzhg:zhg+-   r   )r?   lower
startswithrD   egg_namesplitr   )r   distr   reporC   egg_project_namer   r   r   get_src_requirementW   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_equal`   s    zMercurial.is_commit_id_equalN)__name__
__module____qualname__rO   r-   	repo_nameschemesr   r   r&   r:   r   r?   rB   rD   rN   rP   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	   	getLoggerrQ   r   r
   registerr   r   r   r   <module>   s   
U