a
    h5                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ ejdkrbd dlmZ zd dlZW n( ey   ejd ed Y n0 ddlmZmZmZ dd	lmZ ee d
ddZe ejdde ejddddejddde g dddejdddej!ddej"edej#ej$eeeddddZ%eej&e
e	e  d d!d"Z'e%( ej#ejd#d$e g d%d&dej$e)dd'd(d)Z*e%( ej#ej+d*dd+ej+d,dd+ej$eedd-d.d/Z,e%( ej#ej+d*dd+ej$edd0d1d2Z-e%( ej#ej+d*dd+ej$edd0d3d4Z.e%j(d5did6ej#ejd7dd8d9ej+d:d;ej/d<ej$e)ee dd=d>d?Z0ee eeef dd@dAdBZ1dS )C    N)contextmanager)AnyDictIOIteratorListOptionalwin32)PopenzkIt seems python-dotenv is not installed with cli option. 
Run pip install "python-dotenv[cli]" to fix this.   )dotenv_valuesset_key	unset_key)__version__)returnc                  C   s4   zt  } W n ty    Y dS 0 t j| d}|S )zZ
    Return a path for the ${pwd}/.env file.

    If pwd does not exist, return None.
    Nz.env)osgetcwdFileNotFoundErrorpathjoin)cwdr    r   F/var/www/html/assistant/venv/lib/python3.9/site-packages/dotenv/cli.pyenumerate_env   s    r   z-fz--fileT)Z	file_okayzNLocation of the .env file, defaults to .env file in current working directory.)defaulttypehelpz-qz--quotealways)r   neverautozbWhether to quote or not the variable values. Default mode is always. This does not affect parsing.z-ez--exportFz;Whether to write the dot file as an executable bash script.)version)ctxfilequoteexportr   c                 C   s   |||d| _ dS )zAThis script is used to set, get or unset values from a .env file.)QUOTEEXPORTFILEN)obj)r!   r"   r#   r$   r   r   r   cli$   s    r)   )r   r   c              
   c   sx   z2t | }|V  W d   n1 s&0    Y  W n@ tyr } z(td| tjd td W Y d}~n
d}~0 0 dS )z~
    Open a file and yield the corresponding (decoded) stream.

    Exits with error code 2 if the file cannot be opened.
    NzError opening env file: )r"      )openOSErrorprintsysstderrexit)r   streamexcr   r   r   stream_file5   s    
(r3   z--formatsimple)r4   jsonshellr$   zlThe format in which to display the list. Default format is simple, which displays name=value without quotes.)r!   formatr   c                 C   s   | j d }t|}t|d}W d   n1 s20    Y  |dkr\ttj|ddd nX|dkrhd	nd
}t|D ]>}|| }|durt|dv rt	|}t| | d|  qtdS )z!Display all the stored key/value.r'   r1   Nr5   r*   T)indent	sort_keysr$   zexport  )r$   r6   =)
r(   r3   r   clickechor5   dumpssortedshlexr#   )r!   r7   r"   r1   valuesprefixkvr   r   r   listE   s    

(
rF   key)requiredvalue)r!   rG   rI   r   c                 C   sZ   | j d }| j d }| j d }t|||||\}}}|rNt| d|  ntd dS )zStore the given key/value.r'   r%   r&   r<   r   N)r(   r   r=   r>   r0   )r!   rG   rI   r"   r#   r$   successr   r   r   set^   s    


rK   )r!   rG   r   c                 C   sb   | j d }t|}t|d}W d   n1 s20    Y  ||}|rVt| ntd dS )z%Retrieve the value for the given key.r'   r8   Nr   )r(   r3   r   getr=   r>   r0   )r!   rG   r"   r1   rB   Zstored_valuer   r   r   rL   n   s    

(
rL   c                 C   sF   | j d }| j d }t|||\}}|r:td|  ntd dS )zRemoves the given key.r'   r%   zSuccessfully removed r   N)r(   r   r=   r>   r0   )r!   rG   r"   r#   rJ   r   r   r   unset   s    

rM   Zignore_unknown_options)Zcontext_settingsz--override/--no-overridezKOverride variables from the environment file with those from the .env file.)r   r   commandline)nargsr   )r!   overriderN   r   c                    sj   | j d }tj|s,tjd| d| d fddt| D }|s\td t	d t
|| d	S )
z/Run command with environment variables present.r'   zInvalid value for '-f' "z" does not exist.)r!   c                    s,   i | ]$\}}|d ur s"|t jvr||qS )N)r   environ).0rD   rE   rQ   r   r   
<dictcomp>   s   zrun.<locals>.<dictcomp>zNo command given.r   N)r(   r   r   isfiler=   ZBadParameterr   itemsr>   r0   run_command)r!   rQ   rN   r"   Zdotenv_as_dictr   rT   r   run   s    





rY   )commandenvr   c                 C   s`   t j }|| tjdkrHt| ddd|d}| \}}t|j	 nt j
| d | |d dS )a  Replace the current process with the specified command.

    Replaces the current process with the specified command and the variables from `env`
    added in the current environment variables.

    Parameters
    ----------
    command: List[str]
        The command and it's parameters
    env: Dict
        The additional environment variables

    Returns
    -------
    None
        This function does not return any value. It replaces the current process with the new one.

    r	   Tr   F)universal_newlinesbufsizer6   r[   )argsr[   N)r   rR   copyupdater.   platformr
   communicater0   
returncodeexecvpe)rZ   r[   Zcmd_envp_r   r   r   rX      s    


rX   )2r5   r   rA   r.   
contextlibr   typingr   r   r   r   r   r   ra   
subprocessr
   r=   ImportErrorr/   writer0   mainr   r   r   r    r   strr   groupoptionPathZChoiceZBOOLZversion_optionZpass_contextContextr)   PathLiker3   rZ   boolrF   argumentrK   rL   rM   ZUNPROCESSEDrY   rX   r   r   r   r   <module>   s~    




$"