B
    lz]M"                 @   s   d dl mZmZmZmZ d dlZd dlmZmZ d dl	Z
d dlZddlmZmZmZ ddlmZ dd Zd	d
 Zdd Zdd ZdddZdddZdddZdd Zedejd edkre  dS )    )absolute_importdivisionprint_functionunicode_literalsN)abspathisdir   )ensure_text_typeon_win	text_type)shellsc             C   s   | dkr<|dkr&ddl m} |dqddl m} |dn^| dkrx|dkrbddl m} |dqddl m} |d	n"ddl m} |d
ttjd  d S )N)z
..activatez
..checkenv)zcmd.exezpowershell.exer   )CondaSystemExitzUsage: activate ENV

Adds the 'Scripts' and 'Library\bin' directory of the environment ENV to the front of PATH.
ENV may either refer to just the name of the environment, or the full
prefix path.zUsage: source activate ENV

Adds the 'bin' directory of the environment ENV to the front of PATH.
ENV may either refer to just the name of the environment, or the full
prefix path.z..deactivatezUsage: deactivate

Removes the environment prefix, 'Scripts' and 'Library\bin' directory
of the environment ENV from the front of PATH.zuUsage: source deactivate

Removes the 'bin' directory of the environment activated with 'source
activate' from PATH. z No help available for command %s   )
exceptionsr   r	   sysargv)Zcommandshellr    r   1lib/python3.7/site-packages/conda/cli/activate.pyhelp   s$    r   c             C   s   ddl m} ||| jS )Nr   )locate_prefix_by_name)base.contextr   Z	envs_dirs)Zctxnamer   r   r   r   r   5   s    r   c             C   s   |rt | ni }ddlm} |d | kr|td| s||d | }tt|drbt|d}qddlm	} |d| nt
|| d	tjj}|S )
Nr   )contextsepz	[a-zA-Z]:Z	path_from")CondaValueErrorzCould not find environment: %s/)r   r   r   regexmatchr   r   stripr   r   r   replaceospathr   )argr   	shelldictr   Znative_pathprefixr   r   r   r   prefix_from_arg:   s    r'   c             c   s   t rl| dV  tj| dddV  tj| dddV  tj| ddV  tj| dV  tj| dV  ntj| dV  d S )N\Libraryz	mingw-w64binZusrZScripts)r
   rstripr"   r#   join)r&   r   r   r   _get_prefix_pathsM   s    r-   Tc                sJ   |rt | ni  t| |}|r4 fddt|D S dd t|D S d S )Nc                s   g | ]} d  |qS )path_tor   ).0r#   )r%   r   r   
<listcomp>_   s    z$binpath_from_arg.<locals>.<listcomp>c             S   s   g | ]}|qS r   r   )r/   r#   r   r   r   r0   a   s    )r   r'   r-   )r$   r   going_to_shellr&   r   )r%   r   binpath_from_argY   s
    
r2   c             C   s2   d | }tr"|r"tdd|}n|dd}|S )zf
    Format a path list, e.g., of bin paths to be added or removed,
    for user-friendly output.
    z and z(?<!\\)\\(?!\\)z\\\\z\\r(   )r,   r
   r   subr!   )pathsZescape_backslashesr#   r   r   r   pathlist_to_strd   s
    
r5   c             C   s@   |rt | ni }t| ||}|r0|d |}ntj|}|S )Npathsep)r   r2   r,   r"   r6   )r&   r   r1   r%   Zbinpathr#   r   r   r   get_activate_pathr   s    r7   c           
   C   s  t dtjd ddlm}  ddlm} |  tdd tjD }d|ksPd	|krbt	|d
 |d  t
|dkrx|d }nd}td|d
 rt
|}|dkrd}|dk rddlm} |||| d|d
 |dkrddlm} |||| |dd  d|d
 |d
 dkr<t t|d |d td n|d
 dkrt|d |d}tdrtdt| dtjtd d
}	n$tdt| dtjtd d
}	t| d |	}	t |	 td n|d
 dkrt
|dk rddlm}
 |
dt
|dkr(ddlm}
 |
d |d  |  krHtd yt|d | W n< tk
r } zdd!lm} |t|W d d }~X Y nX td n:|d
 d"krdd#l m!} t"|j#}ndd!lm} |d$t | d S )%NzWARNING: The module conda.cli.activate is deprecated. It will be removed in a future feature release (i.e. minor version release).)filer   )ROOT_ENV_NAME)initialize_loggingc             s   s   | ]}t |V  qd S )N)r	   )r/   sr   r   r   	<genexpr>   s    zmain.<locals>.<genexpr>z-hz--helpr    z^..(?:de|)activate$   )TooFewArgumentsErrorz`{} expected exactly two arguments:                                            shell and env name)TooManyArgumentsErrorza{} expected exactly two arguments:                                             shell and env namez
..activate   Tr   z..deactivate.pathFZ_CONDA_HOLDz%s(:?)zCONDA_PATH_PLACEHOLDER\1PATHr.   z
..checkenv)ArgumentErrorz<Invalid arguments to checkenv.  Need shell and env name/pathz&did not expect more than one argument.)r   z..changeps1)r   zunexpected command)$printr   stderrZbase.constantsr9   Zgateways.loggingr:   tupler   r   lenr   r   r   r?   formatr@   r7   exitr"   getenvr3   escapeenvironstrr   rC   lowerr'   
ValueErrorr   r   r   r   intZ	changeps1)r9   r:   Zsys_argvr   Zarg_numZnum_expectedr?   r@   Zactivation_pathnew_pathrC   er   r   r#   r   r   r   main~   st    





rS   z]WARNING: The conda.cli.activate module is deprecated and will be removed in a future release.)r8   __main__)T)T)T)Z
__future__r   r   r   r   r"   os.pathr   r   rer   r   Zcommon.compatr	   r
   r   Zutilsr   r   r   r'   r-   r2   r5   r7   rS   rD   rE   __name__r   r   r   r   <module>   s$   &


e
