B
    Tò†[S  ã               @   s˜   d dl mZmZmZmZ d dlZd dlZd dlZej 	d¡Z
ejZe
rJdndZeeee
r\dndƒZeeedƒZd	d
„ Zdd„ Zdd„ Zdd„ Zeƒ ZdS )é    )ÚbasenameÚdirnameÚjoinÚexistsNÚwinZScriptsÚbinz	conda.exeÚcondaz	conda.batc              C   s   dd l } | jjS )Nr   )Zconda.configZconfigZroot_dir)r   © r	   úYlib/python3.7/site-packages/anaconda_client-1.7.2-py3.7.egg/binstar_client/utils/conda.pyÚ_import_conda_root   s    r   c              C   s(   t } trtt ƒrt nt} t| ƒs$d } | S )N)Ú	CONDA_EXEÚWINDOWSr   Ú	CONDA_BAT)Úcommandr	   r	   r
   Ú_get_conda_exe   s    r   c           
   C   sX   t ƒ } | sd S y(t | ddg¡ d¡}t |¡}|d S  tttjfk
rR   d S X d S )NÚinfoz--jsonzutf-8Zroot_prefix)	r   Ú
subprocessZcheck_outputÚdecodeÚjsonÚloadsÚ
ValueErrorÚKeyErrorZCalledProcessError)r   ÚoutputZ
conda_infor	   r	   r
   Ú_conda_root_from_conda_info   s    
r   c              C   sH   y
t ƒ } W n8 tk
rB   ttƒ}t|ƒdkr8t|ƒ} ntƒ } Y nX | S )zsGet the PREFIX of the conda installation.

    Returns:
        str: the ROOT_PREFIX of the conda installation
    Zenvs)r   ÚImportErrorr   ÚCONDA_PREFIXr   r   )Z
conda_rootZenvs_dirr	   r	   r
   Úget_conda_root+   s    

r   )Úos.pathr   r   r   r   r   Úsysr   ÚplatformÚ
startswithr   Úprefixr   ZBIN_DIRr   r   r   r   r   r   Z
CONDA_ROOTr	   r	   r	   r
   Ú<module>   s   
