o
    QeUs                     @   sB   d Z ddlZddlZddlZddlZdd Zd	ddZdd ZdS )
zOMiscellaneous functions.

run_command borrowed from Cheesecake - See CREDITS.

    Nc                   C   s   t jdt jd S )z/Return location we store config files and data.z%s/.yolk~)ospathabspath
expanduser r   r   B/home/ubuntu/flask/venv/lib/python3.10/site-packages/yolk/utils.pyget_yolk_dir   s   r	   c              
   C   s   zt j| t jt j|d}W n ty# } z
d|fW  Y d}~S d}~ww |rQt }| du rQtd t | |krKt	|j
tj |  dS | du s0|  |j| d  fS )zRun command and return its return status code and its output.

    >>> run_command(['true'])
    (0, '')

    >>> run_command(['false'])
    (1, '')

    >>> run_command(['echo', 'hello world'])
    (0, 'hello world\n')

    )stdoutstderrenv   Ng?)r   zTime exceededr   )
subprocessPopenPIPESTDOUT	Exceptiontimepollsleepr   killpidsignalSIGINTwait
returncodecommunicatedecode)argsr   max_timeoutpipeerrmsgstartr   r   r   run_command   s*   

r#   c                 C   s   t | \}}|dkS )z8Return True if command exited normally, False otherwise.r   )r#   )r   return_code_r   r   r   command_successful5   s   r&   )NN)__doc__r   r   r   r   r	   r#   r&   r   r   r   r   <module>   s    
#