B
    `4                 @   sJ  d Z ddlmZmZmZ eZddlZddlZddl	m
Z ddlmZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZ yejd
ddZW n ek
r   dZY nX G dd dZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd de!Z"G dd de!Z#G dd de!Z$G dd deZ%dS ) zConfiguration classes.    )absolute_importdivisionprint_functionN   )types)find_pythongenerate_pip_commandApplicationError)docker_qualify_imageget_docker_completionget_remote_completionCommonConfig)Metadata)data_contextTIntegrationConfigIntegrationConfig)boundc               @   s$   e Zd ZdZdd Zedd ZdS )ParsedRemotez&A parsed version of a "remote" string.c             C   s   || _ || _|| _d S )N)archplatformversion)selfr   r   r    r   L/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/config.py__init__'   s    zParsedRemote.__init__c             C   sL   |  d}t|dkr$d}|\}}nt|dkr<|\}}}ndS t|||S )zLReturn a ParsedRemote from the given value or None if the syntax is invalid./   N   )splitlenr   )valuepartsr   r   r   r   r   r   parse,   s    

zParsedRemote.parseN)__name__
__module____qualname____doc__r   staticmethodr"   r   r   r   r   r   %   s   r   c                   s@   e Zd ZdZ fddZedd Zedd Zdd	 Z  Z	S )
EnvironmentConfigzEConfiguration common to all commands which execute in an environment.c                s  t t| || |jdk| _|j| _|j| _d|kr<|jnd| _t|j| _|j| _	|j
| _
| j
rt| j
| _| jr| jjr| jjstd| j
 nd| _d|kr|jnd| _d|kr|jnd| _d|kr|jnd| _d	|kr|jnd| _d
|kr|jnd| _d|kr|jnd| _d|kr(|jnd| _| jdkrTt | j	i dd| _|j| _|j| _|j| _|j| _|j| _| jdkrd| _|j| _| jdkrd| _d dd t!j"dd D }| jp|| _#|j$| _$|j%| _%| jp| j
p| j| _&g | _'| j&rd| _d|kr |j(nd| _(td|kr8|j)nd| _)| * dddkr\d| _)| * dddkrxd| _%|j+r|j+|krtd||j+f | jrdd }t, -| dS )z<
        :type args: any
        :type command: str
        TpythonNzSUnrecognized remote "%s" syntax. Use "platform/version" or "arch/platform/version".docker_privilegedFdocker_pulldocker_keep_gitdocker_seccompdocker_memorydocker_terminatedocker_networkZseccompdefault.c             s   s   | ]}t |V  qd S )N)str).0ir   r   r   	<genexpr>p   s    z-EnvironmentConfig.__init__.<locals>.<genexpr>r   inject_httptester
httptester enableddisabledz	pip-checkz9Running under Python %s instead of Python %s as expected.c                sT   xNt t jt jjdD ]0\ }} fdd|D }| dd |D  qW dS )zHAdd files from the content root .git directory to the payload file list.z.gitc                s   g | ]}t j |qS r   )ospathjoin)r4   filename)dirpathr   r   
<listcomp>   s    zDEnvironmentConfig.__init__.<locals>.git_callback.<locals>.<listcomp>c             s   s&   | ]}|t j|t jjfV  qd S )N)r<   r=   relpathr   contentroot)r4   r=   r   r   r   r6      s    zCEnvironmentConfig.__init__.<locals>.git_callback.<locals>.<genexpr>N)r<   walkr=   r>   r   rC   rD   extend)filesZ	_dirnames	filenamespathsr   )r@   r   git_callback   s    &z0EnvironmentConfig.__init__.<locals>.git_callback).superr(   r   localZvenvZvenv_system_site_packagesr)   r
   docker
docker_rawremoter   r"   Zparsed_remoter   r   r	   r*   r+   r,   r-   r.   r/   r0   r   getZremote_stageZremote_providerZremote_endpointZremote_aws_regionZremote_terminaterequirementsr>   sysversion_infopython_versionZpython_interpreterZ	pip_checkZdelegateZdelegate_argsr7   r8   get_delegated_completionZcheck_pythonr   register_payload_callback)r   argscommandZactual_major_minorrJ   )	__class__r   r   r   >   sf    zEnvironmentConfig.__init__c             C   s
   t | jS )z
        :rtype: str
        )r   rT   )r   r   r   r   python_executable   s    z#EnvironmentConfig.python_executablec             C   s
   t | jS )z#
        :rtype: list[str]
        )r   rZ   )r   r   r   r   pip_command   s    zEnvironmentConfig.pip_commandc             C   s0   | j rt | ji S | jr,t | ji S i S )zReturns a dictionary of settings specific to the selected delegation system, if any. Otherwise returns an empty dictionary.
        :rtype: dict[str, str]
        )rM   r   rP   rN   rO   r   )r   r   r   r   rU      s
    z*EnvironmentConfig.get_delegated_completion)
r#   r$   r%   r&   r   propertyrZ   r[   rU   __classcell__r   r   )rY   r   r(   <   s
   Tr(   c                   s    e Zd ZdZ fddZ  ZS )
TestConfigz*Configuration common to all test commands.c                s"  t t || |j _|j _|j _d _|jp8g  _|jpDg  _|j	pPg  _	|j
 _
|j _|j _|j _|j _|j _|j _|j _|j _d|kr|jnd _d|kr|jnd _d|kr|jnd _|jrt|jnt  _d _ jrd _ fdd}t | dS )	z<
        :type args: any
        :type command: str
        NlintFjunit
failure_okTc                s(    } j r$| tj|j |j f dS )z/Add the metadata file to the payload file list.N)metadata_pathappendr<   r=   abspath)rG   config)r   r   r   metadata_callback   s    z.TestConfig.__init__.<locals>.metadata_callback)rK   r^   r   ZcoverageZcoverage_labelZcoverage_checkZcoverage_config_base_pathincludeexcluderequirechangedZtrackedZ	untrackedZ	committedZstagedZunstagedZchanged_fromZchanged_pathZbase_branchr_   r`   ra   metadatar   	from_filerb   r   rV   )r   rW   rX   rf   )rY   )r   r   r      s4    zTestConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   r^      s   r^   c                   s    e Zd ZdZ fddZ  ZS )ShellConfigz$Configuration for the shell command.c                s*   t t| |d |j| _| jr&d| _dS )z!
        :type args: any
        shellFN)rK   rm   r   rawr8   )r   rW   )rY   r   r   r      s    zShellConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   rm      s   rm   c                   s    e Zd ZdZ fddZ  ZS )SanityConfigz%Configuration for the sanity command.c                sF   t t| |d |j| _|j| _|j| _|j| _|j| _| j| _	dS )z!
        :type args: any
        ZsanityN)
rK   rp   r   testZ	skip_testZ
list_testsallow_disabledZenable_optional_errorsr_   info_stderr)r   rW   )rY   r   r   r      s    zSanityConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   rp      s   rp   c                   s,   e Zd ZdZ fddZ fddZ  ZS )r   z*Configuration for the integration command.c                s   t t| || |j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|  dddkrd| _| jrd| _d| _dS )z<
        :type args: any
        :type command: str
        ztemp-unicoder:   r;   TN)rK   r   r   Zstart_atZstart_at_taskallow_destructiveZ
allow_rootrr   Zallow_unstableZallow_unstable_changedZallow_unsupportedZretry_on_errorZcontinue_on_errorZdebug_strategyZchanged_all_targetZchanged_all_modeZlist_targetstagsZ	skip_tagsZdiffZno_temp_workdirZno_temp_unicoderU   rP   explainrs   )r   rW   rX   )rY   r   r   r      s2    zIntegrationConfig.__init__c                sL   t jt jjd| j }t jt jj|}t j|sHt	t
|  }|S )z;Return the path to the Ansible config for the given config.z%s.cfg)r<   r=   r>   r   rC   Zintegration_pathrX   rD   existsrK   r   get_ansible_config)r   Zansible_config_relative_pathZansible_config_path)rY   r   r   rx     s
    z$IntegrationConfig.get_ansible_config)r#   r$   r%   r&   r   rx   r]   r   r   )rY   r   r      s   "c                   s    e Zd ZdZ fddZ  ZS )PosixIntegrationConfigz0Configuration for the posix integration command.c                s   t t| |d dS )z!
        :type args: any
        ZintegrationN)rK   ry   r   )r   rW   )rY   r   r   r   -  s    zPosixIntegrationConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   ry   *  s   ry   c                   s    e Zd ZdZ fddZ  ZS )WindowsIntegrationConfigz2Configuration for the windows integration command.c                s2   t t| |d |j| _|j| _| jr.d| _dS )z!
        :type args: any
        zwindows-integrationTN)rK   rz   r   Zwindows	inventoryrt   )r   rW   )rY   r   r   r   7  s
    z!WindowsIntegrationConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   rz   4  s   rz   c                   s    e Zd ZdZ fddZ  ZS )NetworkIntegrationConfigz2Configuration for the network integration command.c                sN   t t| |d |j| _t|jp$g | _t|jp4g | _|j| _|j| _dS )z!
        :type args: any
        znetwork-integrationN)	rK   r|   r   r   dictZplatform_collectionZplatform_connectionr{   Ztestcase)r   rW   )rY   r   r   r   G  s    z!NetworkIntegrationConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   r|   D  s   r|   c                   s    e Zd ZdZ fddZ  ZS )UnitsConfigz$Configuration for the units command.c                s\   t t| |d |j| _|j| _d|kr0|jnd| _| jdkrHd| _n| jdkrXd| _dS )	z!
        :type args: any
        Zunitsrequirements_moder9   onlyTskipFN)rK   r~   r   Zcollect_onlyZnum_workersr   rQ   )r   rW   )rY   r   r   r   V  s    

zUnitsConfig.__init__)r#   r$   r%   r&   r   r]   r   r   )rY   r   r~   T  s   r~   )&r&   
__future__r   r   r   type__metaclass__r<   rR   r9   r   tutilr   r   r	   Zutil_commonr
   r   r   r   rk   r   datar   TypeVarr   AttributeErrorr   r(   r^   rm   rp   r   ry   rz   r|   r~   r   r   r   r   <module>   s.   
q/0
