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/__pycache__/container.cpython-310.pyc
o

S�`�$�@s�ddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddl
mZGdd
�d
�Zdd�ZdS)�)�reduce)�
ImageNotFound�)�LABEL_CONTAINER_NUMBER)�
LABEL_ONE_OFF)�
LABEL_PROJECT)�
LABEL_SERVICE)�
LABEL_SLUG)�
LABEL_VERSION)�truncate_id)�ComposeVersionc@s@eZdZdZdsdd�Zedd��Zedd��Zed	d
��Ze	dd��Z
e	d
d��Ze	dd��Ze	dd��Z
e	dd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��Ze	dd ��Ze	d!d"��Ze	d#d$��Ze	d%d&��Ze	d'd(��Ze	d)d*��Ze	d+d,��Ze	d-d.��Ze	d/d0��Ze	d1d2��Ze	d3d4��Ze	d5d6��Ze	d7d8��Z e	d9d:��Z!e	d;d<��Z"e	d=d>��Z#d?d@�Z$dAdB�Z%dtdDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRdS�Z-dTdU�Z.dVdW�Z/dXdY�Z0dZd[�Z1d\d]�Z2d^d_�Z3d`da�Z4dbdc�Z5ddde�Z6dfdg�Z7dhdi�Z8djdk�Z9dldm�Z:dndo�Z;dpdq�Z<drS)u�	Containerzf
    Represents a Docker container, constructed from the output of
    GET /containers/:id:/json.
    FcCs||_||_||_d|_dS�N)�client�
dictionary�has_been_inspected�
log_stream)�selfrrr�r�3/usr/lib/python3/dist-packages/compose/container.py�__init__s
zContainer.__init__cKs>t|�}|dur
dS|d|dd|d�}|||fi|��S)zW
        Construct a container object from the output of GET /containers/json.
        N�Id�Image�/)rr�Name)�get_container_name)�clsrr�kwargs�name�new_dictionaryrrr�from_pss�zContainer.from_pscCs|||�|�dd�S)NT)r)�inspect_container)rr�idrrr�from_id*szContainer.from_idcKs |jdi|��}|�||d�S)Nrr)�create_containerr#)rr�options�responserrr�create.szContainer.createcC�
|jdS)Nr�r�rrrrr"3�
zContainer.idcCr()Nrr)r*rrr�image7r+zContainer.imagecCs|j�|j�Sr)r�
inspect_imager,r*rrr�image_config;�zContainer.image_configcCs|jdd�S)N�)r"r*rrr�short_id?r/zContainer.short_idcCs|jddd�S)Nrrr)r*rrrrCszContainer.namecC�|j�t�Sr)�labels�getrr*rrr�projectG�zContainer.projectcCr2r)r3r4rr*rrr�serviceKr6zContainer.servicecCs@|j�d�|j|j��rd�|j|jdur|j�S|j�S|jS)N�{}_{})r�
startswith�formatr5r7�number�slugr*rrr�name_without_projectOs"zContainer.name_without_projectcCs4|jrdS|j�t�}|std�|jt���t|�S)Nz%Container {} does not have a {} label)�one_offr3r4r�
ValueErrorr:r1�int)rr;rrrr;Vs�zContainer.numbercCs|jsdSt|j�Sr)�	full_slugrr*rrrr<bs
zContainer.slugcCr2r)r3r4r	r*rrrrAhr6zContainer.full_slugcCs|j�t�dkS)N�True)r3r4rr*rrrr>lszContainer.one_offcCs|��|�d�p
iS)NzNetworkSettings.Ports)�inspect_if_not_inspectedr4r*rrr�portspszContainer.portscs*dd��d��fdd�t|j���D��S)Ncs|s�gS�fdd�|D�S)Ncs g|]}djdd�i|���qS)z{HostIp}:{HostPort}->{private}�privater)r:)�.0�pub�rErr�
<listcomp>zs��zGContainer.human_readable_ports.<locals>.format_port.<locals>.<listcomp>r)rE�publicrrHr�format_portws

�z3Container.human_readable_ports.<locals>.format_portz, c3s�|]
}d��|��VqdS)�,N)�join)rF�item�rKrr�	<genexpr>s
��
�z1Container.human_readable_ports.<locals>.<genexpr>)rM�sortedrD�itemsr*rrOr�human_readable_portsus�zContainer.human_readable_portscCs|�d�piS)Nz
Config.Labels�r4r*rrrr3�r/zContainer.labelscC�
|�d�S)NzConfig.StopSignalrTr*rrr�stop_signal�r+zContainer.stop_signalcCs|�d�pdS)NzHostConfig.LogConfigrTr*rrr�
log_config�r/zContainer.log_configcCs<|jrdS|jr
dS|jr|�d�rdS|jSd|�d�S)N�Paused�
RestartingzState.Ghost�GhostzExit %s�State.ExitCode)�	is_paused�
is_restarting�
is_runningr4�human_readable_health_statusr*rrr�human_readable_state�szContainer.human_readable_statecCs*|�d�pg}|�d�p
g}d�||�S)NzConfig.Entrypointz
Config.Cmd� )r4rM)r�
entrypoint�cmdrrr�human_readable_command�sz Container.human_readable_commandcs(dd��t�fdd�|�d�pgD��S)NcSsd|vr
|�dd�S|dfS)N�=r)�split)�varrrr�	parse_env�sz(Container.environment.<locals>.parse_envc3s�|]}�|�VqdSrr)rFrg�rhrrrP�s�z(Container.environment.<locals>.<genexpr>z
Config.Env)�dictr4r*rrir�environment�s zContainer.environmentcCrU)Nr[rTr*rrr�	exit_code�r+zContainer.exit_codecCrU)Nz
State.RunningrTr*rrrr^�r+zContainer.is_runningcCrU)NzState.RestartingrTr*rrrr]�r+zContainer.is_restartingcCrU)NzState.PausedrTr*rrrr\�r+zContainer.is_pausedcCrU)NzHostConfig.LogConfig.TyperTr*rrr�
log_driver�r+zContainer.log_drivercCs:d}|�d�}|dkr|d7}|S|dur|d|7}|S)z; Generate UP status string with up time and health
        �UpzState.Health.Status�startingz (health: starting)Nz (%s)rT)r�
status_string�container_statusrrrr_�s
�z&Container.human_readable_health_statuscCs|jdddd�|_dS)NT)�stdout�stderr�stream)�attachrr*rrr�attach_log_stream��zContainer.attach_log_streamcCs$|��dd�}t||�d�|j�S)z�Return a value from the container or None if the value is not set.

        :param key: a string using dotted notation for nested dictionary
                    lookups
        cSs|pi�|�SrrT)r�keyrrr�	get_value�sz Container.get.<locals>.get_value�.)rCrrfr)rrxryrrrr4�sz
Container.get�tcpcCs0|j�d�||��}|rdjdi|d��SdS)Nz{}/{}z{HostIp}:{HostPort}rr)rDr4r:)r�port�protocolrrr�get_local_port�szContainer.get_local_portcCs(|�d�D]}|d|kr|SqdS)N�Mounts�DestinationrT)r�
mount_dest�mountrrr�	get_mount�s
�zContainer.get_mountcK�|jj|jfi|��Sr)r�startr"�rr%rrrr��rwzContainer.startcKr�r)r�stopr"r�rrrr��rwzContainer.stopcKr�r)r�pauser"r�rrrr��rwzContainer.pausecKr�r)r�unpauser"r�rrrr��rwzContainer.unpausecKr�r)r�killr"r�rrrr��rwzContainer.killcKr�r)r�restartr"r�rrrr��rwzContainer.restartcKr�r)r�remove_containerr"r�rrr�remove�rwzContainer.removecKs|jj|j|fi|��Sr)r�exec_creater")r�commandr%rrr�create_exec��zContainer.create_execcKs|jj|fi|��Sr)r�
exec_start)r�exec_idr%rrr�
start_exec�szContainer.start_execcCs2|j�|j�s|j�|jd�|j|j��dSdS)zpRename the container to a hopefully unique temporary container name
        by prepending the short id.
        r8N)rr9r1r�renamer"r:r*rrr�rename_to_tmp_name�s
��zContainer.rename_to_tmp_namecCs|js	|��dSdSr)r�inspectr*rrrrCs�z"Container.inspect_if_not_inspectedcCs|j�|j��dd�S)N�
StatusCode�)r�waitr"r4r*rrrr�rwzContainer.waitcO�|jj|jg|�Ri|��Sr)r�logsr"�r�argsrrrrr��zContainer.logscCs|j�|j�|_d|_|jS)NT)rr!r"rrr*rrrr�szContainer.inspectcCs*z
|j�|j�WdStyYdSw)NFT)rr-r,rr*rrr�image_existss��zContainer.image_existscCs|��s||jd<dSdS)zu If this container's image has been removed, temporarily replace the old image ID
            with `img_id`.
        rN)r�r)r�img_idrrr�reset_images�zContainer.reset_imagecOr�r)rrur"r�rrrru%r�zContainer.attachcCs"t|j�t��td�ko|j|kS)Nz1.21.0)rr3r4r
r5)r�project_namerrr�has_legacy_proj_name(s�zContainer.has_legacy_proj_namecCsd�|j|jdd��S)Nz<Container: {} ({})>�)r:rr"r*rrr�__repr__.r�zContainer.__repr__cCs t|�t|�kr
dS|j|jkS)NF)�typer")r�otherrrr�__eq__1szContainer.__eq__cCs
|j��Sr)r"�__hash__r*rrrr�6s
zContainer.__hash__N)F)r{)=�__name__�
__module__�__qualname__�__doc__r�classmethodr r#r'�propertyr"r,r.r1rr5r7r=r;r<rAr>rDrSr3rVrWr`rdrkrlr^r]r\rmr_rvr4r~r�r�r�r�r�r�r�r�r�r�r�rCr�r�r�r�r�rur�r�r�r�rrrrr
s�
































	r
cCsJ|�d�s|�d�sdSd|vr|dSt|ddd�d�}|�d�dS)Nr�NamescSst|�d��S)Nr)�lenrf)�nrrr�<lambda>Asz$get_container_name.<locals>.<lambda>)rxr���)r4�minrf)�	container�
shortest_namerrrr:srN)�	functoolsr�
docker.errorsr�constrrrrr	r
�utilsr�versionrr
rrrrr�<module>s-