o 6a@sNdZddlZddlmZddlmZddlmZee Z ddZ dd Z dS) zPlugin utilities.N)util)os)STANDARD_BINARY_DIRScCsHtj|}g}|r"||tj|\}}||dkr |S|s |S)aRetrieves 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` )rpathnormpathappendsplit)rprefixprefixes_r 6/usr/lib/python3/dist-packages/certbot/plugins/util.py get_prefixes s   rcCstjd}g}tD]}||vr|tj|7}||q t|r0td|tj||tjd<t |r7dSt|r=dnd}td|||dS)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 expandedz*Failed to find executable %s in%s PATH: %sF) renvironrpathsepranyloggerdebugjoinr exe_exists)cmdraddeddexpandedr r r path_surgery"s&     r) __doc__loggingcertbotrcertbot.compatrcertbot.compat.miscr getLogger__name__rrrr r r rs