ó
è¾bc           @   s–   d  Z  d Z d d l Z d d l m Z d d l m Z i d d 6d d 6d	 d
 6Z d d „ Z	 d d d d d d d „ Z
 d d d „ Z d „  Z d S(   sF   distutils.file_util

Utility functions for operating on single files.
s   $Id$iÿÿÿÿN(   t   DistutilsFileError(   t   logt   copyings   hard linkingt   hards   symbolically linkingt   symi   i   c         C   sÈ  d } d } zŽy t |  d ƒ } Wn2 t j k
 rV \ } } t d |  | f ƒ ‚ n Xt j j | ƒ r² y t j | ƒ Wq² t j k
 r® \ } } t d | | f ƒ ‚ q² Xn  y t | d ƒ } Wn2 t j k
 rù \ } } t d | | f ƒ ‚ n Xxœ y | j | ƒ } Wn2 t j k
 rD\ } } t d |  | f ƒ ‚ n X| sOPn  y | j	 | ƒ Wqý t j k
 r”\ } } t d | | f ƒ ‚ qý Xqý WWd | r°| j
 ƒ  n  | rÃ| j
 ƒ  n  Xd S(	   s5  Copy the file 'src' to 'dst'.

    Both must be filenames. Any error opening either file, reading from
    'src', or writing to 'dst', raises DistutilsFileError.  Data is
    read/written in chunks of 'buffer_size' bytes (default 16k).  No attempt
    is made to handle anything apart from regular files.
    t   rbs   could not open '%s': %ss   could not delete '%s': %st   wbs   could not create '%s': %ss   could not read from '%s': %ss   could not write to '%s': %sN(   t   Nonet   opent   ost   errorR    t   patht   existst   unlinkt   readt   writet   close(   t   srct   dstt   buffer_sizet   fsrct   fdstt   errnot   errstrt   buf(    (    s)   /usr/lib/python2.7/distutils/file_util.pyt   _copy_file_contents   sF    
i   i    c         C   sÂ  d d l  m } d d l m }	 m }
 m } m } t j j	 |  ƒ sW t
 d |  ƒ ‚ n  t j j | ƒ r“ | } t j j | t j j |  ƒ ƒ } n t j j | ƒ } | rä | |  | ƒ rä | d k rÚ t j d |  ƒ n  | d f Sy t | } Wn! t k
 rt d | ƒ ‚ n X| d k rxt j j | ƒ t j j |  ƒ k r_t j d	 | |  | ƒ qxt j d	 | |  | ƒ n  | rˆ| d f S| d
 k rót j j | ƒ o¸t j j |  | ƒ sCy t j |  | ƒ | d f SWqðt k
 rìqðXqCnP | d k rCt j j | ƒ o#t j j |  | ƒ sCt j |  | ƒ | d f Sn  t |  | ƒ | s\| r¸t j |  ƒ } | r’t j | | |	 | |
 f ƒ n  | r¸t j | | | | ƒ ƒ q¸n  | d f S(   s  Copy a file 'src' to 'dst'.

    If 'dst' is a directory, then 'src' is copied there with the same name;
    otherwise, it must be a filename.  (If the file exists, it will be
    ruthlessly clobbered.)  If 'preserve_mode' is true (the default),
    the file's mode (type and permission bits, or whatever is analogous on
    the current platform) is copied.  If 'preserve_times' is true (the
    default), the last-modified and last-access times are copied as well.
    If 'update' is true, 'src' will only be copied if 'dst' does not exist,
    or if 'dst' does exist but is older than 'src'.

    'link' allows you to make hard links (os.link) or symbolic links
    (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
    None (the default), files are copied.  Don't set 'link' on systems that
    don't support it: 'copy_file()' doesn't check if hard or symbolic
    linking is available. If hardlink fails, falls back to
    _copy_file_contents().

    Under Mac OS, uses the native file copy function in macostools; on
    other systems, uses '_copy_file_contents()' to copy file contents.

    Return a tuple (dest_name, copied): 'dest_name' is the actual name of
    the output file, and 'copied' is true if the file was copied (or would
    have been copied, if 'dry_run' true).
    iÿÿÿÿ(   t   newer(   t   ST_ATIMEt   ST_MTIMEt   ST_MODEt   S_IMODEs4   can't copy '%s': doesn't exist or not a regular filei   s"   not copying %s (output up-to-date)i    s&   invalid value '%s' for 'link' arguments   %s %s -> %sR   R   (   t   distutils.dep_utilR   t   statR   R   R   R   R	   R   t   isfileR    t   isdirt   joint   basenamet   dirnameR   t   debugt   _copy_actiont   KeyErrort
   ValueErrort   infoR   t   samefilet   linkt   OSErrort   symlinkR   t   utimet   chmod(   R   R   t   preserve_modet   preserve_timest   updateR,   t   verboset   dry_runR   R   R   R   R   t   dirt   actiont   st(    (    s)   /usr/lib/python2.7/distutils/file_util.pyt	   copy_fileG   sT    ""$
$
'
'! c         C   sû  d d l  m } m } m } m } m } d d l }	 | d k rV t j d |  | ƒ n  | r` | S| |  ƒ s t	 d |  ƒ ‚ n  | | ƒ r© t
 j j | | |  ƒ ƒ } n% | | ƒ rÎ t	 d |  | f ƒ ‚ n  | | | ƒ ƒ sù t	 d |  | f ƒ ‚ n  d	 }
 y t
 j |  | ƒ WnM t
 j k
 rb\ } } | |	 j k rFd }
 qct	 d
 |  | | f ƒ ‚ n X|
 r÷t |  | d | ƒy t
 j |  ƒ Wq÷t
 j k
 ró\ } } y t
 j | ƒ Wn t
 j k
 rÏn Xt	 d d |  | |  | f ƒ ‚ q÷Xn  | S(   s)  Move a file 'src' to 'dst'.

    If 'dst' is a directory, the file will be moved into it with the same
    name; otherwise, 'src' is just renamed to 'dst'.  Return the new
    full name of the file.

    Handles cross-device moves on Unix using 'copy_file()'.  What about
    other systems???
    iÿÿÿÿ(   R   R!   R"   R$   R%   Ni   s   moving %s -> %ss#   can't move '%s': not a regular files0   can't move '%s': destination '%s' already existss2   can't move '%s': destination '%s' not a valid pathi    s   couldn't move '%s' to '%s': %sR4   s+   couldn't move '%s' to '%s' by copy/delete: s   delete '%s' failed: %s(   t   os.pathR   R!   R"   R$   R%   R   R   R*   R    R	   R   R#   t   renameR
   t   EXDEVR9   R   (   R   R   R4   R5   R   R!   R"   R$   R%   R   t   copy_itt   numt   msg(    (    s)   /usr/lib/python2.7/distutils/file_util.pyt	   move_fileª   sP    
(	c         C   sG   t  |  d ƒ } z& x | D] } | j | d ƒ q WWd | j ƒ  Xd S(   s{   Create a file with the specified name and write 'contents' (a
    sequence of strings without line terminators) to it.
    t   ws   
N(   R   R   R   (   t   filenamet   contentst   ft   line(    (    s)   /usr/lib/python2.7/distutils/file_util.pyt
   write_fileæ   s
    i @  (   t   __doc__t   __revision__R	   t   distutils.errorsR    t	   distutilsR   R   R'   R   R9   R@   RF   (    (    (    s)   /usr/lib/python2.7/distutils/file_util.pyt   <module>   s   

5	b<