U
    cUh                     @   s   d dl Z d dlZd dlZd dlmZ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eZG dd	 d	eZee dS )
    N)ListOptionalTuple)
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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)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-http)revreturnc                 C   s   d|  gS )Nz--rev= )r   r   r   [/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/vcs/mercurial.pyget_base_rev_args    s    zMercurial.get_base_rev_argsN)desturlrev_options	verbosityr   c                 C   s   |  }td||t| |dkr*d}n |dkr8d}n|dkrFd}nd}| td|||f  | jtd|| f |d d S )NzCloning hg %s%s to %sr   )z--quiet   r      )	--verbose)r   z--debugr   
--noupdateupdatecwd)r   r   )r   )
to_displayloggerinfor   run_commandr	   to_args)selfr   r   r   r   rev_displayflagsr   r   r   	fetch_new$   s&    zMercurial.fetch_new)r   r   r   r   c           	   
   C   s   t j|| jd}t }z>|| |dd|j t	|d}|
| W 5 Q R X W n6 ttjfk
r } ztd|| W 5 d }~X Y n X tdd| }| j||d d S )	NZhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr   -qr    )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   switch<   s    
 zMercurial.switchc                 C   s4   | j ddg|d tdd| }| j ||d d S )NZpullr.   r    r   )r%   r	   r&   )r'   r   r   r   r@   r   r   r   r   J   s    zMercurial.update)locationr   c                 C   s4   | j ddgdd|d }| |r,t|}| S )NZ
showconfigzpaths.defaultFTshow_stdoutstdout_onlyr!   )r%   strip_is_local_repositoryr
   )clsrB   r   r   r   r   get_remote_urlO   s    

zMercurial.get_remote_urlc                 C   s   | j ddgdd|d }|S )zW
        Return the repository-local changeset revision number, as an integer.
        parentsz--template={rev}FTrC   r%   rF   )rH   rB   Zcurrent_revisionr   r   r   get_revision[   s    
zMercurial.get_revisionc                 C   s   | j ddgdd|d }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rJ   z--template={node}FTrC   rK   )rH   rB   Zcurrent_rev_hashr   r   r   get_requirement_revisionh   s    
z"Mercurial.get_requirement_revision)r   namer   c                 C   s   dS )z&Always assume the versions don't matchFr   )rH   r   rN   r   r   r   is_commit_id_equalv   s    zMercurial.is_commit_id_equalc                 C   sD   | j dgdd|d }tj|s:tjt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.
        rootFTrC   )r%   rF   r/   r0   isabsabspathr1   r   )rH   rB   	repo_rootr   r   r   get_subdirectory{   s       
zMercurial.get_subdirectoryc                    sz   t  |}|r|S z| jdg|ddddd}W n6 tk
rR   td| Y d S  tk
rf   Y d S X tj	|
dS )NrP   FTraise)r!   rD   rE   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/   r0   normpathrstrip)rH   rB   locr	__class__r   r   rY      s*    
zMercurial.get_repository_root)__name__
__module____qualname__rN   r2   	repo_nameschemesstaticmethodstrr   r   r   r   intr*   rA   r   classmethodrI   rL   rM   r   boolrO   rT   rY   __classcell__r   r   r_   r   r      s4      r   )r3   loggingr/   typingr   r   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   	getLoggerra   r#   r   registerr   r   r   r   <module>   s   
 