
    hh                     j    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 Z
d	 Zd
 Z	 	 ddZy)zCSome general file utilities used that can be used by the Cloud SDK.    )absolute_import)division)unicode_literalsN)encoding)	platformsc                  J    t        j                  t        j                  d      S )z5Returns properly encoded system PATH variable string.PATH)encoding_utilGetEncodedValueosenviron     P/var/www/html/dev/engine/venv/lib/python3.12/site-packages/fire/console/files.py_GetSystemPathr      s    		&	&rzz6	::r   c                    t        |t              rt        dj                  |            |D ]  }|j	                  t
        j                        D ]  }|j                  d      }t
        j                  j                  t
        j                  j                  ||       |z         }t
        j                  j                  |      stt        j                  |t
        j                        s|c c S   y)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fulls         r   _FindExecutableOnPathr&   !   s      
 !!'2 2
  cZZ

+ 	//#&iWWbggll9jACGHd		"))D"''": 
r   c                 @    | t         j                  j                  k(  ryy)N)z.exez.cmdz.batz.comz.ps1) z.sh)r   OperatingSystemWINDOWS)platforms    r   _PlatformExecutableExtensionsr,   B   s    **2223r   c                 ~   |s<t         j                  j                  |       d   rt        dj	                  |             t         j                  j                  |       rt        dj	                  |             |t               }n|}||n&t        t        j                  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.)r   r   splitextr   r   dirnamer   r,   r   r)   Currentr&   )r!   r   r"   allow_extensionseffective_patheffective_pathexts         r   FindExecutableOnPathr5   I   s    0 
bgg..z:1=
 <<BF:<NP P WW__Z 
 66<fZ6HJ J 
\#%NN")"5w9$44<<>@  
z>0
2 2r   )NNF)__doc__
__future__r   r   r   r   fire.consoler   r
   r   r   r&   r,   r5   r   r   r   <module>r9      s:     J &  ' 	 2 ";
B 9=*/)2r   