ó
Y[c           @   sS   d  Z  d d l Z d d l Z d d l m Z e j e  Z d   Z d   Z	 d S(   s   Plugin utilities.i’’’’N(   t   utilc         C   sb   |  } g  } xO t  |  d k r] | j |  t j j |  \ } } | | d k r Pq q W| S(   s>  Retrieves all possible path prefixes of a path, in descending order
    of length. For instance,
        /a/b/c/ => ['/a/b/c/', '/a/b/c', '/a/b', '/a', '/']
    :param str path: the path to break into prefixes

    :returns: all possible path prefixes of given path in descending order
    :rtype: `list` of `str`
    i    i’’’’(   t   lent   appendt   ost   patht   split(   R   t   prefixt   prefixest   _(    (    s8   /usr/lib/python2.7/dist-packages/certbot/plugins/util.pyt   get_prefixes	   s    	c         C   sŪ   d
 } t  j d } g  } x; | D]3 } | | k r  | t  j | 7} | j |  q  q  Wt |  r t j d |  t  j j |   | t  j d <n  t j	 |   r„ t
 St |  r· d n d } t j d |  | |  t Sd	 S(   sö   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
    s	   /usr/sbins   /usr/local/bins   /usr/local/sbint   PATHs6   Can't find %s, attempting PATH mitigation by adding %ss	    expandedt    s*   Failed to find executable %s in%s PATH: %sN(   s	   /usr/sbins   /usr/local/bins   /usr/local/sbin(   R   t   environt   pathsepR   t   anyt   loggert   debugt   joinR    t
   exe_existst   Truet   False(   t   cmdt   dirsR   t   addedt   dt   expanded(    (    s8   /usr/lib/python2.7/dist-packages/certbot/plugins/util.pyt   path_surgery   s"    		
(
   t   __doc__t   loggingR   t   certbotR    t	   getLoggert   __name__R   R	   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/certbot/plugins/util.pyt   <module>   s   	