U
    ÓZjÇ  ã                   @   sN   d Z ddlZddlmZ ddlmZ ddlmZ e e	¡Z
dd„ Zdd	„ ZdS )
zPlugin utilities.é    N)Úutil)Úos)ÚSTANDARD_BINARY_DIRSc                 C   sB   t j | ¡}g }|r>| |¡ t j |¡\}}||d krq>q|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   ÚpathÚnormpathÚappendÚsplit)r   ÚprefixÚprefixesÚ_© r   úW/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot/plugins/util.pyÚget_prefixes   s    

r   c                 C   s’   t jd }g }tD ]$}||kr|t j| 7 }| |¡ qt|ƒr`t d| t j |¡¡ |t jd< t	 
| ¡rndS t|ƒrzdnd}t d| ||¡ dS )zöAttempt 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   Z
exe_exists)Úcmdr   ÚaddedÚdÚexpandedr   r   r   Úpath_surgery    s(    	
 
ÿ

 ÿr   )Ú__doc__ÚloggingZcertbotr   Zcertbot.compatr   Zcertbot.compat.miscr   Ú	getLoggerÚ__name__r   r   r   r   r   r   r   Ú<module>   s   
