ó
úJVNc           @   sÝ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e j d d e	 ƒj
 Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿNs   command-not-foundt   fallbackt   BinaryDatabasec           B   s   e  Z d  „  Z d „  Z RS(   c         C   sh   d  |  _ | j d ƒ rd y t j | d ƒ |  _ Wqd t j k
 r` } t j d | | f IJqd Xn  d  S(   Ns   .dbt   rs%   Unable to open binary database %s: %s(   t   Nonet   dbt   endswitht   gdbmt   opent   errort   syst   stderr(   t   selft   filenamet   err(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   __init__   s    	c         C   s.   |  j  r& |  j  j | ƒ r& |  j  | Sd  Sd  S(   N(   R   t   has_keyR   (   R   t   key(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   lookup   s    (   t   __name__t
   __module__R   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR      s   	t   FlatDatabasec           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sW   g  |  _  t | ƒ } x1 d „  | Dƒ D] } |  j  j | j d ƒ ƒ q& W| j ƒ  d  S(   Nc         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   strip(   t   .0t   line(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pys	   <genexpr>&   s    t   |(   t   rowst   filet   appendt   splitt   close(   R   R   t   dbfileR   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   #   s
    	c         C   s>   g  } x1 |  j  D]& } | | | k r | j | ƒ q q W| S(   N(   R   R   (   R   t   columnt   textt   resultt   row(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   *   s
    c         C   s/   x( |  j  D] } | j | | | ƒ ƒ q
 Wd  S(   N(   R   R   (   R   t   cbR   R"   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   createColumnByCallback1   s    c         C   sA   g  } x4 |  j  D]) } | | | | ƒ r | j | ƒ q q W| S(   N(   R   R   (   R   R   R#   R    R!   R"   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   lookupWithCallback5   s
    (   R   R   R   R   R$   R%   (    (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   !   s   			t   ProgramDatabasec           B   s,   e  Z e d  ƒ \ Z Z d „  Z d „  Z RS(   i   c         C   sM   t  j j | ƒ } | j d ƒ d j d ƒ \ |  _ |  _ t | ƒ |  _ d  S(   Nt   .i    t   -(   t   ost   patht   basenameR   t   archt	   componentR   R   (   R   R   R+   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   A   s    (c         C   s-   |  j  j | ƒ } | r% | j d ƒ Sg  Sd  S(   NR   (   R   R   R   (   R   t   commandR!   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   F   s    (   R   R   t   ranget   PACKAGEt   BASENAME_PATHR   R   (    (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR&   =   s   	c         C   s;  d } g  t  t |  ƒ d ƒ D] } |  |  |  | f ^ q } g  | D]  \ } } | rD | | d ^ qD } g  | D]< \ } } t | ƒ d k rq | | d | d | d ^ qq } g  | D]1 \ } } | D] } | rÊ | | | d ^ qÊ qº }	 g  | D]' \ } } | D] } | | | ^ qqø }
 t | | |	 |
 ƒ S(   sw   
    return a set with spelling1 distance alternative spellings

    based on http://norvig.com/spell-correct.html
    s&   abcdefghijklmnopqrstuvwxyz-_0123456789i   i    i   (   R/   t   lent   set(   t   wordt   alphabett   it   st   at   bt   deletest
   transposest   ct   replacest   inserts(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   similar_wordsN   s    7-I>4t   CommandNotFoundc           B   s_   e  Z d  Z d Z d d	 „ Z d
 d d „ Z d „  Z d „  Z d „  Z d „  Z	 e
 d „ Z RS(   s
   programs.ds   /bins   /usr/bins   /usr/local/bins   /sbins	   /usr/sbins   /usr/local/sbins
   /usr/gamess   /usr/share/command-not-foundc         C   s>  g  |  _  g  |  _ t j j | d ƒ } t j j | ƒ r] t t j t	 | ƒ j
 ƒ  ƒ |  _ n  d d d d d d g |  _ |  j j ƒ  |  j ƒ  |  _ x` t j t j j j | |  j g ƒ ƒ D]7 } |  j  j t t j j j | |  j | g ƒ ƒ ƒ q¼ Wy& t j d ƒ d	 t j ƒ  k |  _ Wn t k
 r9t |  _ n Xd  S(
   Ns   priority.txtt   maint   universet   contribt
   restricteds   non-freet
   multiverset   admini   (   t   programst   priority_overridesR)   R*   t   joint   existst   mapt   stringR   R   t	   readlinest
   componentst   reverset   _getSourcesListt   sources_listt   listdirt   sept   programs_dirR   R&   t   grpt   getgrnamt   posixt	   getgroupst   user_can_sudot   KeyErrort   False(   R   t   data_dirt   pR   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR   j   s    		$.5&i   i   c         C   s  t  | ƒ | k  r d Sg  } xP t | ƒ D]B } |  j | ƒ } x* | D]" \ } } | j | | | f ƒ qE Wq) Wt  | ƒ | k r§ t j t d ƒ | t  | ƒ f IJnf t  | ƒ d k rt j t d ƒ | IJx: | D]/ \ } }	 }
 t j t d ƒ | |	 |
 f IJq× Wn  d S(   s    try to correct the spelling Ns4   No command '%s' found, but there are %s similar onesi    s$   No command '%s' found, did you mean:s$    Command '%s' from package '%s' (%s)(   R2   R?   t   getPackagesR   R	   R
   t   _(   R   R4   t   min_lent   max_lent   possible_alternativest   wt   packagest   packaget   compR]   R<   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   print_spelling_suggestion{   s    &c         C   sY   t  ƒ  } xC |  j D]8 } | j g  | j | ƒ D] } | | j f ^ q/ ƒ q Wt | ƒ S(   N(   R3   RG   t   updateR   R-   t   list(   R   R.   R!   R   t   pkg(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR^   ‹   s    	6c         C   s€   y] t  t j j t j d d ƒ d f ƒ ƒ } g  | D]$ } | j ƒ  d k r4 | j ƒ  ^ q4 SWn t k
 rq g  SX| j ƒ  d  S(   Nt   HOMEs   /roots   .command-not-found.blacklistt    (   R   R)   RS   RI   t   getenvR   t   IOErrorR   (   R   t	   blacklistR   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   getBlacklist‘   s    *3c         C   s§   y* d d  l  } d d l m } | j ƒ  Wn t t f k
 rD g  SXt g  ƒ } xO | d t ƒ D]> } | j ra | j	 ra x! | j
 D] } | j | ƒ q… Wqa qa W| S(   Niÿÿÿÿ(   t   SourcesListt   withMatcher(   t   apt_pkgt   aptsources.sourceslistRq   t   initt   SystemErrort   ImportErrorR3   R[   t   disabledt   invalidt   compst   add(   R   Rs   Rq   RQ   t   sourceR-   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyRP   š   s    c         C   sÂ   | d |  j  k r) | d |  j  k r) n. | d |  j  k r@ d S| d |  j  k rW d Sy |  j j | d ƒ } Wn d } n Xy |  j j | d ƒ } Wn d } n X| | pÁ t | | ƒ S(   Ni    iÿÿÿÿi   (   RH   RN   t   indext   cmp(   R   t   xt   yt   xidxt   yidx(    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   sortByComponent«   s     

c   	   	   C   sG  d „  } | j  d ƒ rK t j j | ƒ rB t j j | ƒ g } qv g  } n+ g  |  j D] } | | | ƒ rU | ^ qU } | r´| r´t | ƒ d k rÐ t j t	 d ƒ i | d 6t j j
 | d | ƒ d 6IJnO t j t	 d ƒ i | d 6IJx. | D]& } t j d	 t j j
 | | ƒ IJqõ Wt t | ƒ t t j d
 d ƒ j d ƒ ƒ ƒ } t | ƒ d k r°t j t	 d ƒ d j
 | ƒ IJd d j
 | ƒ k r°t j t	 d ƒ IJq°n  t St j j d ƒ pÕt j j d ƒ sÜt S| |  j ƒ  k ròt S|  j | ƒ } t | ƒ d k r#|  j | ƒ nt | ƒ d k r.t j t	 d ƒ | It j ƒ  d k rt j t	 d ƒ IJt j d | d d IJne |  j rÅt j t	 d ƒ IJt j d | d d IJn- t j t	 d ƒ i | d 6| d d d 6IJ| d d |  j k r7t j t	 d ƒ | d d IJq7n	t | ƒ d k r7| j |  j ƒ t j t	 d ƒ | IJxh | D]` } | d |  j k rŸt j d	 | d IJqnt j d	 | d d t	 d ƒ | d d IJqnWt j ƒ  d k rþt j t	 d ƒ d IJq7|  j r!t j t	 d ƒ d IJq7t j t	 d  ƒ IJn  t | ƒ d k S(!   s7    give advice where to find the given command to stderr c         S   sA   t  j j t  j j |  | ƒ ƒ o@ t  j j t  j j |  | ƒ ƒ S(   s?    helper that returns if a command is found in the given prefix (   R)   R*   RJ   RI   t   isdir(   t   prefixR.   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt
   _in_prefixÂ   s    !t   /i   s1   Command '%(command)s' is available in '%(place)s'R.   i    t   places:   Command '%(command)s' is available in the following placess    * %st   PATHRl   t   :s_   The command could not be located because '%s' is not included in the PATH environment variable.t   sbinsf   This is most likely caused by the lack of administrative privileges associated with your user account.s   /usr/bin/apt-gets   /usr/bin/aptitudes-   The program '%s' is currently not installed. s   You can install it by typing:s   apt-get install %ss   sudo apt-get install %ssW   To run '%(command)s' please ask your administrator to install the package '%(package)s'Re   s1   You will have to enable the component called '%s's8   The program '%s' can be found in the following packages:s    (s-   You will have to enable component called '%s't   )s   Try: %s <selected package>s   apt-get installs   sudo apt-get installs-   Ask your administrator to install one of them(   t
   startswithR)   R*   RJ   t   dirnamet   prefixesR2   R	   R
   R_   RI   Ri   R3   Rm   R   R[   Rp   R^   Rg   RW   t   geteuidRY   RQ   t   sortRƒ   (	   R   R.   t   ignore_installedR†   R   R…   t   missingRd   Re   (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   adviseÀ   sd    		+;$1 	-%3	(   s   /bins   /usr/bins   /usr/local/bins   /sbins	   /usr/sbins   /usr/local/sbins
   /usr/games(   R   R   RT   R   R   Rg   R^   Rp   RP   Rƒ   R[   R”   (    (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyR@   ]   s         					(   R   t   gettextRU   R)   t   os.pathRW   RL   R	   t   translationt   Truet   ugettextR_   t   objectR   R   R&   R?   R@   (    (    (    sC   /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.pyt   <module>   s   	