m๒
ญfIc        
   @   s๋   d  Z  d k Z d k Z d k Z d k Z d k l Z d d d d d d d	 d
 d d g
 Z d e i f d     YZ	 d d d  Z
 d   Z d   Z d   Z d   Z d   Z d   Z e d  Z e d d  Z d   Z d   Z d S(   s   Utility functions for copying files and directory trees.

XXX The functions here don't copy the resource fork or other metadata on Mac.

N(   s   abspatht   copyfileobjt   copyfilet   copymodet   copystatt   copyt   copy2t   copytreet   movet   rmtreet   Errorc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t#   /mit/python/lib/python2.4/shutil.pyR	      s   i   i   c         C   s4   x- |  i |  } | p Pn | i |  q Wd S(   s=   copy data from file-like object fsrc to file-like object fdsti   N(   t   fsrct   readt   lengtht   buft   fdstt   write(   R   R   R   R   (    (    R   R       s       c         C   s   t  t i d  o5 y t i i |  |  SWqH t j
 o t SqH Xn t i i t i i	 |    t i i t i i	 |   j S(   Nt   samefile(
   t   hasattrt   ost   pathR   t   srct   dstt   OSErrort   Falset   normcaset   abspath(   R   R   (    (    R   t	   _samefile   s    c         C   s   t  |  |  o t d |  | f  n d } d } z/ t |  d  } t | d  } t | |  Wd | o | i	   n | o | i	   n Xd S(   s   Copy data from src to dsts   `%s` and `%s` are the same filet   rbt   wbN(
   R   R   R   R	   t   NoneR   R   t   openR    t   close(   R   R   R   R   (    (    R   R   '   s      c         C   sI   t  t d  o5 t i |   } t i | i  } t i | |  n d S(   s   Copy mode bits from src to dstt   chmodN(
   R   R   t   statR   t   stt   S_IMODEt   st_modet   modeR#   R   (   R   R   R%   R(   (    (    R   R   8   s
     c         C   sy   t  i |   } t i | i  } t t  d  o  t  i | | i
 | i f  n t t  d  o t  i | |  n d S(   s?   Copy all stat info (mode bits, atime and mtime) from src to dstt   utimeR#   N(   R   R$   R   R%   R&   R'   R(   R   R)   R   t   st_atimet   st_mtimeR#   (   R   R   R%   R(   (    (    R   R   ?   s      c         C   sV   t  i i |  o% t  i i | t  i i |    } n t |  |  t |  |  d S(   sV   Copy data and mode bits ("cp src dst").

    The destination may be a directory.

    N(	   R   R   t   isdirR   t   joint   basenameR   R   R   (   R   R   (    (    R   R   I   s
     %c         C   sV   t  i i |  o% t  i i | t  i i |    } n t |  |  t |  |  d S(   s]   Copy data and all stat info ("cp -p src dst").

    The destination may be a directory.

    N(	   R   R   R,   R   R-   R.   R   R   R   (   R   R   (    (    R   R   T   s
     %c         C   sI  t  i |   }	 t  i |  g  } x|	 D]} t  i i	 |  |  } t  i i	 | |  } yu | o6 t  i i |  o# t  i |  }
 t  i |
 |  n5 t  i i |  o t | | |  n t | |  Wq) t t  i f j
 o } | i | | | f  q) t j
 o } | i | i d  q) Xq) W| o t |  n d S(   sี  Recursively copy a directory tree using copy2().

    The destination directory must not already exist.
    If exception(s) occur, an Error is raised with a list of reasons.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    XXX Consider this example code rather than the ultimate tool.

    i    N(   R   t   listdirR   t   namest   mkdirR   t   errorst   nameR   R-   t   srcnamet   dstnamet   symlinkst   islinkt   readlinkt   linktot   symlinkR,   R   R   t   IOErrort   errort   whyt   appendR	   t   errt   extendt   args(   R   R   R6   R2   R3   R?   R5   R=   R4   R0   R9   (    (    R   R   `   s*      c         C   s  | o d   } n | d j o d   } n g  } y t i |   } Wn1 t i j
 o" } | t i |  t	 i
    n Xxม | D]น } t i i |  |  } y t i |  i } Wn t i j
 o d } n Xt i |  o t | | |  q y t i |  Wq t i j
 o" } | t i | t	 i
    q Xq Wy t i |   Wn/ t i j
 o  | t i |  t	 i
    n Xd S(   sม  Recursively delete a directory tree.

    If ignore_errors is set, errors are ignored; otherwise, if onerror
    is set, it is called to handle the error with arguments (func,
    path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
    path is the argument to that function that caused it to fail; and
    exc_info is a tuple returned by sys.exc_info().  If ignore_errors
    is false and onerror is None, an exception is raised.

    c          G   s   d  S(   N(    (   RA   (    (    R   t   onerror   s    c          G   s     d  S(   N(    (   RA   (    (    R   RB      s    i    N(   t   ignore_errorsRB   R    R0   R   R/   R   R<   R?   t   syst   exc_infoR3   R-   t   fullnamet   lstatR'   R(   R$   t   S_ISDIRR   t   removet   rmdir(   R   RC   RB   R3   R?   R0   RF   R(   (    (    R   R      s6    
  "c         C   sฃ   y t  i |  |  Wn t j
 o| t  i i |   oH t |  |  o t d |  | f  n t	 |  | d t
 t |   q t |  |  t  i |   n Xd S(   s=  Recursively move a file or directory to another location.

    If the destination is on our current filesystem, then simply use
    rename.  Otherwise, copy src to the dst and then remove src.
    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    s.   Cannot move a directory '%s' into itself '%s'.R6   N(   R   t   renameR   R   R   R   R,   t	   destinsrcR	   R   t   TrueR   R   t   unlink(   R   R   (    (    R   R   ฎ   s     c         C   s   t  |  i t  |    S(   N(   R   R   t
   startswithR   (   R   R   (    (    R   RL   ฤ   s    (   t   __doc__R   RD   R$   t
   exceptionst   os.pathR   t   __all__t   EnvironmentErrorR	   R    R   R   R   R   R   R   R   R   R    R   R   RL   (   R   R   R$   R   R   RS   R   R   R   RD   RL   R   R   R	   RQ   R    R   R   (    (    R   t   ?   s$   				$				
		&(	