ó
Ò¬Qc           @   s  d  Z  d d l m Z e d d d ƒd d l m Z d d l m Z m Z d d l Z d d l Z d d l	 Z	 y e	 j
 Z
 Wn e k
 r– e Z
 n Xd	 Z d
 Z e j e j Be j Be j Be j BZ d d „ Z d „  Z d „  Z d „  Z d d d d „ Z d d „ Z d S(   s¢   macostools - Various utility functions for MacOS.

mkalias(src, dst) - Create a finder alias 'dst' pointing to 'src'
copy(src, dst) - Full copy of 'src' to 'dst'
iÿÿÿÿ(   t   warnpy3ks)   In 3.x, the macostools module is removed.t
   stackleveli   (   t   Res(   t   Filet   FilesNs   macostools.Errori   c         C   s  t  j |  ƒ } t j j | ƒ \ } } | s9 t j } n  t  j | ƒ } | rr t  j | ƒ } t  j | | ƒ } n | j ƒ  } t j	 | t
 | ƒ t  j ƒ  ƒ \ }	 }
 t j |	 t  j ƒ  d ƒ } t j | j ƒ } | j d d d ƒ t j | ƒ |
 j ƒ  } | j d B| _ |
 j | ƒ d S(   s   Create a finder aliasi   t   alisi    t    i €  N(   R   t   FSReft   ost   patht   splitt   curdirt
   FSNewAliast   FSNewAliasMinimalR   t   FSCreateResourceFilet   unicodet   FSGetResourceForkNamet   FSOpenResourceFilet   Resourcet   datat   AddResourcet   CloseResFilet   FSpGetFInfot   Flagst   FSpSetFInfo(   t   srct   dstt   relativet   srcfsrt   dstdirt   dstnamet	   dstdirfsrt   relativefsrt   aliast   dstfsrt   dstfsst   ht   resourcet   dstfinfo(    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyt   mkalias    s$     c         C   s²   |  d k s t  j j |  ƒ r" d St  j j |  ƒ \ } } t  j d k rb d | k rb | d } n  t | ƒ y t  j |  d ƒ Wn+ t k
 r­ } | j t j	 k r® ‚  q® n Xd S(   s9   Make directories leading to 'dst' if they don't exist yetR   Nt   :iÿ  (
   R   R	   t   existsR
   t   sept   mkdirst   mkdirt   OSErrort   errnot   EEXIST(   R   t   headt   tailt   e(    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyR+   :   s    
c         C   s#   d d l  } | j d t d ƒ d S(   s4   Tell the finder a file has changed. No-op on MacOSX.iÿÿÿÿNs(   macostools.touched() has been deprecatedi   (   t   warningst   warnt   DeprecationWarning(   R   R3   (    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyt   touchedK   s    	c         C   sZ   t  j j |  ƒ d } | s( t  j } n  d d l } | j ƒ  } | j t j | ƒ ƒ d S(   s"   Tell the finder a file has changedi    iÿÿÿÿN(   R   R	   R
   R   t   Findert   updateR   R   (   R   t   pardirR7   t   f(    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyt
   touched_aeQ   s    i    i   c         C   sõ  t  j |  ƒ }  t  j | ƒ } | rA t t j j | ƒ d ƒ n  t |  d ƒ } t | d ƒ } | j t ƒ } x& | r– | j	 | ƒ | j t ƒ } qq W| j
 ƒ  | j
 ƒ  t |  d ƒ } t | d ƒ } | j t ƒ } x& | r | j	 | ƒ | j t ƒ } qÛ W| j
 ƒ  | j
 ƒ  t  j |  ƒ } t  j | ƒ }	 | j ƒ  }
 |	 j ƒ  } |
 j |
 j | _ | _ | d k	 r|| | _ n  |
 j t @| _ |	 j | ƒ | rñt  j |  ƒ } t  j | ƒ } | j t j ƒ \ } } } } | j t j | ƒ n  d S(   s6   Copy a file, including finder info, resource fork, etci    t   rbt   wbs   *rbs   *wbN(   R   t   pathnameR+   R   R	   R
   t   opent   readt   BUFSIZt   writet   closet   openrft   FSSpecR   t   Creatort   Typet   NoneR   t
   COPY_FLAGSR   R   t   FSGetCatalogInfoR   t   kFSCatInfoAllDatest   FSSetCatalogInfo(   R   R   t
   createpatht	   copydatest	   forcetypet   ifpt   ofpt   dt   srcfssR#   t   sft   dfR   R"   t   catinfot   _(    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyt   copyZ   sD    	

	

c         C   s„   t  j j |  ƒ rm t | ƒ t  j |  ƒ } xR | D]4 } t t  j j |  | ƒ t  j j | | ƒ | ƒ q2 Wn t |  | d | ƒ d S(   s.   Copy a complete file tree to a new destinationi   N(   R   R	   t   isdirR+   t   listdirt   copytreet   joinRX   (   R   R   RN   t   filesR:   (    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyR[   ‚   s    
5(   t   __doc__R3   R    t   CarbonR   R   R   R   R.   t   MacOSRD   t   AttributeErrorR?   t   ErrorRA   t   kIsStationaryt   kNameLockedt
   kHasBundlet   kIsInvisiblet   kIsAliasRI   RH   R'   R+   R6   R;   RX   R[   (    (    (    s@   /Users/tom/newbuild/install/lib/python2.7/plat-mac/macostools.pyt   <module>   s(   
%				(