o
    S`^                     @   s$  d dl Z d dlZd dlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	l	mZ dd
l	mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ e eZh dZd)ddZdd Zdd Zd)ddZdd Zdd Z			d*dd Zd!d" Zd#d$ Z d%d& Z!d+d'd(Z"dS ),    N   )errors   )config)parallel)Environment)LABEL_CONFIG_FILES)LABEL_ENVIRONMENT_FILE)LABEL_WORKING_DIR)Project)
get_client)load_context)make_context)	UserError>   psrmtopexeckilllogsstoppausestarteventsrestartunpausec           	      C   s   |pi }t |}|d}t|p| |}|dd tv |_t| d }|dd }|r9t|}|s9td	||dd }|d urT|rItd|
d}t|||}t| t|||d|d	||||d
 |t||d
S )N
--env-fileCOMMANDz	--contextzContext '{}' not foundz--hostzL-H, --host and -c, --context are mutually exclusive. Only one should be set.=z--project-namez	--verbose--no-interpolate)project_nameverbosecontextenvironmentoverride_dirinterpolateenvironment_fileenabled_profiles)get_project_dirgetr   from_env_fileSILENT_COMMANDSsilentset_parallel_limitr   r   formatlstripr   get_projectget_config_path_from_optionsget_profiles_from_options)	project_diroptionsadditional_optionsr$   r&   r#   r"   context_namehost r8   5/usr/lib/python3/dist-packages/compose/cli/command.pyproject_from_options$   s@   


r:   c              
   C   sf   |  d}|r1zt|}W n ty   td|  dw |dkr)tdtj| d S d S )NCOMPOSE_PARALLEL_LIMITz7COMPOSE_PARALLEL_LIMIT must be an integer (found: "{}")r   z-COMPOSE_PARALLEL_LIMIT can not be less than 2)	r)   int
ValueErrorr   r   r.   r   GlobalLimitset_global_limit)r#   parallel_limitr8   r8   r9   r-   J   s   

r-   c                 C   sB   d }t | tj}|r|d dkrdS tj|d }| dp |S )Nr   -.z--project-directory)r1   osenvironpathdirnamer)   )r4   r$   filesr8   r8   r9   r(   Z   s   r(   c                 C   sT   |pi }t |}|d}t|p| |}t||}tt| ||||d S )Nr   r   )r(   r)   r   r*   r1   r   loadfind)base_dirr4   r5   r$   r&   r#   config_pathr8   r8   r9   get_config_from_optionsd   s   


rL   c                 C   sL   dd }|  d}|r||S | d}|r$| dtj}|||S d S )Nc                 S   s   dd | D S )Nc                 S   s$   g | ]}t |tr|d n|qS )zutf-8)
isinstancebytesdecode).0pr8   r8   r9   
<listcomp>r   s   $ zGget_config_path_from_options.<locals>.unicode_paths.<locals>.<listcomp>r8   )pathsr8   r8   r9   unicode_pathsq   s   z3get_config_path_from_options.<locals>.unicode_pathsz--fileCOMPOSE_FILECOMPOSE_PATH_SEPARATOR)r)   rC   pathsepsplit)r4   r#   rT   file_optionconfig_filesrW   r8   r8   r9   r1   p   s   

r1   c                 C   s.   |  d}|r	|S | d}|r|dS g S )Nz	--profileCOMPOSE_PROFILES,)r)   rX   )r4   r#   profile_optionprofilesr8   r8   r9   r2      s   


r2   FTc
              
   C   s   |st | }t| |||}
t|
j||}t|
|}|d}t||||d}t	
| t||||dt|
||	W  d    S 1 sIw   Y  d S )NCOMPOSE_API_VERSION)r!   versionr"   r#   DOCKER_DEFAULT_PLATFORM)r   r*   r   rI   get_project_nameworking_dirrH   r)   r   r   handle_connection_errorsr   from_configexecution_context_labels)r3   rK   r    r!   r"   r#   r$   r%   r&   r'   config_detailsconfig_dataapi_versionclientr8   r8   r9   r0      s*   

$r0   c                 C   s\   d ttj| jg}t| s|d tt	|  |d ur,|d t
tj| |S )Nz{}={})r.   r
   rC   rE   abspathrc   use_config_from_stdinappendr   config_files_labelr	   normpath)rg   r&   extra_labelsr8   r8   r9   rf      s   
rf   c                 C   s   | j D ]}|js dS qdS )NTF)rZ   filename)rg   cr8   r8   r9   rl      s
   
rl   c                 C   s   d dd | jD S )Nr\   c                 s   s    | ]
}t j|jV  qd S N)rC   rE   ro   rq   )rP   rr   r8   r8   r9   	<genexpr>   s    
z%config_files_label.<locals>.<genexpr>)joinrZ   )rg   r8   r8   r9   rn      s   
rn   c                 C   sT   dd }|st | }|p|d}|r||S tjtj| }|r(||S dS )Nc                 S   s   t dd|  S )Nz[^-_a-z0-9] )resublower)namer8   r8   r9   normalize_name   s   z(get_project_name.<locals>.normalize_nameCOMPOSE_PROJECT_NAMEdefault)r   r*   r)   rC   rE   basenamerk   )rc   r    r#   r{   projectr8   r8   r9   rb      s   
rb   rs   )	NNFNNNTNN)NN)#loggingrC   rw   rv   r   r   r   config.environmentr   constr   r	   r
   r   r   docker_clientr   r   r   r   	getLogger__name__logr+   r:   r-   r(   rL   r1   r2   r0   rf   rl   rn   rb   r8   r8   r8   r9   <module>   s>    

&


