ó
è¾bc           @   sÓ   d  Z  d d l Z d d l Z d d l m Z m Z m Z m Z d d d g Z i  Z	 d Z
 d	 d
 „ Z d „  Z d „  Z d d d „  ƒ  YZ d	 d „ Z e e d „ Z d „  Z d „  Z e d k rÏ e ƒ  n  d S(   sž   Utilities for comparing files and directories.

Classes:
    dircmp

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

iÿÿÿÿN(   t   ifiltert   ifilterfalset   imapt   izipt   cmpt   dircmpt   cmpfilesi   i   i   c         C   sô   t  t j |  ƒ ƒ } t  t j | ƒ ƒ } | d t j k sP | d t j k rT t S| rj | | k rj t S| d | d k r‚ t St j |  | | | f ƒ } | d k rð t	 |  | ƒ } t
 t ƒ d k r× t j ƒ  n  | t |  | | | f <n  | 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.

    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.

    i    i   id   N(   t   _sigt   ost   statt   S_IFREGt   Falset   Truet   _cachet   gett   Nonet   _do_cmpt   lent   clear(   t   f1t   f2t   shallowt   s1t   s2t   outcome(    (    s   /usr/lib/python2.7/filecmp.pyR      s    &c         C   s   t  j |  j ƒ |  j |  j f S(   N(   R	   t   S_IFMTt   st_modet   st_sizet   st_mtime(   t   st(    (    s   /usr/lib/python2.7/filecmp.pyR   ;   s    c      
   C   s   t  } t |  d ƒ d } t | d ƒ L } xB t rn | j | ƒ } | j | ƒ } | | k ra t S| s- t Sq- WWd  QXWd  QXd  S(   Nt   rb(   t   BUFSIZEt   openR   t   readR   (   R   R   t   bufsizet   fp1t   fp2t   b1t   b2(    (    s   /usr/lib/python2.7/filecmp.pyR   @   s     	c           B   sÈ   e  Z d  Z d d 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   sm   | |  _  | |  _ | d  k r6 t j t j g |  _ n	 | |  _ | d  k r` d d d g |  _ n	 | |  _ d  S(   Nt   RCSt   CVSt   tags(   t   leftt   rightR   R   t   curdirt   pardirt   hidet   ignore(   t   selft   at   bR/   R.   (    (    s   /usr/lib/python2.7/filecmp.pyt   __init__o   s    			c         C   sn   t  t j |  j ƒ |  j |  j ƒ |  _ t  t j |  j ƒ |  j |  j ƒ |  _ |  j j	 ƒ  |  j j	 ƒ  d  S(   N(
   t   _filterR   t   listdirR*   R.   R/   t	   left_listR+   t
   right_listt   sort(   R0   (    (    s   /usr/lib/python2.7/filecmp.pyt   phase0{   s    c         C   s»   t  t t t j j |  j ƒ |  j ƒ ƒ } t  t t t j j |  j ƒ |  j ƒ ƒ } t | j	 t
 | j | ƒ ƒ |  _ t | j	 t | j | ƒ ƒ |  _ t | j	 t | j | ƒ ƒ |  _ d  S(   N(   t   dictR   R   R   t   patht   normcaseR6   R7   t   mapt   __getitem__R    t   __contains__t   commonR   t	   left_onlyt
   right_only(   R0   R1   R2   (    (    s   /usr/lib/python2.7/filecmp.pyt   phase1ƒ   s
    **!!c   
      C   s}  g  |  _  g  |  _ g  |  _ x[|  j D]P} t j j |  j | ƒ } t j j |  j | ƒ } d } y t j	 | ƒ } Wn t j
 k
 r’ } d } n Xy t j	 | ƒ } Wn t j
 k
 rÄ } d } n X| ret	 j | j ƒ } t	 j | j ƒ }	 | |	 k r|  j j | ƒ qut	 j | ƒ r0|  j  j | ƒ qut	 j | ƒ rR|  j j | ƒ qu|  j j | ƒ q% |  j j | ƒ q% Wd  S(   Ni   i    (   t   common_dirst   common_filest   common_funnyR@   R   R;   t   joinR*   R+   R	   t   errorR   R   t   appendt   S_ISDIRt   S_ISREG(
   R0   t   xt   a_patht   b_patht   okt   a_statt   whyt   b_statt   a_typet   b_type(    (    s   /usr/lib/python2.7/filecmp.pyt   phase2Š   s4    			

c         C   s7   t  |  j |  j |  j ƒ } | \ |  _ |  _ |  _ d  S(   N(   R   R*   R+   RE   t
   same_filest
   diff_filest   funny_files(   R0   t   xx(    (    s   /usr/lib/python2.7/filecmp.pyt   phase3­   s    c         C   ss   i  |  _  xc |  j D]X } t j j |  j | ƒ } t j j |  j | ƒ } t | | |  j |  j	 ƒ |  j  | <q Wd  S(   N(
   t   subdirsRD   R   R;   RG   R*   R+   R   R/   R.   (   R0   RL   t   a_xt   b_x(    (    s   /usr/lib/python2.7/filecmp.pyt   phase4±   s
    	c         C   s2   |  j  ƒ  x! |  j j ƒ  D] } | j ƒ  q Wd  S(   N(   R^   R[   t
   itervaluest   phase4_closure(   R0   t   sd(    (    s   /usr/lib/python2.7/filecmp.pyR`   »   s    
c         C   s0  d G|  j  G|  j GH|  j rC |  j j ƒ  d G|  j  Gd G|  j GHn  |  j rs |  j j ƒ  d G|  j Gd G|  j GHn  |  j r˜ |  j j ƒ  d G|  j GHn  |  j r½ |  j j ƒ  d G|  j GHn  |  j râ |  j j ƒ  d G|  j GHn  |  j r|  j j ƒ  d G|  j GHn  |  j	 r,|  j	 j ƒ  d G|  j	 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+   RA   R8   RB   RV   RW   RX   RD   RF   (   R0   (    (    s   /usr/lib/python2.7/filecmp.pyt   reportÀ   s,    							c         C   s3   |  j  ƒ  x" |  j j ƒ  D] } H| j  ƒ  q Wd  S(   N(   Rd   R[   R_   (   R0   Ra   (    (    s   /usr/lib/python2.7/filecmp.pyt   report_partial_closureÙ   s    
c         C   s3   |  j  ƒ  x" |  j j ƒ  D] } H| j ƒ  q Wd  S(   N(   Rd   R[   R_   t   report_full_closure(   R0   Ra   (    (    s   /usr/lib/python2.7/filecmp.pyRf   ß   s    
R[   RV   RW   RX   RD   RE   RF   R@   RA   RB   R6   R7   c         C   s9   | |  j  k r t | ‚ n  |  j  | |  ƒ t |  | ƒ S(   N(   t	   methodmapt   AttributeErrort   getattr(   R0   t   attr(    (    s   /usr/lib/python2.7/filecmp.pyt   __getattr__ë   s    N(   t   __name__t
   __module__t   __doc__R   R3   R9   RC   RU   RZ   R^   R`   Rd   Re   Rf   R:   Rg   Rk   (    (    (    s   /usr/lib/python2.7/filecmp.pyR   M   s"    			#		
				c         C   sk   g  g  g  f } xU | D]M } t  j j |  | ƒ } t  j j | | ƒ } | t | | | ƒ j | ƒ q 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

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

    (   R   R;   RG   t   _cmpRI   (   R1   R2   R@   R   t   resRL   t   axt   bx(    (    s   /usr/lib/python2.7/filecmp.pyR   ñ   s    !c         C   s=   y | | |  | | ƒ ƒ SWn t  j t f k
 r8 d SXd  S(   Ni   (   R   RH   t   IOError(   R1   R2   t   sht   absR   (    (    s   /usr/lib/python2.7/filecmp.pyRo     s    c         C   s   t  t | j |  ƒ ƒ S(   N(   t   listR   R?   (   t   flistt   skip(    (    s   /usr/lib/python2.7/filecmp.pyR4     s    c          C   sœ   d d  l  }  d d  l } | j |  j d d ƒ \ } } t | ƒ d k r^ | j d d  ƒ ‚ n  t | d | d ƒ } d	 | k rŽ | j ƒ  n
 | j ƒ  d  S(
   Niÿÿÿÿi   t   ri   s   need exactly two argsi    s   -rt    (   s   -rRz   (	   t   syst   getoptt   argvR   t   GetoptErrorR   R   Rf   Rd   (   R{   R|   t   optionst   argst   dd(    (    s   /usr/lib/python2.7/filecmp.pyt   demo  s    t   __main__i    (    (   Rn   R   R	   t	   itertoolsR    R   R   R   t   __all__R   R   R   R   R   R   R   Ru   Ro   R4   R‚   Rl   (    (    (    s   /usr/lib/python2.7/filecmp.pyt   <module>
   s    "&		¤			