ó
ä™xTc           @   s½  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z e j Z d „  Z d „  Z	 d „  Z
 d e d „ Z d „  Z d e d	 „ Z e j d
 k r£ e Z n e Z d „  Z d „  Z d d d „ Z d d d „ Z d d „ Z d „  Z d d „ Z g  g  d „ Z d e f d „  ƒ  YZ d d „ Z d d d „ Z d „  Z d d d d d „ Z d  e f d! „  ƒ  YZ  d" e  f d# „  ƒ  YZ! d$ e  f d% „  ƒ  YZ" d& e f d' „  ƒ  YZ# d( „  Z$ d S()   iÿÿÿÿ(   t   divisionNc          G   s   t  j t  j |  Œ  ƒ S(   N(   t   opt   normpatht   join(   t   args(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt	   norm_join   s    c         C   s   t  j t  j t  j |  ƒ ƒ ƒ S(   N(   R   R   t   realpatht   abspath(   t   path(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   abs_real_norm   s    c         C   s   t  j t  j |  ƒ ƒ S(   N(   R   R   R   (   R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   abs_norm   s    t   .c   	      C   sµ   |  s t  d ƒ ‚ n  d „  } | t j | ƒ ƒ } t j |  ƒ } | | ƒ } t t j | | g ƒ ƒ } | d k r | r | Sd g t | ƒ | | | } | s¨ d St j | Œ  S(   Ns   no path specifiedc         S   s:   g  } x- |  j  d ƒ D] } | r | j | ƒ q q W| S(   Nt   /(   t   splitt   append(   t   apt   resultt   _(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   as_list   s
     i    s   ..R   (   t
   ValueErrorR   R   t   lent   commonprefixR   (	   R   t   startt   enable_abspath_if_through_rootR   t
   start_listt   path_abst	   path_listt   it   rel_list(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   posix_relpath   s    	c         C   sD   t  j |  ƒ \ } } t | ƒ r% t St  j |  ƒ \ } } t | ƒ S(   N(   R   t   splitunct   boolt   Truet
   splitdrive(   R   t   prefixR   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   nt_is_true_abs(   s
     c         C   s¾  |  s t  d ƒ ‚ n  | rC t | ƒ o0 t |  ƒ rC t d ƒ ‚ n  t | ƒ } t |  ƒ } d „  } | | ƒ \ } } } | | ƒ \ }	 }
 } |	 | Ar» | r¢ | St  d |  | f ƒ ‚ n  |
 j ƒ  | j ƒ  k r| rÝ | S|	 rü t  d |
 | f ƒ ‚ qt  d |
 | f ƒ ‚ n  d } xC t | | ƒ D]2 \ } } | j ƒ  | j ƒ  k rSPn  | d 7} q+W| d k rˆ| rˆ|
 d	 d	 j | ƒ Sd
 g t | ƒ | | | } | s±d St j | Œ  S(   Ns   no path specifieds9   nt_relpath(): both path and start must be absolute paths.c         S   s‚   t  j |  ƒ \ } } t | ƒ } | s? t  j |  ƒ \ } } n  g  } x- | j d ƒ D] } | rU | j | ƒ qU qU W| | | f S(   Ns   \(   R   R   R   R!   R   R   (   t   absR"   t   restt   is_unct	   rest_listR   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   _abspath_split<   s     s,   Cannot mix UNC and non-UNC paths (%s and %s)s,   path is on UNC root %s, start on UNC root %ss&   path is on drive %s, start on drive %si    i   s   \s   ..R   (	   R   R#   t   RuntimeErrorR
   t   lowert   zipR   R   R   (   R   R   R   t	   start_absR   R(   t   start_is_unct   start_prefixR   t   path_is_unct   path_prefixR   R   t   e1t   e2R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt
   nt_relpath.   sH    		
t   ntc         C   s   t  j |  j t  j ƒ | Œ  S(   N(   R   R   R   t   sep(   R   t   number_of_levels(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   tail_levelsf   s    c         C   s6   t  j |  ƒ d } t  j | ƒ s2 t j | ƒ n  d  S(   Ni    (   R   R   t   isdirt   ost   makedirs(   t   target_filet
   target_dir(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   create_target_diri   s    R   s   %03dc   
      C   så   t  j |  ƒ s d  St  j |  ƒ | } t  j t  j |  ƒ ƒ } d } xl t j | ƒ D][ } | j | ƒ rT | t | ƒ } y t	 | ƒ } Wn t
 k
 rœ q¯ Xt | | ƒ } qT qT Wt  j | | | | d ƒ }	 t j |  |	 ƒ d  S(   Ni    i   (   R   t   existst   basenamet   dirnameR   R9   t   listdirt
   startswithR   t   intR   t   maxR   t   rename(
   R   t
   serial_sept
   serial_fmtt   bnst   dnt   max_it   ext   sR   t   nn(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   move_oldn   s       c         C   s*   t  d |  d | d | ƒ t j |  ƒ d  S(   NR   RF   RG   (   RN   R9   R:   (   R   RF   RG   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   move_old_create_new_directory|   s    c         C   sp   t  |  t t f ƒ s$ t |  ƒ }  n  t j |  ƒ sc | d  k rN t j ƒ  } n  t j	 | |  ƒ }  n  t j
 |  ƒ S(   N(   t
   isinstancet   strt   unicodeR$   R   t   isabst   NoneR9   t   getcwdR   R   (   t	   file_namet#   effective_current_working_directory(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   canonical_path€   s    c         C   s[   t  |  ƒ d k s t ‚ |  d |  d k r0 t St t d ƒ rW t j |  d |  d ƒ St S(   Ni   i    i   t   samefile(   R   t   AssertionErrorR    t   hasattrR   RY   t   False(   t
   file_names(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   is_same_canoncial_file‰   s     c         C   s&   t  g  |  D] } t | | ƒ ^ q
 ƒ S(   N(   R^   RX   (   R]   RW   RV   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   is_same_file�   s    c         C   sd   | t  j d j t  j ƒ | } x< | D]4 } t j | |  ƒ } t j | ƒ r( t d | ƒ Sq( Wd  S(   Nt   PATHR   (	   R9   t   environR   t   pathsepR   R   R>   R
   RT   (   t   commandt   search_firstt   search_lastt   dirsR   t   path_command(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   full_command_path•   s    !t	   directoryc           B   s)   e  Z d  „  Z e d „ Z e d „ Z RS(   c         C   s   | |  _  d  S(   N(   R   (   t   selfR   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __init__Ÿ   s    c         C   sj   | d  k	 s t ‚ t j |  j | ƒ } | rf t j | ƒ rf d d l m } t d | | ƒ ƒ ‚ n  | S(   Niÿÿÿÿ(   t   show_strings   No such file or directory: %s(	   RT   RZ   R   R   R   R>   t   libtbx.str_utilsRl   R)   (   Rj   t   namet
   must_existR   Rl   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   get¢   s    c         C   s^   t  |  j | ƒ ƒ } | rZ t j | j ƒ rZ d d l m } t d | | j ƒ ƒ ‚ n  | S(   Niÿÿÿÿ(   Rl   s   Not a directory: %s(   Ri   Rp   R   R8   R   Rm   Rl   R)   (   Rj   Rn   Ro   R   Rl   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   sub_directoryª   s
    (   t   __name__t
   __module__Rk   R    Rp   Rq   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRi   �   s   	c         C   s&   d „  } g  } t  j |  | | ƒ | S(   Nc            së   g  } x² | D]ª } t  j | | ƒ ‰  t  j ˆ  ƒ sY | j d ƒ s |  j ˆ  ƒ q q n  ‡  f d †  } | d k r€ | d ƒ s | d k rª | d ƒ s | d ƒ rª q n  | j | ƒ q Wt | ƒ t | ƒ k rç | 2| j | ƒ n  d  S(   Ns   .pycc            s   t  j t  j ˆ  |  ƒ ƒ S(   N(   R   t   isfileR   (   Rn   (   R   (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   is_file_in_subdirº   s    t   CVSt   Entriess   .svns
   README.txtt   entries(   R   R   R8   t   endswithR   R   t   extend(   R   R@   t   namest
   names_keepRn   Ru   (    (   R   s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   visitor²   s"    (   R   t   walk(   t   topt   argR}   R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   walk_source_tree±   s    	t   tmp_dir_i   c         C   sW   d d l  m } x@ t d ƒ D], } |  | d | ƒ } t j | ƒ s | Sq Wt ‚ d  S(   Niÿÿÿÿ(   t   random_hex_codei
   i   t   number_of_digitsi@B (   t   libtbx.utilsRƒ   t   xrangeR   R>   RZ   (   R"   t   number_of_hex_code_digitsRƒ   t   i_trialRn   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   random_new_directory_nameÉ   s    c         C   sM   y t  j |  ƒ Wn5 t k
 rH } d d l m } | t | ƒ ƒ ‚ n Xd S(   sJ   
  Wrapper for os.makedirs that catches OSError and re-raises as Sorry.
  iÿÿÿÿ(   t   SorryN(   R9   R:   t   OSErrorR…   RŠ   RQ   (   R   t   eRŠ   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR:   Ò   s
    i
   gü©ñÒMbP?g      à?c         C   sÑ   |  d  k r t ƒ  }  n  d d  l } x„ t | ƒ D]v } t j |  ƒ rf | d  k	 rb | j | ƒ n  Pn  y t j |  ƒ Wq1 t	 k
 r¦ | d  k	 r§ | j | ƒ q§ q1 Xq1 Wt j
 |  ƒ sÍ t d |  ƒ ‚ n  |  S(   Niÿÿÿÿs   makedirs_race(%s) failure.(   RT   R‰   t   timeR†   R   R>   t   sleepR9   R:   t	   ExceptionR8   R)   (   R   t
   max_trialst   delay_if_existst   delay_after_exceptionR�   Rˆ   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   makedirs_raceÜ   s     t
   path_mixinc           B   s°   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z RS(   c         C   s   |  j  | ƒ S(   N(   t   __div__(   Rj   R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __truediv__ö   s    c         C   s   t  j t |  ƒ ƒ S(   N(   R   R8   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR8   ù   s    c         C   s   t  j t |  ƒ ƒ S(   N(   R   Rt   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRt   ü   s    c         C   s   t  j t |  ƒ ƒ S(   N(   R   R>   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR>   ÿ   s    c         O   s   t  t |  ƒ | | Ž S(   N(   t   openR$   (   Rj   R   t   kwds(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR—     s    c         C   s   t  j t |  ƒ ƒ d  S(   N(   R9   R:   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR:     s    c         C   s9   |  j  ƒ  r" t j t |  ƒ ƒ n  |  j  ƒ  s5 t ‚ d  S(   N(   R>   R9   t   removeR$   RZ   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR™     s     c         C   s=   d d l  m } |  j ƒ  r/ | t |  ƒ ƒ n
 |  j ƒ  d  S(   Niÿÿÿÿ(   t   remove_tree(   t   distutils.dir_utilRš   R8   R$   R™   (   Rj   Rš   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRš     s    c         C   s   t  j t |  ƒ ƒ S(   N(   R9   RA   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRA     s    c         O   s   t  j t |  ƒ | | Ž S(   N(   R9   t   chmodR$   (   Rj   R   R˜   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRœ     s    c         O   s   t  j t |  ƒ | | Ž S(   N(   R9   t   accessR$   (   Rj   R   R˜   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR�     s    c         C   s   t  j t |  ƒ ƒ S(   N(   R   R?   R$   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR?     s    c         C   s   t  j |  j ƒ  ƒ d S(   Ni   (   R   t   splitextR?   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   ext  s    c         C   s   |  j  ƒ  |  j ƒ  f S(   N(   R@   R?   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR   "  s    c         C   sT   t  | t ƒ s t  | t ƒ r4 t j t |  ƒ | ƒ St j t |  ƒ t | ƒ ƒ Sd  S(   N(   RP   RQ   RR   R   RY   R$   (   Rj   t   other(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRY   %  s    c         C   s   t  |  t ƒ S(   N(   RP   t   relocatable_path(   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   is_relocatable+  s    t   LIBTBX_BUILDc         C   s-   |  j  ƒ  r# t j d | |  j ƒ St |  ƒ S(   Ns   $%s(   R¢   R   R   t   relocatableR$   (   Rj   t
   anchor_var(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   sh_value.  s    c         C   s-   |  j  ƒ  r# t j d | |  j ƒ St |  ƒ S(   Ns   %%%s%%(   R¢   R   R   R¤   R$   (   Rj   R¥   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt	   bat_value3  s    (   Rr   Rs   R–   R8   Rt   R>   R—   R:   R™   Rš   RA   Rœ   R�   R?   RŸ   R   RY   R¢   R¦   R§   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR”   ô   s$   																t   absolute_pathc           B   sM   e  Z e d  „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   sI   t  j | ƒ s t ‚ | s- t  j | ƒ } n  t  j | ƒ } | |  _ d  S(   N(   R   RS   RZ   t   normcaseR   t   _path(   Rj   R   t   case_sensitive(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRk   ;  s
    c         C   s   t  | | ƒ j |  _ d  S(   N(   R¨   Rª   (   Rj   t   new_pathR«   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   resetB  s    c         C   s   t  t j |  j | ƒ ƒ S(   N(   R¨   R   R   Rª   (   Rj   R    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR•   E  s    c         C   s   |  j  S(   N(   Rª   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __abs__H  s    c         C   s   t  |  j | ƒ S(   N(   R¨   Rª   (   Rj   RŸ   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __add__K  s    c         C   s   d |  j  S(   Ns   absolute_path("%s")(   Rª   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __repr__N  s    c         C   s   t  t j |  j ƒ ƒ S(   N(   R¨   R   R@   Rª   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR@   Q  s    (
   Rr   Rs   R\   Rk   R­   R•   R®   R¯   R°   R@   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR¨   9  s   				R¡   c           B   s€   e  Z d  „  Z d „  Z e e ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z RS(   c         C   s   t  | t ƒ s t ‚ | |  _ t j | ƒ rr t d t j t t | ƒ ƒ ƒ d t j t |  j ƒ ƒ d t	 ƒ } n  | |  _
 d  S(   NR   R   R   (   RP   R¨   RZ   t   _anchorR   RS   t   relpathR   R$   R    R¤   (   Rj   t   anchorR¤   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRk   W  s    	c         C   s   |  j  S(   N(   R±   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR³   a  s    c         C   s   t  |  j t j |  j | ƒ ƒ S(   N(   R¡   R±   R   R   R¤   (   Rj   R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR•   e  s    c         C   s   t  j |  j | ƒ |  _ |  S(   N(   R   R   R¤   (   Rj   R   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __idiv__h  s    c         C   s   t  |  j |  j | ƒ S(   N(   R¡   R±   R¤   (   Rj   RŸ   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR¯   l  s    c         C   s   | r t  |  ƒ S|  Sd  S(   N(   R$   (   Rj   t   flag(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   self_or_abs_ifo  s    
c         C   s%   t  j t  j t |  j ƒ |  j ƒ ƒ S(   N(   R   R   R   R$   R³   R¤   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR®   u  s    c         C   s   d t  |  j ƒ |  j f S(   Ns/   relocatable_path(anchor="%s", relocatable="%s")(   R$   R³   R¤   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR°   x  s    c         C   s+   |  j  s t ‚ t |  j t j |  j  ƒ ƒ S(   N(   R¤   RZ   R¡   R±   R   R@   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR@   |  s    c         C   s   t  j |  j ƒ S(   N(   R   R?   R¤   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR?   €  s    c         C   s   t  |  j t j |  j ƒ ƒ S(   N(   R¡   R±   R   R©   R¤   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR©   ƒ  s    c         C   s"   |  j  | j  k o! |  j | j k S(   N(   R±   R¤   (   Rj   R    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   __eq__†  s    (   Rr   Rs   Rk   R³   t   propertyR•   R´   R¯   R¶   R®   R°   R@   R?   R©   R·   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR¡   U  s   	
										t   clean_out_directoryc           B   sn   e  Z d  Z e e e e e d „ Z d „  Z d „  Z e d „  ƒ Z e	 j
 d „ Z d „  Z e	 j
 d „ Z RS(   sß   
  Utility for cleaning out Phenix (etc.) project folders, which tend to
  accumulate large amounts of temporary files and other large objects (CCP4
  maps, .geo files, etc.) which we may not want to keep around forever.
  c         C   sØ  | |  _  d |  _ |  _ |  _ g  |  _ g  |  _ xŸt j | ƒ D]Ž\ } } }	 t j j	 | ƒ }
 |
 j
 d ƒ d } | d k rÉ d | k r4| r4| j d ƒ t j j | d ƒ } |  j | ƒ q4nk | d k r"d
 | k r4| r4| r4| j d
 ƒ t j j | d
 ƒ } |  j | ƒ q4n | d k r4qB n  x™ |	 D]‘ } t j j | | ƒ } | j d ƒ rk| s¼| j d ƒ r€| s¼| j d ƒ r•| s¼| j d ƒ rª| s¼| d k r;| r;|  j | ƒ q;q;WqB Wd  S(   Ni    R   t   AutoSolt	   AutoBuildt   AutoMRt	   LigandFitt   StructureComparisont   TEMP0t   Refines   .commt   FFTt   SuperposeMapss   .kins   .geos   .ccp4s   .xplors	   probe.txt(   Rº   R»   R¼   R½   R¾   (   RÀ   (   RÁ   RÂ   (   t	   path_namet   n_filest   n_dirst   n_bytest
   file_pathst	   dir_pathsR9   R~   R   R?   R   R™   R   t   delete_directoryRy   t   delete_file(   Rj   RÃ   t   delete_kin_filest   delete_geo_filest   delete_map_filest   delete_temp_dirst   delete_probe_filesR@   t   dirnamest	   filenamest   base_dirt   base_dir_namet	   full_pathRV   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRk   �  s8    				c         C   sT   t  j j | ƒ s d  S|  j t  j j | ƒ 7_ |  j j | ƒ |  j d 7_ d  S(   Ni   (   R9   R   Rt   RÆ   t   getsizeRÇ   R   RÄ   (   Rj   RV   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRÊ   µ  s
     c         C   s8   |  j  t | ƒ 7_  |  j j | ƒ |  j d 7_ d  S(   Ni   (   RÆ   t   directory_sizeRÈ   R   RÅ   (   Rj   t   dir_name(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRÉ   »  s    c         C   s   |  j  |  j S(   N(   RÅ   RÄ   (   Rj   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   n_totalÀ  s    c         C   s`   |  j  d | ƒ | d IJx |  j D] } t j | ƒ q$ Wx |  j D] } t j | ƒ qE Wd  S(   Nt   outs.   Deleting all selected files and directories...(   t   showRÇ   R9   R™   RÈ   t   shutilt   rmtree(   Rj   RÙ   RV   R×   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   runÄ  s    
c         C   sh   t  j t  j d ƒ |  j d } | d k rJ t  j d | d d t ƒd St  j d | d t ƒd Sd  S(   Nt   en_USiè  i'  s   %.1ft   groupings    MBs    KB(   t   localet	   setlocalet   LC_ALLRÆ   t   formatR    (   Rj   t   n_kb(    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   get_freed_spaceÌ  s
    c         C   sÀ   |  j  d k rK | d |  j  IJx( t |  j ƒ D] } | d | IJq0 Wn  |  j d k r– | d |  j IJx( t |  j ƒ D] } | d | IJq{ Wn  |  j d k r¼ | d |  j ƒ  IJn  d  S(   Ni    s*   The following %d directories will deleted:s     %ss'   The following %d files will be deleted:s   %s of disk space will be freed.(   RÅ   t   sortedRÈ   RÄ   RÇ   RÆ   Rå   (   Rj   RÙ   R×   RV   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRÚ   Ô  s    

(   Rr   Rs   t   __doc__R    Rk   RÊ   RÉ   R¸   RØ   t   syst   stdoutRÝ   Rå   RÚ   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyR¹   Š  s   			c   	      C   s¸   d } t  ƒ  } x¢ t j |  ƒ D]‘ \ } } } x | D]w } t j j | | ƒ } y t j | ƒ } Wn t k
 ry q5 n X| j | k r� q5 n  | j | j ƒ | | j	 7} q5 Wq W| S(   Ni    (
   t   setR9   R~   R   R   t   statR‹   t   st_inot   addt   st_size(	   R   t
   total_sizet   seent   dirpathRÐ   RÑ   t   ft   fpRë   (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyRÖ   ã  s    	(%   t
   __future__R    Rà   RÛ   R9   Rè   R   R   R   R	   R
   R\   R   R#   R3   Rn   R²   R7   R=   RN   RO   RT   RX   R^   R_   Rh   t   objectRi   R�   R‰   R:   R“   R”   R¨   R¡   R¹   RÖ   (    (    (    s9   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/path.pyt   <module>   sJ   					0							E5Y