B
    '\-                 @   s   d dl mZmZmZmZ d dlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ eeZG dd dZejZejZdd ZdS )    )absolute_importdivisionprint_functionunicode_literals)	getLogger   )do_call   )encode_arguments)generate_parser)SEARCH_PATH)context)CaptureTargetargvcaptured)conda_exception_handler)initialize_std_loggersc               @   s8   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdS )CommandsZcleanZconfigZcreateinfoZinstallhelplistremovesearchupdaterunN)__name__
__module____qualname__ZCLEANZCONFIGZCREATEINFOZINSTALLZHELPZLISTZREMOVEZSEARCHZUPDATEZRUN r   r   3lib/python3.7/site-packages/conda/cli/python_api.pyr      s   r   c          
   O   sX  t   |dd}|dt}|dt}|dt}t }t|}|d|  ||}d|_t	j
||d dd	lm}	 td
|	| yTtdgt| 8 t||"}
|rtt||}n
t||}W dQ R X W dQ R X W nL tk
r* } z,td|
j|
j |
j|
j |_|_|W dd}~X Y nX |p4d}td|
j|
j| |
j|
j|fS )a  Runs a conda command in-process with a given set of command-line interface arguments.

    Differences from the command-line interface:
        Always uses --yes flag, thus does not ask for confirmation.

    Args:
        command: one of the Commands.X
        *arguments: instructions you would normally pass to the conda comamnd on the command line
                    see below for examples. Be very careful to delimit arguements exactly as you
                    want them to be delivered. No 'combine then split at spaces' or other
                    information destroying processing gets performed on the arguments.
        **kwargs: special instructions for programmatic overrides
          use_exception_handler: defaults to False.  False will let the code calling
              `run_command` handle all exceptions.  True won't raise when an exception
              has occured, and instead give a non-zero return code
          search_path: an optional non-standard search path for configuration information
              that overrides the default SEARCH_PATH
          stdout: Define capture behavior for stream sys.stdout. Defaults to STRING.
              STRING captures as a string.  None leaves stream untouched.
              Otherwise redirect to file-like object stdout.
          stderr: Define capture behavior for stream sys.stderr. Defaults to STRING.
              STRING captures as a string.  None leaves stream untouched.
              STDOUT redirects to stdout target and returns None as stderr value.
              Otherwise redirect to file-like object stderr.

    Returns: a tuple of stdout, stderr, and return_code.
        stdout, stderr are either strings, None or the corresponding file-like function argument.

    Examples:
        >>  run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask",
                        use_exception_handler=True)
        >>  run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask")
        >>  run_command(Commands.CREATE, ["-n", "newenv", "python=3", "flask"], search_path=())


    use_exception_handlerFsearch_pathstdoutstderrr   T)r"   Zargparse_args)list2cmdlinezexecuting command >>>  conda %sZ
python_apiNz
  stdout: %s
  stderr: %sz,
  stdout: %s
  stderr: %s
  return_code: %s)r   popr   STRINGr   r   insert
parse_argsZyesr   __init__
subprocessr%   logdebugr   r
   r   r   r   	Exceptionr#   r$   )ZcommandZ	argumentskwargsr!   Zconfiguration_search_pathr#   r$   pargsr%   cZreturn_codeer   r   r    run_command&   s6    %
 "
r4   N)Z
__future__r   r   r   r   Zloggingr   Zconda_argparser   compatr
   mainr   Zbase.constantsr   Zbase.contextr   Z	common.ior   r   r   
exceptionsr   Zgateways.loggingr   r   r,   r   r'   ZSTDOUTr4   r   r   r   r    <module>   s   