
    i                     l    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dS )zCSome general file utilities used that can be used by the Cloud SDK.    )absolute_import)division)unicode_literalsN)encoding)	platformsc                  @    t          j        t          j        d          S )z5Returns properly encoded system PATH variable string.PATH)encoding_utilGetEncodedValueosenviron     Y/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fire/console/files.py_GetSystemPathr      s    		&rz6	:	::r   c                    t          |t                    r"t          d                    |                    |D ]}|                    t
          j                  D ]}|                    d          }t
          j        	                    t
          j        
                    ||           |z             }t
          j                            |          r%t          j        |t
          j                  r|c c S 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fulls         r   _FindExecutableOnPathr&   !   s       2
 !!'2 2 2
   cZZ
++  	//#&&iWbgll9jAACGHHd			 ")D"'":":  
r   c                 4    | t           j        j        k    rdS dS )N)z.exez.cmdz.batz.comz.ps1) z.sh)r   OperatingSystemWINDOWS)platforms    r   _PlatformExecutableExtensionsr,   B   s    *22233;r   Fc                    |sGt           j                            |           d         r"t          d                    |                     t           j                            |           r"t          d                    |                     |t                      }n|}||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.)r   r   splitextr   r   dirnamer   r,   r   r)   Currentr&   )r!   r   r"   allow_extensionseffective_patheffective_pathexts         r   FindExecutableOnPathr5   I   s    0 
 Pbg..z::1= P
 <<BF:<N<NP P P W__Z   J
 66<fZ6H6HJ J J 
\#%%NNN")"5ww9$4<<>>@ @  
z>0
2 
2 2r   )NNF)__doc__
__future__r   r   r   r   fire.consoler   r
   r   r   r&   r,   r5   r   r   r   <module>r9      s     J I & & & & & &       ' ' ' ' ' ' 				 2 2 2 2 2 2 " " " " " "; ; ;
  B   9=*/)2 )2 )2 )2 )2 )2r   