o
    ŠÄŽiØ  ã                   @   sr   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 dd	„ Z
d
d„ Zdd„ Z		ddd„ZdS )zCSome general file utilities used that can be used by the Cloud SDK.é    )Úabsolute_import)Údivision)Úunicode_literalsN)Úencoding)Ú	platformsc                   C   s   t  tjd¡S )z5Returns properly encoded system PATH variable string.ÚPATH)Úencoding_utilÚGetEncodedValueÚosÚenviron© r   r   úN/home/jeff/fluffinator/venv/lib/python3.10/site-packages/fire/console/files.pyÚ_GetSystemPath   s   r   c                 C   s‚   t |tƒrtd |¡ƒ‚|D ]0}| tj¡D ]'}| d¡}tj 	tj 
|| ¡| ¡}tj |¡r=t |tj¡r=|    S qqdS )a}  Internal function to a find an executable.

  Args:
    executable: The name of the executable to find.
    path: A list of directories to search separated by 'os.pathsep'.
    pathext: An iterable of file name extensions to use.

  Returns:
    str, the path to a file on `path` with name `executable` + `p` for
      `p` in `pathext`.

  Raises:
    ValueError: invalid input.
  zr_FindExecutableOnPath(..., pathext='{0}') failed because pathext must be an iterable of strings, but got a string.ú"N)Ú
isinstanceÚstrÚ
ValueErrorÚformatÚsplitr
   ÚpathsepÚstripÚpathÚnormpathÚjoinÚisfileÚaccessÚX_OK)Ú
executabler   ÚpathextÚextÚ	directoryÚfullr   r   r   Ú_FindExecutableOnPath!   s   
þ
€úr"   c                 C   s   | t jjkrdS dS )N)z.exez.cmdz.batz.comz.ps1)Ú z.sh)r   ÚOperatingSystemÚWINDOWS)Úplatformr   r   r   Ú_PlatformExecutableExtensionsB   s   r'   Fc                 C   sv   |st j | ¡d rtd | ¡ƒ‚t j | ¡rtd | ¡ƒ‚|du r&tƒ }n|}|dur.|nttj	 
¡ ƒ}t| ||ƒS )a$  Searches for `executable` in the directories listed in `path` or $PATH.

  Executable must not contain a directory or an extension.

  Args:
    executable: The name of the executable to find.
    path: A list of directories to search separated by 'os.pathsep'.  If None
      then the system PATH is used.
    pathext: An iterable of file name extensions to use.  If None then
      platform specific extensions are used.
    allow_extensions: A boolean flag indicating whether extensions in the
      executable are allowed.

  Returns:
    The path of 'executable' (possibly with a platform-specific extension) if
    found and executable, None if not found.

  Raises:
    ValueError: if executable has a path or an extension, and extensions are
      not allowed, or if there's an internal error.
  é   zWFindExecutableOnPath({0},...) failed because first argument must not have an extension.zQFindExecutableOnPath({0},...) failed because first argument must not have a path.N)r
   r   Úsplitextr   r   Údirnamer   r'   r   r$   ÚCurrentr"   )r   r   r   Úallow_extensionsÚeffective_pathÚeffective_pathextr   r   r   ÚFindExecutableOnPathI   s&   ÿÿÿÿÿr/   )NNF)Ú__doc__Ú
__future__r   r   r   r
   Úfire.consoler   r   r   r   r"   r'   r/   r   r   r   r   Ú<module>   s   !ÿ