ó
î7­Wc           @   s_  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z e j d ƒ Z	 d Z
 e j d ƒ Z e Z y d d l Z Wn$ e k
 rº e j d ƒ e Z n Xd e f d „  ƒ  YZ d	 „  Z e d
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! e e d d d d „ Z# d S(   sw   
Library and helper functions for the delete(1) suite of tools, including
delete, expunge, lsdel, purge, and undelete.
iÿÿÿÿNs   ([*?[])i   t	   libdeletes   AFS support unavailablet   DeleteErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyR      s   c            s)   ‡  ‡ f d †  t  d t ˆ  ƒ ˆ ƒ Dƒ S(   s.   
    Break a sequence up into size chunks
    c         3   s    |  ] } ˆ  | | ˆ !Vq d  S(   N(    (   t   .0t   pos(   t   seqt   size(    s-   /usr/lib/python2.7/dist-packages/libdelete.pys	   <genexpr>!   s    i    (   t   xranget   len(   R   R   (    (   R   R   s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   chunks   s    iP   c            sÎ   | r d j  |  ƒ St |  ƒ d k  r) d St d „  |  Dƒ ƒ d ‰  ˆ  | k r\ d j  |  ƒ S| ˆ  } d | ˆ  | ‰ g  } x@ t |  | ƒ D]/ } | j d j  ‡  ‡ f d †  | Dƒ ƒ ƒ qŽ Wd j  | ƒ S(   sL   
    Pretty-print in optional multi-column format, with padding/spread.
    s   
i   t    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R	   (   R   t   x(    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pys	   <genexpr>-   s    i   iP   c         3   s"   |  ] } | j  ˆ  ˆ ƒ Vq d  S(   N(   t   ljust(   R   t   item(   t	   col_widtht   padding(    s-   /usr/lib/python2.7/dist-packages/libdelete.pys	   <genexpr>4   s    (   t   joinR	   t   maxR
   t   append(   t   itemst	   singlecolt   widtht   n_colst   rvt   c(    (   R   R   s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   format_columns#   s    
-c         C   s‘   t  j j |  ƒ r t St r t j j t  j j |  ƒ ƒ r t j j	 |  ƒ y t j j
 |  ƒ d  k	 SWq t k
 r‰ } t j d | ƒ q Xn  t S(   Ns,   Got exception while checking mount point: %s(   t   ost   patht   ismountt   Truet   have_AFSt   afst   fst   inafst   abspatht	   whichcellt   lsmountt   Nonet   OSErrort   loggert   debugt   False(   R   t   e(    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   is_mountpoint7   s    $c         C   s   t  j |  ƒ d  k	 S(   N(   t   WILDCARDS_REt   searchR&   (   t   string(    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   has_wildcardsB   s    c         C   s   t  j j |  ƒ j d ƒ S(   sA   
    Return True if the file has been 'deleted' by delete(1)
    s   .#(   R   R   t   basenamet
   startswith(   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt
   is_deletedE   s    c         C   s/   g  t  j |  ƒ D] } t  j j |  | ƒ ^ q S(   s1   
    A directory listing with the full path.
    (   R   t   listdirR   R   (   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   dir_listingK   s    c         C   s   t  d „  t |  ƒ Dƒ ƒ S(   sd   
    Return True if the directory is "empty" (that is, any entries
    in it have been deleted)
    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R3   (   R   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pys	   <genexpr>V   s    (   t   allR5   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   empty_directoryQ   s    c         C   s   |  j  d ƒ r |  d S|  S(   sR   
    For relative paths that begin with '.', strip off the leading
    stuff.
    s   ./i   (   R2   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   relpathX   s    c         C   sL   t  j j |  ƒ } | d j d ƒ rD t  j j | d | d d ƒ S|  Sd S(   sÈ   
    Return the undeleted name of a file.  Only the last component
    is changed.  If it's in a chain of deleted directories, those
    are still printed with the leading '.#' for compatibility.
    i   s   .#i    i   N(   R   R   t   splitR2   R   (   R   t   parts(    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   undeleted_name_   s
    c         C   sh   | d k  r t  d ƒ ‚ n  | d k r+ t St j j |  ƒ } t j d |  | ƒ t j ƒ  | d | k S(   Ni    s   n must not be negatives   %s modified %d sec agoi€Q (   t
   ValueErrorR   R   R   t   getmtimeR(   R)   t   time(   R   t   nt   mtime(    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt
   n_days_oldl   s    c         C   s   t  j d |  ƒ S(   Ns   [\1](   R-   t   sub(   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   escape_metav   s    c         C   s   t  t t |  ƒ t ƒ ƒ S(   N(   t   intt   roundt   floatt   KILO(   R   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   to_kby   s    i    c         C   s«  t  j d |  | | | | | ƒ g  } t j |  ƒ t j d |  ƒ } t | ƒ d k r t d j |  t |  ƒ ru d n t j t	 j
 ƒ ƒ ƒ ‚ n  x| D]} t  j d | ƒ t j j | ƒ rt  j d | ƒ t j j | ƒ rþ | rþ t  j d | ƒ q— n  t | ƒ r'| r't  j d	 | ƒ q— n  t | ƒ r?| t k sXt | ƒ r| t k rt  j d
 t | ƒ ssd n d | ƒ yd x] t | ƒ D]O }	 | t t |	 ƒ | | | d  k rºt n | | d  k rÏt n | | ƒ 7} qWWqt k
 r}
 t d d |
 j d |
 j ƒqXqn  t | ƒ r— y, t | | ƒ sPt  j d | | ƒ w— n  Wn/ t k
 r‚}
 t d d |
 j d |
 j ƒn Xt  j d | ƒ | j | ƒ q— q— W| S(   NsT   find_deleted_files(%s, links=%s, mounts=%s, recurse_un=%s, recurse_del=%s, ndays=%s)s   .#i    s   {0}: {1}s   No matchs   Examining %ss   %s is a directorys   Skipping symlink: %ss   Skipping mountpoint: %ss&   Recursing into %sdeleted directory: %st   unR   s   {filename}: {error}t   filenamet   errors   %s is not %d days old, skippings&   {filename}: {error} while checking ages
   Adding: %s(   R(   R)   t   globR	   R   t   formatR0   R   t   strerrort   errnot   ENOENTR   t   isdirt   islinkR,   R3   R*   R5   t   find_deleted_filesRC   R&   R'   t   perrorRJ   RA   R   (   t   file_or_patternt   follow_linkst   follow_mountst   recurse_undeleted_subdirst   recurse_deleted_subdirst   n_daysR   t	   file_listRJ   R   R+   (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyRS   |   sX    	
 -		

	($   t   __doc__RO   RL   t   loggingR   t   ret   syst   statt   compileR-   RG   t	   getLoggerR(   R   R   t   afs.fsR    t   ImportErrort   warnR*   t	   ExceptionR   R
   R   R,   R0   R3   R5   R7   R8   R;   RA   RC   RH   R&   RS   (    (    (    s-   /usr/lib/python2.7/dist-packages/libdelete.pyt   <module>   s@   
									
		