ó
á™xTc           @   s½   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	 d  d l
 m
 Z
 d  d l Z d  d l Z d  d l Z d „  Z d	 d
 „ Z e d k r¹ e e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   walk_source_tree(   t   show_string(   t   Sorry(   t   option_parser(   t   fnmatchNc         C   s8   y t  |  d ƒ } Wn t k
 r' g  SX| j ƒ  j ƒ  S(   Nt   r(   t   opent   IOErrort   readt
   splitlines(   t	   file_patht   f(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/find_files.pyt   read_lines_if_possible
   s
      s   libtbx.find_filesc            s¦  t  |  ƒ d k r d g }  n  t d d | d d ƒ j d d d	 d
 d d d d d d ƒj d d d	 d
 d d d d d d ƒj d d d	 d d t d d ƒj d d d	 d d t d d ƒj d d d	 d d t d d ƒj d  |  ƒ } | j } | j ‰  d ‰ ˆ  j rˆ t j	 O‰ n  t  | ƒ d k r4d! g } n  ˆ  j
 } | d  k rUd" g } n  xJ| D]B} t j j | ƒ s�t d# t | ƒ ƒ ‚ n  xt d$ | ƒ D]ý } t j j | ƒ } xâ | D]Ú } t | | ƒ r¼ˆ  j rét | ƒ }	 n | }	 ˆ  j d  k r|	 GHq–ˆ  j }
 x„ t d% | ƒ D]p ‰ |
 s:d& ˆ k }
 n  ‡  ‡ ‡ f d' †  } | ƒ  rˆ  j rj|	 GHPq�|
 r}d( |	 GHPq�d) |	 ˆ f GHqqWq¼q¼Wq�Wq\Wd  S(*   Ni    s   --helpt   usages   %s [options] pattern ...t   descriptionsa   Recursively finds all files matching patterns,
excluding CVS and .svn directories and .pyc files.s   -ts   --topt   actiont   appendt   typet   stringt   metavart   PATHt   helpsN   top-level directory where search starts (default is current working directory)s   -gs   --grept   PATTERNsV   find regular expression pattern in each file (multiple -g/--grep options can be given)s   -is   --ignore_caset
   store_truet   defaults&   with -g/--grep: case-insensitive matchs   -fs   --file_names_onlys<   with -g/--grep: show file names only, not the matching liness   -qs   --quotes   quote file namest   argst   *t   .s   Not a directory: %st   topR   t    c             s@   x9 ˆ  j  D]. }  t j d |  d ˆ d ˆ ƒ d  k r
 t Sq
 Wt S(   Nt   patternR   t   flags(   t   grept   ret   searcht   Nonet   Falset   True(   t   grep_pattern(   t   cot
   grep_flagst   line(    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/find_files.pyt   line_matches_all_grep_patternsH   s    	s   %s: match in binary files   %s: %s(   t   lenR   t   optionR%   t   processR   t   optionst   ignore_caseR"   t
   IGNORECASER   R$   t   ost   patht   isdirR   R   R   t   basenameR   t   quoteR!   t   file_names_onlyR   (   R   t   command_namet   command_linet   fn_patternst   topsR   R   t	   file_namet
   fn_patternt   fpt   is_binary_fileR+   (    (   R(   R)   R*   sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/find_files.pyt   run   s~     
																 				t   __main__i   (   t
   __future__R    t   libtbx.pathR   t   libtbx.str_utilsR   t   libtbx.utilsR   t   libtbx.option_parserR   R   R"   t   sysR2   R   R@   t   __name__t   argv(    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/find_files.pyt   <module>   s   	K