ó
à™xTc           @   s   d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d e f d „  ƒ  YZ d „  Z	 e
 e
 d „ Z d „  Z d S(	   iÿÿÿÿ(   t   division(   t   find_unused_imports_crudeNt   file_clutterc           B   sb   e  Z e j d  e j ƒ Z e e d „ Z d „  Z	 d „  Z
 e e d „ Z e d e e d „ Z RS(   s3   ^ from [ ]+ __future__ [ ]+ import [ \w,]+ divisionc         C   sg  | |  _  t j | t j ƒ |  _ t |  _ g  |  _ d |  _ t |  _	 d |  _
 d  |  _ d  |  _ d  |  _ t | d ƒ j ƒ  } t | ƒ d k rc| d d k r¬ t |  _	 n
 | d  } | j d ƒ } x¡ t | ƒ D]“ \ } } | j d ƒ r| d  } t |  _ n  | j ƒ  j ƒ  } | | k r8|  j j | d ƒ n  t | ƒ d k r\|  j d 7_ qÒ d |  _ qÒ W| j d ƒ rcd |  _ | j ƒ  }	 xˆ |	 D]€ } |  j j | ƒ r¾|  j d 7_ n  | j ƒ  }
 |
 j d ƒ r”|
 d	 j ƒ  j d
 ƒ r”|
 j d ƒ r”|  j
 d 7_
 q”q”W| rE| j d ƒ rEt j d |	 ƒ |  _ n  | r`t  | ƒ |  _ q`qcn  d  S(   Ni    t   rbiÿÿÿÿs   
s   i   s   .pyt   excepti   t   :s    # intentionalt   py_lines(!   t   patht   ost   accesst   X_OKt   is_executablet   Falset
   dos_formatt   n_tabs_or_trailing_whitespacet   n_trailing_empty_linest   missing_eolt   n_bare_exceptst   Nonet   unused_importst   n_from_future_import_divisiont   bad_indentationt   opent   readt   lent   Truet   splitt	   enumeratet   endswitht
   expandtabst   rstript   appendt
   splitlinest   from_future_import_division_patt   searcht   stript
   startswithR   t   inspectt   detect_indentation_problems(   t   selfR   t   find_unused_importst   find_bad_indentationt   bytest   textt   it   linet
   clean_lineR   t   ls(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   __init__   sT    									

  		c         C   sL   |  j  r | pK |  j pK t |  j ƒ d k pK |  j d k pK |  j pK |  j S(   Ni    i   (   R   R   R   R   R   R   R   (   R'   t   flag_x(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   is_cluttered7   s    		c         C   s"   |  j  d  k	 o! t |  j  ƒ d k S(   Ni    (   R   R   R   (   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   has_unused_imports?   s    c   
         s  g  ‰  ‡  f d †  } |  j  ru | ru |  j j ƒ  j d ƒ d k  ru |  j j d ƒ ru |  j j d ƒ ru | d ƒ n  | r‘ |  j r‘ | d ƒ n  t |  j ƒ d k r
d t |  j ƒ } xA t |  j ƒ D]0 \ } } | d	 t	 | ƒ 7} | d
 k rÉ PqÉ qÉ W| | ƒ n  |  j
 d k r-| d |  j
 ƒ n  |  j rC| d ƒ n  |  j d k rf| d |  j ƒ n  |  j ƒ  rŒ| d t |  j ƒ ƒ n  |  j d k r¨| d ƒ n |  j d k rÄ| d ƒ n  |  j d  k	 rÿ| rÿ|  j \ } }	 | d |	 | f ƒ n  d j ˆ  ƒ S(   Nc            s   ˆ  j  |  ƒ d  S(   N(   R   (   t   s(   t   status(    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   sappD   s    t   command_linei    s   .cshs   .shs   is executables
   dos formats   tabs or trailing whitespace=%ds   , #i	   i   s   trailing empty lines=%ds   missing end-of-lines   bare excepts=%ds   unused imports=%ds)   missing 'from __future__ import division's=   more than one appearance of 'from __future__ import division's*   non-standard indentation: %d space, %d tabs   , (   R   R   t   lowert   findR   R   R   R   R   t   strR   R   R   R3   R   R   R   R   t   join(
   R'   R1   t   flag_dos_formatt   flag_indentationR6   R-   t   cntR,   t   n_tabt   n_space(    (   R5   sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyR5   B   sB    	c   	      C   s¨   |  j  | | | ƒ } t | ƒ d k r¤ d |  j | f } | d  k	 rS | | ƒ n | GH| r¤ |  j ƒ  r¤ d d j |  j ƒ } | d  k	 r™ | | ƒ q¡ | GHq¤ n  d  S(   Ni    s   %s: %ss     unused imports: %ss   , (   R5   R   R   R   R3   R;   R   (	   R'   R1   R<   R   t   verboseR=   R5   t   msgt   msg2(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   showe   s    N(   t   __name__t
   __module__t   ret   compilet   VERBOSER!   R   R   R0   R2   R3   R5   R   RD   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyR      s   +		#	c         C   s4   |  j  ƒ  } x! d D] } | j | ƒ r t Sq Wt S(   Ns   .cs   .cpps   .hs   .hpps   .pys   .javas   .paramss   .doxs   .txts   .htmls   .cshs   .shs   .cifs   .cc(   s   .cs   .cpps   .hs   .hpps   .pys   .javas   .paramss   .doxs   .txts   .htmls   .cshs   .shs   .cifs   .cc(   R8   R   R   R   (   t	   file_namet   namet	   extension(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   is_text_fileu   s    
 c            sâ   g  ‰  ‡  ‡ ‡ ‡ f d †  } x½ |  D]µ ‰ t  j j ˆ ƒ sS t j d Iˆ IJq% t  j j ˆ ƒ ro | ƒ  q% xh t  j ˆ ƒ D]W \ } } } xE | D]= } t | ƒ r• t  j j t  j j	 | | ƒ ƒ ‰ | ƒ  q• q• Wq Wq% Wˆ  S(   Nc              s    ˆ  j  t ˆ ˆ d ˆ ƒƒ d  S(   NR)   (   R   R   (    (   t   clutterR)   R(   R   (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   capp~   s    s   No such file or directory:(
   R   R   t   existst   syst   stderrt   isfilet   walkRM   t   normpathR;   (   t   pathsR(   R)   RO   t   roott   dirst   filest   f(    (   RN   R)   R(   R   sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   gather|   s    
!c         C   sÒ   y d d  l  } Wn t k
 r$ d  SX| j ƒ  } | j ƒ  | j |  ƒ | j ƒ  } | | j k rg d  S| \ } } d } } | d k rÊ | d k rž | } n | } | d k rÀ | d k rÀ d  S| | f S| Sd  S(   Niÿÿÿÿi    t   mixedt   spacei   (   t   indent_findert   ImportErrorR   t   IndentFindert   cleart
   parse_filet   resultst   default_result(   RJ   R^   t   fit   resultt   itypet   ivalR?   R@   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyR&   Ž   s*    

	
(   t
   __future__R    t   libtbx.command_lineR   RQ   R   RG   t   objectR   RM   R   R[   R&   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/file_clutter.pyt   <module>   s   o	