ó
²,]c           @ s+  d  Z  d d l m Z m Z d d l j Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z m Z d d	 l m Z m  Z  d d
 l! m" Z# d d l$ m% Z% d d l& m' Z' d d l( m) Z) d d l* m+ Z+ m, Z, d d l- m. Z. d d l/ m0 Z0 y e d d  Z1 Wn( e2 k
 rŖZ3 d d l4 Z4 e4 j4 Z1 n Xd Z5 e
 j6 Z7 e j8 d e1 d  d e5 d e7 d e. f d     YZ9 d e f d     YZ: d   Z; e< d k r'e;   n  d S(   s   Pylint widgeti’’’’(   t   print_functiont   with_statementN(   t   getopenfilename(   t
   QByteArrayt   QProcesst   Signalt   Slot(   t   QHBoxLayoutt   QLabelt   QMessageBoxt   QTreeWidgetItemt   QVBoxLayoutt   QWidget(   t   dependencies(   t   get_conf_patht   get_translation(   t   picklet   to_text_string(   t   icon_manager(   t   to_unicode_from_fs(   t   create_toolbutton(   t   getcwd_or_home(   t   is_module_or_packaget   PythonModulesComboBox(   t   OneColumnTree(   t
   TextEditort   pylintt   spyder_pylints   >=0.25s   Static code analysist   required_versiont   installed_versiont   ResultsTreec           B s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C s<   t  j |  |  d  |  _ d  |  _ d  |  _ |  j d  d  S(   Nt    (   R   t   __init__t   Nonet   filenamet   resultst   datat	   set_title(   t   selft   parent(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR    9   s
    			c         C sS   |  j  j t |   } | d k	 rO | \ } } |  j   j j | | d  n  d S(   s   Double-click eventR   N(   R$   t   gett   idR!   R'   t	   edit_gotot   emit(   R&   t   itemR$   t   fnamet   lineno(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt	   activated@   s    c         C s   |  j  |  d S(   s   Click eventN(   R/   (   R&   R,   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   clickedG   s    c         C s   |  j    |  j d  d  S(   NR   (   t   clearR%   (   R&   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   clear_resultsK   s    
c         C s    | |  _  | |  _ |  j   d  S(   N(   R"   R#   t   refresh(   R&   R"   R#   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   set_resultsO   s    		c         C sk  t  d  |  j } |  j |  |  j   i  |  _ t  d  t j d  |  j d f t  d  t j d  |  j d f t  d  t j d	  |  j d
 f t  d  t j d  |  j d f f } x£| D]\ } } } | d t |  t |  d k rž d n d f 7} t	 |  | g t	 j
  } | j d |  | sG| j t  n  i  } x| D]\ } } }	 }
 t j t j |  j   d } | j |  s°| j |  } | | } n  t j |  j  } | j d  sŻ| | k rņt j | |  } n t j | | j d   } t j |  r1t j | d  } n  x/ d D]' } t j | |  r8| | } Pq8q8Wt j |  j  r×| j |  } | d  k rŻt	 | | g t	 j
  } | j d t j d   | | | <| } qŻn | } t |
  d k rd |
 | |	 f } n d | |	 f } t	 | | g t	 j
  } | j d t j d   | | f |  j t |  <qTWqČ Wd  S(   Ns   Results for t
   Conventiont
   conventions   C:t   Refactort   refactors   R:t   Warningt   warnings   W:t   Errort   errors   E:s    (%d message%s)i   t   sR   i    t   .R    s   .pys   .pywt   pythons   [%s] %d : %ss   %d : %st   arrow(   s   .pys   .pyw(   t   _R"   R%   R1   R$   t   imat   iconR#   t   lenR
   t   Typet   setIcont   setDisabledt   Truet   ospt   splitextt   basenamet
   startswitht   findt   dirnamet   joint   splitt   isdirt   isfileR(   R!   R)   (   R&   t   titleR#   RC   t   messagest
   title_itemt   modulest   moduleR.   t   messaget   msg_idRK   t   i_baseRN   t   modnamet   extR'   R,   t   textt   msg_item(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR3   T   sd    
					#

(   t   __name__t
   __module__R    R/   R0   R2   R4   R3   (    (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR   8   s   					t   PylintWidgetc           B sŚ   e  Z d  Z e d  Z d Z e e  Z d d  Z	 d   Z
 e   d    Z d   Z d   Z d	   Z d
   Z d   Z e   d    Z e   d    Z e d  Z e d  Z d   Z d   Z e d  Z RS(   s   
    Pylint widget
    s   pylint.resultss   1.1.0id   c         C s_  t  j |  |  |  j d  d  |  _ d  |  _ | |  _ g  |  _ t j	 |  j
  rø yH t j t |  j
 d  j    } | d |  j k r | d |  _ n  Wqø t t f k
 r“ qø Xn  t |   |  _ t |  d t j d  d t d  d	 t d
  d |  j d t |  _ t |  d t j d  d t d  d	 t d  d t |  _ |  j j j |  j j  |  j j j |  j  t |  d t j d  d	 t d  d |  j  } t!   |  _" t!   |  _# t |  d t j d  d t d  d t d	 t d  d |  j$ |  _% t& |   |  _' t(   } | j) |  j  | j) |  | j) |  j  | j) |  j  t(   } | j) |  j"  | j*   | j) |  j#  | j*   | j) |  j%  t+   } | j, |  | j, |  | j) |  j'  |  j- |  d  |  _. |  j/ t0  |  j   |  j rK|  j1   |  j j2 |  j3    |  j j |  j j4    n |  j j t0  d  S(   Nt   Pylintt   rbi    i   RC   t   runR]   t   Analyzet   tips   Run analysist	   triggeredt   text_beside_icont   stopt   Stops   Stop current analysist   fileopens   Select Python filet   logt   Outputs   Complete output(5   R   R    t   setWindowTitleR!   t   outputt   error_outputt   max_entriest   rdataRI   RR   t   DATAPATHR   t   loadst   opent   readt   VERSIONt   EOFErrort   ImportErrorR   t	   filecomboR   RB   RC   RA   t   startRH   t   start_buttont   stop_buttont   validt   connectt
   setEnabledt	   show_datat   select_fileR   t	   ratelabelt	   datelabelt   show_logt
   log_buttonR   t
   treewidgetR   t	   addWidgett
   addStretchR   t	   addLayoutt	   setLayoutt   processt   set_running_statet   Falset   remove_obsolete_itemst   addItemst   get_filenamest   is_valid(   R&   R'   Rq   R$   t   browse_buttont   hlayout1t   hlayout2t   layout(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR       sx    				!			

		
	
c         C s°   t  |  } |  j   |  j |  \ } } | d  k rg |  j j |  |  j j |  j j   d  n |  j j |  j j |   |  j j	   |  j j
   r¬ |  j   n  d  S(   Ni   (   R   t   kill_if_runningt   get_dataR!   Rz   t   addItemt   setCurrentIndext   countt   findTextt   selectedR   R{   (   R&   R"   t   indext   _data(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   analyzeį   s    
 c         C sh   |  j  j t  t |  t d  t   t d  d  \ } } |  j  j t  | rd |  j |  n  d  S(   Ns   Select Python files   Python filess    (*.py ; *.pyw)(   t   redirect_stdioR+   R   R   RA   R   RH   R    (   R&   R"   t
   _selfilter(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR   ī   s    c         C s;   g  |  j  D]$ \ } } t |  r
 | | f ^ q
 |  _  d S(   s   Removing obsolete itemsN(   Rr   R   (   R&   R"   R$   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR   ų   s    c         C s    g  |  j  D] \ } } | ^ q
 S(   N(   Rr   (   R&   R"   R   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR   ż   s    c         C sS   t  j |  } x= t |  j  D]( \ } \ } } | | k r | | f Sq Wd Sd  S(   N(   NN(   RI   t   abspatht	   enumerateRr   R!   (   R&   R"   R   R-   R$   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR      s
    "c         C sj   t  j |  } |  j |  \ } } | d  k	 rC |  j j |  n  |  j j d | | f  |  j   d  S(   Ni    (   RI   R£   R   R!   Rr   t   popt   insertt   save(   R&   R"   R$   R   R   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   set_data  s    c         C s_   x, t  |  j  |  j k r. |  j j d  q Wt j |  j g |  j t |  j d  d  d  S(   Ni’’’’t   wbi   (	   RD   Rr   Rq   R„   R   t   dumpRw   Ru   Rs   (   R&   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR§     s    c      	   C s;   |  j  r7 t |  j  d t d  d t d d j   n  d  S(   NRS   s   Pylint outputt   readonlyt   sizei¼  iō  (   i¼  iō  (   Ro   R   RA   RH   t   exec_(   R&   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR     s    	c          s²  t    j j    } t      _   j j t j    j j t j	 |     j j
 j   j    j j j   f d      j j j t j   f d     j j j   j j  d   _ d   _ t } | d  k	 rBd d d g } | j d  d d	 k r| d
 d g 7} n | d g 7} | t j |  g 7} n t j |  g }   j j t j |    j j   }   j |  | s®t j   t  d  t  d   n  d  S(   Nc            s     j  d t  S(   NR<   (   t   read_outputRH   (    (   R&   (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   <lambda>$  R   c          s     j  |  |  S(   N(   t   finished(   t   ect   es(   R&   (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyRÆ   %  s    R   s   -mR   s   --output-format=textR>   i    t   0s   -it   yess9   --msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}R;   s   Process failed to start(!   R   Rz   t   currentTextR   R   t   setProcessChannelModet   SeparateChannelst   setWorkingDirectoryRI   RN   t   readyReadStandardOutputR   R®   t   readyReadStandardErrorR°   t
   ExitStatusR}   R0   t   killRo   Rp   t
   PYLINT_VERR!   RP   RK   R{   t   syst
   executablet   waitForStartedR   R	   t   criticalRA   (   R&   R"   t   plvert   p_argst   running(    (   R&   s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR{     s2    "		c         C s%   |  j  j |  |  j j |  d  S(   N(   R|   R   R}   (   R&   t   state(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR   A  s    c         C sĄ   | r |  j  j t j  n |  j  j t j  t   } xB |  j  j   r| | rf | |  j  j   7} q; | |  j  j   7} q; Wt	 | j
   d d } | r­ |  j | 7_ n |  j | 7_ d  S(   Nt   encodings   utf-8(   R   t   setReadChannelR   t   StandardErrort   StandardOutputR   t   bytesAvailablet   readAllStandardErrort   readAllStandardOutputR   R$   Rp   Ro   (   R&   R<   t   qbaR]   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR®   E  s    	c         C są  |  j  t  |  j s\ |  j rX t j |  t d  |  j  t d |  j d t j	 n  d  Si g  d 6g  d 6g  d 6g  d 6} d } d	 } x|  j j
   D]} | j |  rÅ | t |  } q n  t j d
 |  sŻ q n  | j d  } | d k rž q n  | |  } | j d | d  }	 |	 d k r0q n  | | d |	 !j   }
 |
 sSq n  t |
 j d  d  }
 | |	 d } | |
 | | f } | | d d j |  q Wd  } d } |  j j |  } | d k r|  j j d |  } | d k r|  j | t |  | !} qn  d	 } | d  k	 rd } |  j j | |  } | d k r|  j j d |  } |  j | t |  | !} qn  t |  j j    } |  j | t j   | | | f  |  j |  j |  _ |  j d t  d  S(   NR;   s   pylint error:

t   files   C:s   R:s   W:s   E:s   ************* Module R   s   ^[CRWE]+([0-9]{4})?:t   :i’’’’i   t   ,i    s   Your code has been rated at s   /10s   previous run: t   justanalyzed(   R   R   Ro   Rp   R	   RĮ   RA   t   printR¾   t   stderrt
   splitlinesRL   RD   t   ret   matchRM   t   stript   intRP   t   appendR!   R   Rz   Rµ   RØ   t   timet	   localtimeR   RH   (   R&   t	   exit_codet   exit_statusR#   t
   txt_moduleRW   t   linet   i1RY   t   i2t   line_nbRX   R,   t   ratet   txt_ratet   i_ratet
   i_rate_endt   previoust   txt_prunt   i_prunt
   i_prun_endR"   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR°   V  s^    		"
  "c         C sK   |  j  d  k	 rG |  j  j   t j k rG |  j  j   |  j  j   qG n  d  S(   N(   R   R!   RÅ   R   t   RunningR¼   t   waitForFinished(   R&   (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR     s    c         C sō  | s d  |  _ n  |  j j |  j d  k	 o< t |  j  d k  |  j   t |  j j    } | si d  S|  j	 |  \ } } | d  k r¬ t
 d  } |  j j   d } n$| \ } } }	 }
 | d  k rģ t
 d  } |  j j   d } nä d } d } d } d } t |  d	 k rd
 } n t |  d k r:d } n  t
 d  } | | | | d | f } |	 rt
 d  } d | |	 f } | | | 7} n  |  j j | |
  t t j d |  d d } | | } |  j j |  |  j j |  d  S(   Ni    s#   Source code has not been rated yet.R   s7   Analysis did not succeed (see output for more details).s.   <span style='color: #444444'><b>%s </b></span>s(   <span style='color: %s'><b>%s</b></span>s&   <span style='color: #666666'>%s</span>s   #FF0000g      @s   #22AA22g      @s   #EE5500s   Global evaluation:s   %s/10s   previous run:s    (%s %s/10)s   %d %b %Y %H:%MRĘ   t   utf8(   R!   Ro   R   R   RD   R   R   Rz   Rµ   R   RA   R   R2   t   floatR4   RŚ   t   strftimeR   t   setTextR   (   R&   RŃ   R"   t   _indexR$   R]   t	   date_textt   datetimeRć   t   previous_rateR#   t
   text_stylet
   rate_stylet   prevrate_stylet   colort	   text_prunt   date(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyR     sN    
					
(   R_   R`   t   __doc__R   Rs   Rw   R   t   boolR”   R    R    R   R   R   R   R   RØ   R§   R   R{   RH   R   R   R®   R°   R   R   (    (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyRa      s&   K	
					&	<	c          C si   d d l  m }  |  d d  } t d  } | j d d  | j   | j t  t j	 | j
    d S(   s   Run pylint widget testi’’’’(   t   qapplicationt	   test_timei   i  ią  N(   t   spyder.utils.qthelpersRż   Ra   R!   t   resizet   showR    t   __file__R¾   t   exitR­   (   Rż   t   appt   widget(    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   testŹ  s    
t   __main__(=   Rū   t
   __future__R    R   t   os.patht   pathRI   RÕ   R¾   RŚ   R   t   qtpy.compatR   t   qtpy.QtCoreR   R   R   R   t   qtpy.QtWidgetsR   R   R	   R
   R   R   t   spyderR   t   spyder.config.baseR   R   t   spyder.py3compatR   R   t   spyder.utilsR   RB   t   spyder.utils.encodingR   R’   R   t   spyder.utils.miscR   t   spyder.widgets.comboboxesR   R   t   spyder.widgets.onecolumntreeR   t*   spyder.widgets.variableexplorer.texteditorR   RA   t   KeyErrorR<   t   gettextt   PYLINT_REQVERt   __version__R½   t   addR   Ra   R  R_   (    (    (    s>   lib/python2.7/site-packages/spyder_pylint/widgets/pylintgui.pyt   <module>   sD   ".	V’ =	