a
   WzÃMÞLöìã                   @   sº   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZddl	m
Z
 ddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    Né   ©ÚIS_WINDOWS_PLATFORMc                 C   sL   t | ƒ ¡  ¡ }|dks |dkr$dS |dks4|dkr8dS |dkrD|S dS dS )	zï
    Prompt the user for a yes or no.

    Can optionally specify a default value, which will only be
    used if they enter a blank line.

    Unrecognised input (anything other than "y", "n", "yes",
    "no" or "") will return None.
    ÚyZyesTÚnÚnoFÚ N)ÚinputÚstripÚlower)ÚpromptÚdefaultZanswer© r   ú5/usr/lib/python3.9/site-packages/compose/cli/utils.pyÚyesno   s    
r   c                 C   s&   t j | ¡ t j ¡  t j ¡  d¡S )z¢
    Version of input (raw_input in Python 2) which forces a flush of sys.stdout
    to avoid problems where the prompt fails to appear due to line buffering
    Ú
)ÚsysÚstdoutÚwriteÚflushÚstdinÚreadlineÚrstrip)r   r   r   r   r	   %   s    
r	   c               	   O   sx   t tjdƒX}z&tj| ||dœ|¤ŽW W  d  ƒ S  tyT   Y W d  ƒ dS 0 W d  ƒ n1 sj0    Y  dS )zO
    Like subprocess.call(), but redirects stdout and stderr to /dev/null.
    Úw)r   ÚstderrNé   )ÚopenÚosÚdevnullÚ
subprocessÚcallÚOSError)ÚargsÚkwargsZshutupr   r   r   Úcall_silently/   s
    &r$   c                   C   s   t  ¡ dkS )NZDarwin)ÚplatformÚsystemr   r   r   r   Úis_mac<   s    r'   c                   C   s   t  ¡ dkot ¡ d dkS )NZLinuxr   ZUbuntu)r%   r&   ÚdistroZlinux_distributionr   r   r   r   Ú	is_ubuntu@   s    r)   c                   C   s   t S )Nr   r   r   r   r   Ú
is_windowsD   s    r*   c                 C   sT   d  tjtƒ ¡}| dkr|S | dkrBd  |tjt ¡ t ¡ t	j
¡S td  | ¡ƒ‚d S )Nz#docker-compose version {}, build {}ÚcomposeZfullz;{}
docker-py version: {}
{} version: {}
OpenSSL version: {}z{} is not a valid version scope)Úformatr+   Ú__version__Úget_build_versionÚdockerÚversionr%   Zpython_implementationZpython_versionÚsslZOPENSSL_VERSIONÚ
ValueError)ZscopeZversioninfor   r   r   Úget_version_infoH   s     þÿör3   c                  C   s`   t j t j tj¡d¡} t j | ¡s(dS t| ƒ}| ¡  	¡ W  d   ƒ S 1 sR0    Y  d S )NZGITSHAÚunknown)
r   ÚpathÚjoinÚdirnamer+   Ú__file__Úexistsr   Úreadr
   )ÚfilenameZfhr   r   r   r.   _   s
    
r.   c                   C   s   t ƒ otj d¡S )Nz/Applications/Docker.app)r'   r   r5   Úisdirr   r   r   r   Úis_docker_for_mac_installedh   s    r=   c                  C   s\   d  tj¡d  tj¡g} zt ¡ }t ¡ }W n ty>   Y n0 |  d  ||¡¡ d 	| ¡S )Nzdocker-compose/{}zdocker-py/{}z{}/{}ú )
r,   r+   r-   r/   r%   r&   Úreleaser!   Úappendr6   )ÚpartsZp_systemZ	p_releaser   r   r   Úgenerate_user_agentl   s    

þrB   c                 C   sV   g d¢}| rt t | d¡ƒnd}|t|ƒkr8t|ƒd }d | td|d ƒ || ¡S )N)ÚBZkBZMBZGBZTBZPBZEBiè  r   r   z	{:.4g} {}é
   é   )ÚintÚmathÚlogÚlenr,   Úpow)ÚsizeÚsuffixesÚorderr   r   r   Úhuman_readable_file_size{   s    þrN   c                 C   s>   t | tƒs| S tr2z|  d¡W S  ty0   Y n0 |  dd¡S )Nzwindows-1250zutf-8Úreplace)Ú
isinstanceÚbytesr   ÚdecodeÚUnicodeDecodeError)Úsr   r   r   Úbinarystr_to_unicode‡   s    
rU   )N)rG   r   r%   r1   r   r   r(   r/   r+   Úconstr   r   r	   r$   r'   r)   r*   r3   r.   r=   rB   rN   rU   r   r   r   r   Ú<module>   s*   

	