
    M/e                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  ej                  e      Zdedee   fd	Zd
edefdZy)zPlugin utilities.    N)List)util)os)STANDARD_BINARY_DIRSpathreturnc                     t         j                  j                  |       }g }|rA|j                  |       t         j                  j	                  |      \  }}||d   k(  r	 |S |rA|S )a  Retrieves all possible path prefixes of a path, in descending order
    of length. For instance:

      * (Linux) `/a/b/c` returns `['/a/b/c', '/a/b', '/a', '/']`
      * (Windows) `C:\a\b\c` returns `['C:\a\b\c', 'C:\a\b', 'C:\a', 'C:']`

    :param str path: the path to break into prefixes

    :returns: all possible path prefixes of given path in descending order
    :rtype: `list` of `str`
    )r   r   normpathappendsplit)r   prefixprefixes_s       6/usr/lib/python3/dist-packages/certbot/plugins/util.pyget_prefixesr      sb     WWd#FH
GGMM&)	Xb\!O  O    cmdc                    t         j                  d   }g }t        D ].  }||vs|t         j                  |z   z  }|j	                  |       0 t        |      rGt        j                  d| t         j                  j                  |             |t         j                  d<   t        j                  |       ryt        |      rdnd}t        j                  d| ||       y)zAttempt to perform PATH surgery to find cmd

    Mitigates https://github.com/certbot/certbot/issues/1833

    :param str cmd: the command that is being searched for in the PATH

    :returns: True if the operation succeeded, False otherwise
    PATHz6Can't find %s, attempting PATH mitigation by adding %sTz	 expanded z*Failed to find executable %s in%s PATH: %sF)r   environr   pathsepr   anyloggerdebugjoinr   
exe_exists)r   r   addeddexpandeds        r   path_surgeryr"   #   s     ::fDE! D=BJJN"DLLO
 5zM"**//%0	2!

6s!%j{bH
LL=s4!r   )__doc__loggingtypingr   certbotr   certbot.compatr   certbot.compat.miscr   	getLogger__name__r   strr   boolr"    r   r   <module>r.      sS         4			8	$s tCy .c d r   