3
gQ                 @   s   d dl Z d dlZd dlZd dlmZmZ d dlmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZmZmZ ejeZG dd	 d	eZeje dS )
    N)ListOptional)
BadCommandInstallationError)
HiddenTextdisplay_path)make_command)path_to_url)
RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsc                   s   e Zd ZdZdZdZd"Zeee	e d	d
dZ
eeeddddZeeeddddZeeeddddZeeedddZeeedddZeeedddZeeee edddZeeee dddZeeee d fd d!Z  ZS )#	Mercurialhgz.hgclonehg+filehg+httphg+httpshg+sshhg+static-http)revreturnc             C   s   | gS )N )r   r   r   Y/var/www/tester-filtro-web/env/lib/python3.6/site-packages/pip/_internal/vcs/mercurial.pyget_base_rev_args    s    zMercurial.get_base_rev_argsN)desturlrev_optionsr   c             C   sP   |j  }tjd||t| | jtddd|| | jtdd|j |d d S )NzCloning hg %s%s to %sr   z
--noupdatez-qupdate)cwd)
to_displayloggerinfor   run_commandr   to_args)selfr   r   r   rev_displayr   r   r   	fetch_new$   s    
zMercurial.fetch_newc       	      C   s   t jj|| jd}tj }y>|j| |jdd|j t	|d}|j
| W d Q R X W n6 ttjfk
r } ztjd|| W Y d d }~X n X tdd|j }| j||d d S )	NZhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr   z-q)r   )ospathjoindirnameconfigparserRawConfigParserreadsetsecretopenwriteOSErrorNoSectionErrorr!   warningr   r$   r#   )	r%   r   r   r   Zrepo_configconfigconfig_fileexccmd_argsr   r   r   switch2   s    
 zMercurial.switchc             C   s4   | j ddg|d tdd|j }| j ||d d S )Npullz-q)r   r   )r#   r   r$   )r%   r   r   r   r<   r   r   r   r   @   s    zMercurial.update)locationr   c             C   s4   | j ddgdd|dj }| j|r,t|}|j S )NZ
showconfigzpaths.defaultFT)show_stdoutstdout_onlyr   )r#   strip_is_local_repositoryr	   )clsr?   r   r   r   r   get_remote_urlE   s    
zMercurial.get_remote_urlc             C   s   | j ddgdd|dj }|S )zW
        Return the repository-local changeset revision number, as an integer.
        parentsz--template={rev}FT)r@   rA   r   )r#   rB   )rD   r?   Zcurrent_revisionr   r   r   get_revisionQ   s    zMercurial.get_revisionc             C   s   | j ddgdd|dj }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rF   z--template={node}FT)r@   rA   r   )r#   rB   )rD   r?   Zcurrent_rev_hashr   r   r   get_requirement_revision^   s    z"Mercurial.get_requirement_revision)r   namer   c             C   s   dS )z&Always assume the versions don't matchFr   )rD   r   rI   r   r   r   is_commit_id_equall   s    zMercurial.is_commit_id_equalc             C   sD   | j dgdd|dj }tjj|s:tjjtjj||}t||S )z
        Return the path to Python project root, relative to the repo root.
        Return None if the project root is in the repo root.
        rootFT)r@   rA   r   )r#   rB   r+   r,   isabsabspathr-   r   )rD   r?   	repo_rootr   r   r   get_subdirectoryq   s
    zMercurial.get_subdirectoryc                sv   t  j|}|r|S y| jdg|ddddd}W n2 tk
rP   tjd| d S  tk
rb   d S X tjj	|j
dS )NrK   FTraise)r   r@   rA   on_returncodelog_failed_cmdzIcould not determine if %s is under hg control because hg is not availablez
)superget_repository_rootr#   r   r!   debugr   r+   r,   normpathrstrip)rD   r?   locr)	__class__r   r   rT      s&    zMercurial.get_repository_root)r   r   r   r   r   )__name__
__module____qualname__rI   r.   	repo_nameschemesstaticmethodstrr   r   r   r
   r'   r=   r   classmethodrE   rG   rH   r   boolrJ   rO   rT   __classcell__r   r   )rZ   r   r      s2       r   )r/   loggingr+   typingr   r   pip._internal.exceptionsr   r   pip._internal.utils.miscr   r   pip._internal.utils.subprocessr   pip._internal.utils.urlsr	    pip._internal.vcs.versioncontrolr
   r   r   r   	getLoggerr[   r!   r   registerr   r   r   r   <module>   s   
 