ó
@æjfc           @   sŒ   d  d l  Z  d  d l Z d  d l m Z e j d ƒ Z e d d d „ Z d d d d d „ Z	 d d d d d „ Z
 d „  Z e d „ Z d S(	   iÿÿÿÿN(   t   settingssa   (?P<source_filename>.+)_(?P<x>\d+)x(?P<y>\d+)(?:_(?P<options>\w+))?_q(?P<quality>\d+)(?:.[^.]+)?$c         C   se  | d	 k r t j } n  | d	 k r0 t j } n  i  } |  j d ƒ sR d |  }  n  t |  ƒ } | rv t j |  ƒ } nc g  } xH t j |  ƒ D]7 } t j	 j
 t j	 j |  | ƒ ƒ rŒ | j | ƒ qŒ qŒ W|  g  | f g } x…| D]}\ }	 }
 } |	 | } xa| D]Y} t j | ƒ } | s!q n  | j ƒ  } | j d ƒ } | r‘t j	 j | ƒ \ } } | j | ƒ soq n  t j	 j | | t | ƒ ƒ } n  | d r®| d j d ƒ p±g  | d <| rá| j | ƒ rá| t | ƒ  } n  t j d | ƒ } | rd | j ƒ  } n  t j	 j | | ƒ } | j | g  ƒ } t j	 j |	 | ƒ | d <| j | ƒ q Wqà W| S(
   sá   
    Return a dictionary referencing all files which match the thumbnail format.

    Each key is a source image filename, relative to path.
    Each value is a list of dictionaries as explained in `thumbnails_for_file`.
    t   /s   %s/t   source_filenamet   optionst   _s	   (.*)_(.*)s   %s.%st   filenameN(   t   NoneR    t   THUMBNAIL_PREFIXt   THUMBNAIL_SUBDIRt   endswitht   lent   ost   walkt   listdirt   patht   isfilet   joint   appendt   re_thumbnail_filet   matcht	   groupdictt   popt   splitt
   startswitht   ret   groupst
   setdefault(   R   t	   recursivet   prefixt   subdirt   thumbnail_filest   len_patht   allt   filest   filet   dir_t   subdirst   rel_dirt   thumbt   dR   t   source_patht   mR   t   thumbnail_file(    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyt   all_thumbnails   sP    !
	'c   	      C   s×   | d k r t j } n  | d k r0 t j } n  | d k rH t j } n  | d k r` t j } n  t j j |  ƒ \ } } t j j	 | | | | ƒ } t j j
 | ƒ s© g  St | d t d | d d ƒ} | j | g  ƒ S(   sl  
    Return a list of dictionaries, one for each thumbnail belonging to the
    source image.

    The following list explains each key of the dictionary:

      `filename`  -- absolute thumbnail path
      `x` and `y` -- the size of the thumbnail
      `options`   -- list of options for this thumbnail
      `quality`   -- quality setting for this thumbnail
    R   R   R   t    N(   R   R    t
   MEDIA_ROOTR   R   t   THUMBNAIL_BASEDIRR   R   R   R   t   isdirR+   t   Falset   get(	   t   relative_source_patht   roott   basedirR   R   t
   source_dirR   t   thumbs_pathR!   (    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyt   thumbnails_for_file@   s    	c         C   s"   t  |  | | | | ƒ } t | ƒ S(   s3   
    Delete all thumbnails for a source image.
    (   R7   t   _delete_using_thumbs_list(   R2   R3   R4   R   R   t   thumbs(    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyt   delete_thumbnails^   s    	c         C   sJ   d } x= |  D]5 } | d } y t  j | ƒ Wn q X| d 7} q W| S(   Ni    R   i   (   R   t   remove(   R9   t   deletedt
   thumb_dictR   (    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyR8   h   s    
c         C   s=   d } x0 t  |  d | ƒj ƒ  D] } | t | ƒ 7} q W| S(   sØ   
    Delete all files within a path which match the thumbnails pattern.

    By default, matching files from all sub-directories are also removed. To
    only remove from the path directory, set recursive=False.
    i    R   (   R+   t   valuesR8   (   R   R   t   totalR9   (    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyt   delete_all_thumbnailsu   s    (   R   R   t   easy_thumbnails.confR    t   compileR   t   TrueR   R+   R7   R:   R8   R@   (    (    (    sA   /var/www/svtgbi.org/svtgbi/easy_thumbnails/management/__init__.pyt   <module>   s   5		