HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/compose/cli/__pycache__/log_printer.cpython-310.pyc
o

S�`��@sddlZddlZddlmZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
ddlmZd	d
lmZddlmZddlmZGd
d�d�Zd-dd�Zd.dd�ZGdd�d�Zdd�Zdd�Zdd�ZGdd�dedd ��Zd!d"�Zd#d$�Zd%d&�Z d'd(�Z!d)d*�Z"d+d,�Z#dS)/�N)�
namedtuple)�cycle)�
attrgetter)�Empty)�Queue)�Thread)�APIError�)�colors)�ShutdownException)�split_bufferc@seZdZddd�Zdd�ZdS)�LogPresenterTcCs||_||_||_dS�N)�prefix_width�
color_func�keep_prefix)�selfrrr�r�9/usr/lib/python3/dist-packages/compose/cli/log_printer.py�__init__s
zLogPresenter.__init__cCs>dj|d�}|jr|j�|j�}dj|�|d�d�|}|S)Nz{line}��linez	{prefix} z |)�prefix)�formatr�name_without_project�ljustrr)r�	containerr�to_logrrrr�presents
zLogPresenter.presentN�T)�__name__�
__module__�__qualname__rrrrrrr
s
r
Tccs@�t|�}dd�}t|r|gnt���D]	}t|||�VqdS)znReturn an iterable of functions.

    Each function can be used to format the logs output of a container.
    cSs|Srr)�textrrr�no_color)sz&build_log_presenters.<locals>.no_colorN)�max_name_widthrr
�rainbowr
)�
service_names�
monochromerrr$rrrr�build_log_presenters"s��r)�cCstdd�|D��|S)z�Calculate the maximum width of container names so we can make the log
    prefixes line up like so:

    db_1  | Listening
    web_1 | Listening
    css�|]}t|�VqdSr)�len)�.0�namerrr�	<genexpr>7s�z!max_name_width.<locals>.<genexpr>)�max)r'�max_index_widthrrrr%0sr%c@s2eZdZdZejddfdd�Zdd�Zdd	�ZdS)
�
LogPrinterz:Print logs from many containers to a single output stream.FNcCs,||_||_||_||_||_|pi|_dSr)�
containers�
presenters�event_stream�output�cascade_stop�log_args)rr2r3r4r5r6r7rrrr=szLogPrinter.__init__cs�|jsdSt�}||jf}t|j|j|�}t||j|j|f�t||j�D](�t	|�|jr@�fdd�|jD�}�|vr@�S�sH|sGdSq%|�
��q%dS)Ncsg|]
}|j�kr|j�qSr)r-)r,�contrrr�
<listcomp>\sz"LogPrinter.run.<locals>.<listcomp>)r2rr7�build_thread_mapr3�start_producer_threadr4�
consume_queuer6�remove_stopped_threads�write)r�queue�thread_args�
thread_map�matching_containerrrr�runKs.
��zLogPrinter.runc	CsJz|j�|�Wnty|j�|�dd����Ynw|j��dS)N�ascii�replace)r5r>�UnicodeEncodeError�encode�decode�flush)rrrrrr>ls�zLogPrinter.write)	r r!r"�__doc__�sys�stdoutrrCr>rrrrr1:s
�!r1cCs.t|���D]\}}|��s|�|d�qdSr)�list�items�is_alive�pop)rA�container_id�
tailer_threadrrrr=xs
��r=cCs&tt||||fd�}d|_|��|S�N)�target�argsT)r�tail_container_logs�daemon�start)r�	presenterr?r7�tailerrrr�build_thread~s
�r[cs ��fdd�t|td�d�D�S)Ncs&i|]}|jt|t��g��R��qSr)�idr[�next)r,r�r3r@rr�
<dictcomp>�s��z$build_thread_map.<locals>.<dictcomp>r-)�key)�sortedr)�initial_containersr3r@rr^rr:�s�r:c@s2eZdZedd��Zedd��Zeddd��ZdS)	�	QueueItemcCs||dd�Srr��cls�itemrrr�new��z
QueueItem.newcCs|dd|�Srr)re�excrrr�	exception�rhzQueueItem.exceptionNcCs||dd�S)NTrrdrrr�stop�rhzQueueItem.stopr)r r!r"�classmethodrgrjrkrrrrrc�s

rc�
_QueueItemzitem is_stop excc
Cs�zt||�D]}|�t�|�||���qWnty1}z|�t�|��WYd}~dSd}~ww|�d�rD|�t�|�t	|����|�t�
|j��dS)N�follow)�build_log_generator�putrcrgr�	Exceptionrj�getr�wait_on_exitrkr-)rrYr?r7rf�errrrV�s���
rVcCs8|jdur|jddddd�|��}t|�S|j}t|�S)NT)rL�stderr�streamr)�
log_stream�logsr)rr7rvrrrro�s

�roc
CsZz|��}d�|j|�WSty,}zd�|j|jj|jjp d�WYd}~Sd}~ww)Nz{} exited with code {}
z=Unexpected API error for {} (HTTP code {})
Response body:
{}
z[empty])�waitrr-r�response�status_coder#)r�	exit_codertrrrrs�s

���rscCstt|d�}d|_|��dSrS)r�watch_eventsrWrX)r@�producerrrrr;�sr;c	Cst�}|D]x}|ddkr|�|dd�|ddkr*|�|dd�|�|d�|ddkr1q|d|vrH||d��r@q|�|dd�|d|vrl|d}|jsez|��Wn	tydYnw|�|d�t|dt	|�g|�R�||d<qdS)N�actionrkr\�dierXr)
�setrP�addrO�
is_restarting�attach_log_streamr�remover[r])rAr4r3r@�crashed_containers�eventrrrrr}�s:����r}ccsd�	z|jdd�}WntydVYqtjy t��w|jr'|j�|jr-|s-q|jVq)z?Consume the queue by reading lines off of it and yielding them.Tg�������?)�timeoutN)rrr�thread�errorrri�is_stoprf)r?r6rfrrrr<�s ��
�r<r)r*)$�_threadr�rK�collectionsr�	itertoolsr�operatorrr?rr�	threadingr�
docker.errorsr�r
�compose.cli.signalsr�
compose.utilsrr
r)r%r1r=r[r:rcrVrorsr;r}r<rrrr�<module>s4


>	
%