3 Ú¯aã@sndZddlZddlmZddlmZddlmZddlm Z ej e ƒZ e ee dœdd „Ze ed œd d „ZdS) zPlugin utilities.éN)ÚList)Úutil)Úos)ÚSTANDARD_BINARY_DIRS)ÚpathÚreturncCsFtjj|ƒ}g}x0|r@|j|ƒtjj|ƒ\}}||dkrPqW|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` ééÿÿÿÿ)rrÚnormpathÚappendÚsplit)rÚprefixÚprefixesÚ_©rú/usr/lib/python3.6/util.pyÚ get_prefixes s   r)ÚcmdrcCs–tjd}g}x,tD]$}||kr|tj|7}|j|ƒqWt|ƒrdtjd|tjj|ƒƒ|tjd<t j |ƒrrdSt|ƒr~dnd}tjd|||ƒdS)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ÚjoinrZ exe_exists)rrZaddedÚdZexpandedrrrÚ path_surgery#s    r)Ú__doc__ZloggingZtypingrZcertbotrZcertbot.compatrZcertbot.compat.miscrZ getLoggerÚ__name__rÚstrrÚboolrrrrrÚs