mς
­fIc           @   sί   d  Z  d k Z d k Z d k Z d k l Z l Z l Z l Z d d d g Z	 h  Z
 d d Z d d d	  Z d
   Z d   Z d f  d     YZ d d d  Z e e d  Z d   Z d   Z e d j o e   n d S(   s   Utilities for comparing files and directories.

Classes:
    dircmp

Functions:
    cmp(f1, f2, shallow=1) -> int
    cmpfiles(a, b, common) -> ([], [], [])

N(   s   ifilters   ifilterfalses   imaps   izipt   cmpt   dircmpt   cmpfilesi   i   i   c         C   s  | d j	 o t i d t  n t t i |    } t t i |   } | d t i j p | d t i j o t Sn | o | | j o t Sn | d | d j o t Sn t i |  | f  } | o# | | f | d  j o | d Sn t |  |  } | | | f t |  | f <| S(   s½  Compare two files.

    Arguments:

    f1 -- First file name

    f2 -- Second file name

    shallow -- Just check stat signature (do not read the files).
               defaults to 1.

    use_statcache -- obsolete argument.

    Return value:

    True if the files are the same, False otherwise.

    This function uses a cache for past comparisons and the results,
    with a cache invalidation mechanism relying on stale signatures.

    s$   use_statcache argument is deprecatedi    i   i   N(   t   use_statcachet   Nonet   warningst   warnt   DeprecationWarningt   _sigt   ost   statt   f1t   s1t   f2t   s2t   S_IFREGt   Falset   shallowt   Truet   _cachet   gett   resultt   _do_cmpt   outcome(   R   R   R   R   R   R   R   R   (    (    t$   /mit/python/lib/python2.4/filecmp.pyR       s$     	(c         C   s   t  i |  i  |  i |  i f S(   N(   R
   t   S_IFMTt   stt   st_modet   st_sizet   st_mtime(   R   (    (    R   R   @   s    c         C   sy   t  } t |  d  } t | d  } xN t oF | i |  } | i |  } | | j o t Sn | p t Sq' q' Wd  S(   Nt   rb(   t   BUFSIZEt   bufsizet   openR   t   fp1R   t   fp2R   t   readt   b1t   b2R   (   R   R   R"   R%   R&   R#   R    (    (    R   R   E   s     c           B   sΘ   t  Z d  Z e e d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z e d e	 d e d e d e d e d e d e d e d e d e d e d e  Z d   Z RS(   sQ  A class that manages the comparison of 2 directories.

    dircmp(a,b,ignore=None,hide=None)
      A and B are directories.
      IGNORE is a list of names to ignore,
        defaults to ['RCS', 'CVS', 'tags'].
      HIDE is a list of names to hide,
        defaults to [os.curdir, os.pardir].

    High level usage:
      x = dircmp(dir1, dir2)
      x.report() -> prints a report on the differences between dir1 and dir2
       or
      x.report_partial_closure() -> prints report on differences between dir1
            and dir2, and reports on common immediate subdirectories.
      x.report_full_closure() -> like report_partial_closure,
            but fully recursive.

    Attributes:
     left_list, right_list: The files in dir1 and dir2,
        filtered by hide and ignore.
     common: a list of names in both dir1 and dir2.
     left_only, right_only: names only in dir1, dir2.
     common_dirs: subdirectories in both dir1 and dir2.
     common_files: files in both dir1 and dir2.
     common_funny: names in both dir1 and dir2 where the type differs between
        dir1 and dir2, or the name is not stat-able.
     same_files: list of identical files.
     diff_files: list of filenames which differ.
     funny_files: list of files which could not be compared.
     subdirs: a dictionary of dircmp objects, keyed by names in common_dirs.
     c         C   sq   | |  _ | |  _ | d  j o t i t i	 g |  _ n
 | |  _ | d  j o d d d g |  _
 n
 | |  _
 d  S(   Nt   RCSt   CVSt   tags(   t   at   selft   leftt   bt   rightt   hideR   R	   t   curdirt   pardirt   ignore(   R+   R*   R-   R2   R/   (    (    R   t   __init__u   s    			c         C   sn   t  t i |  i  |  i |  i  |  _ t  t i |  i  |  i |  i  |  _	 |  i i
   |  i	 i
   d  S(   N(   t   _filterR	   t   listdirR+   R,   R/   R2   t	   left_listR.   t
   right_listt   sort(   R+   (    (    R   t   phase0   s    c         C   s»   t  t t t i i |  i  |  i   } t  t t t i i |  i	  |  i	   } t | i t | i |   |  _ t | i t | i |   |  _ t | i t | i |   |  _ d  S(   N(   t   dictt   izipt   imapR	   t   patht   normcaseR+   R6   R*   R7   R-   t   mapt   __getitem__t   ifiltert   has_keyt   commont   ifilterfalset	   left_onlyt
   right_only(   R+   R*   R-   (    (    R   t   phase1   s
    **!!c   
      C   s  g  |  _ g  |  _ g  |  _ xg|  i D]\} t i i |  i	 |  } t i i |  i |  } d } y t i |  } Wn t i j
 o }	 d } n Xy t i |  } Wn t i j
 o }	 d } n X| o‘ t i | i  } t i | i  } | | j o |  i i |  qt i |  o |  i i |  qt i |  o |  i i |  q|  i i |  q% |  i i |  q% Wd  S(   Ni   i    (   R+   t   common_dirst   common_filest   common_funnyRC   t   xR	   R=   t   joinR,   t   a_pathR.   t   b_patht   okR
   t   a_statt   errort   whyt   b_statR   R   t   a_typet   b_typet   appendt   S_ISDIRt   S_ISREG(
   R+   RN   RO   RU   RS   RT   RP   RM   RK   RR   (    (    R   t   phase2   s6    			
 c         C   s7   t  |  i |  i |  i  } | \ |  _ |  _ |  _ d  S(   N(	   R   R+   R,   R.   RI   t   xxt
   same_filest
   diff_filest   funny_files(   R+   RZ   (    (    R   t   phase3³   s    c         C   ss   h  |  _ xc |  i D]X } t i i |  i |  } t i i |  i	 |  } t | | |  i |  i  |  i | <q Wd  S(   N(   R+   t   subdirsRH   RK   R	   R=   RL   R,   t   a_xR.   t   b_xR   R2   R/   (   R+   R`   Ra   RK   (    (    R   t   phase4·   s    	
 c         C   s2   |  i   x! |  i i   D] } | i   q Wd  S(   N(   R+   Rb   R_   t
   itervaluest   sdt   phase4_closure(   R+   Rd   (    (    R   Re   Α   s    
 c         C   s>  d G|  i G|  i GH|  i o( |  i i   d G|  i Gd G|  i GHn |  i o( |  i i   d G|  i Gd G|  i GHn |  i o |  i i   d G|  i GHn |  i o |  i i   d G|  i GHn |  i o |  i i   d G|  i GHn |  i	 o |  i	 i   d G|  i	 GHn |  i
 o |  i
 i   d G|  i
 GHn d  S(	   Nt   diffs   Only int   :s   Identical files :s   Differing files :s   Trouble with common files :s   Common subdirectories :s   Common funny cases :(   R+   R,   R.   RE   R8   RF   R[   R\   R]   RH   RJ   (   R+   (    (    R   t   reportΖ   s,    






c         C   s3   |  i   x" |  i i   D] } H| i   q Wd  S(   N(   R+   Rh   R_   Rc   Rd   (   R+   Rd   (    (    R   t   report_partial_closureί   s
    
 c         C   s3   |  i   x" |  i i   D] } H| i   q Wd  S(   N(   R+   Rh   R_   Rc   Rd   t   report_full_closure(   R+   Rd   (    (    R   Rj   ε   s
    
 R_   R[   R\   R]   RH   RI   RJ   RC   RE   RF   R6   R7   c         C   s;   | |  i j o t |  n |  i | |   t |  |  S(   N(   t   attrR+   t	   methodmapt   AttributeErrort   getattr(   R+   Rk   (    (    R   t   __getattr__ρ   s    (   t   __name__t
   __module__t   __doc__R   R3   R9   RG   RY   R^   Rb   Re   Rh   Ri   Rj   R:   Rl   Ro   (    (    (    R   R   S   s"     			#		
					c   	      C   s   | d j	 o t i d t  n g  g  g  f } xU | D]M } t i	 i
 |  |  } t i	 i
 | |  } | t | | |  i |  q7 W| S(   s  Compare common files in two directories.

    a, b -- directory names
    common -- list of file names found in both directories
    shallow -- if true, do comparison based solely on stat() information
    use_statcache -- obsolete argument

    Returns a tuple of three lists:
      files that compare equal
      files that are different
      filenames that aren't regular files.

    s$   use_statcache argument is deprecatedN(   R   R   R   R   R   t   resRC   RK   R	   R=   RL   R*   t   axR-   t   bxt   _cmpR   RV   (	   R*   R-   RC   R   R   Rs   Rt   RK   Ru   (    (    R   R   χ   s     	 !c         C   s<   y | | |  | |   SWn t i j
 o d Sn Xd  S(   Ni   (   t   absR    R*   R-   t   shR	   RQ   (   R*   R-   Rx   Rw   R    (    (    R   Rv     s    c         C   s   t  t | i |    S(   N(   t   listRD   t   skipt   __contains__t   flist(   R|   Rz   (    (    R   R4     s    c          C   s   d  k  } d  k } | i | i d d  \ } } t |  d j o | i d d    n t | d | d  }  d | j o |  i
   n |  i   d  S(	   Ni   t   ri   s   need exactly two argsi    s   -rt    (   s   -rR~   (   t   syst   getoptt   argvt   optionst   argst   lent   GetoptErrorR   R   t   ddRj   Rh   (   R   R   R   R   R   (    (    R   t   demo%  s    		t   __main__(   Rr   R	   R
   R   t	   itertoolsRA   RD   R<   R;   t   __all__R   R   R   R    R   R   R   R   Rw   Rv   R4   R   Rp   (   RA   R
   R   R   R   R   R;   Rv   R4   RD   R   R   R   R   R	   R<   R   R    (    (    R   t   ?
   s"   			
*		€			