B
    b                 @   sJ   d Z ddlZddlZddlmZmZ ddlZdgZG dd dZ	e	 Z
dS )a:  Variable type for path Variables.

To be used whenever a user-specified path override setting should be allowed.

Arguments to PathVariable are:
  * *key* - name of this option on the command line (e.g. "prefix")
  * *help* - help string for option
  * *default* - default value for this option
  * *validator* - [optional] validator for option value.  Predefined are:

    * *PathAccept* - accepts any path setting; no validation
    * *PathIsDir* - path must be an existing directory
    * *PathIsDirCreate* - path must be a dir; will create
    * *PathIsFile* - path must be a file
    * *PathExists* - path must exist (any type) [default]

  The *validator* is a function that is called and which should return
  True or False to indicate if the path is valid.  The arguments
  to the validator function are: (*key*, *val*, *env*).  *key* is the
  name of the option, *val* is the path specified for the option,
  and *env* is the environment to which the Options have been added.

Usage example::

    opts = Variables()
    opts.Add(
        PathVariable(
            'qtdir',
            help='where the root of Qt is installed',
            default=qtdir,
            validator=PathIsDir,
        )
    )
    opts.Add(
        PathVariable(
            'qt_includes',
            help='where the Qt includes are installed',
            default='$qtdir/includes',
            validator=PathIsDirCreate,
        )
    )
    opts.Add(
        PathVariable(
            'qt_libraries',
            help='where the Qt library is installed',
            default='$qtdir/lib',
        )
    )
    N)TupleCallablePathVariablec               @   s   e Zd ZeddddZeddddZeddddZeddd	d
ZeddddZde	e
e
e
edf dddZdS )_PathVariableClassN)returnc             C   s   dS )z#Accepts any path, no checking done.N )keyvalenvr   r   ;lib/python3.7/site-packages/SCons/Variables/PathVariable.py
PathAcceptU   s    z_PathVariableClass.PathAcceptc             C   s:   t j|s6t j|rd}nd}tj|| |f dS )z*Validator to check if Path is a directory.z*Directory path for option %s is a file: %sz/Directory path for option %s does not exist: %sN)ospathisdirisfileSConsErrors	UserError)r   r	   r
   mr   r   r   	PathIsDirZ   s
    z_PathVariableClass.PathIsDirc             C   sn   yt j|dd W nV tk
r>   d}tj|| |f Y n, tk
rh   d}tj|| |f Y nX dS )zWValidator to check if Path is a directory,
           creating it if it does not exist.T)exist_okz1Path for option %s is a file, not a directory: %sz+Path for option %s could not be created: %sN)r   makedirsFileExistsErrorr   r   r   PermissionError)r   r	   r
   r   r   r   r   PathIsDirCreated   s    z"_PathVariableClass.PathIsDirCreatec             C   s:   t j|s6t j|rd}nd}tj|| |f dS )z$Validator to check if Path is a filez*File path for option %s is a directory: %sz*File path for option %s does not exist: %sN)r   r   r   r   r   r   r   )r   r	   r
   r   r   r   r   
PathIsFileq   s
    z_PathVariableClass.PathIsFilec             C   s(   t j|s$d}tj|| |f dS )z!Validator to check if Path existsz%Path for option %s does not exist: %sN)r   r   existsr   r   r   )r   r	   r
   r   r   r   r   
PathExists{   s    z_PathVariableClass.PathExistsc             C   sR   |dkr| j }tj|s&tj|r8d||d f }nd||f }||||dfS )a  Return a tuple describing a path list SCons Variable.

        The input parameters describe a 'path list' option. Returns
        a tuple with the correct converter and validator appended. The
        result is usable for input to :meth:`Add`.

        The *default* option specifies the default path to use if the
        user does not specify an override with this option.

        *validator* is a validator, see this file for examples
        Nz%s ( /path/to/%s )r   )r   r   ZUtilZis_ListZis_Tuple)selfr   helpdefaultZ	validatorZhelpmsgr   r   r   __call__   s    z_PathVariableClass.__call__)N)__name__
__module____qualname__staticmethodr   r   r   r   r   r   strr   r!   r   r   r   r   r   S   s   		r   )__doc__r   os.pathtypingr   r   ZSCons.Errorsr   __all__r   r   r   r   r   r   <module>H   s   E