
    h                     r    d dl Z d dlZd dlmZ  ej                  d      Zd	dZ	 	 d
dZ	 	 d
dZd Z	ddZ
y)    N)settingsza(?P<source_filename>.+)_(?P<x>\d+)x(?P<y>\d+)(?:_(?P<options>\w+))?_q(?P<quality>\d+)(?:.[^.]+)?$c           	         |t         j                  }|t         j                  }i }| j                  d      sd| z  } t	        |       }|rt        j                  |       }nqg }t        j                  |       D ]Q  }t
        j                  j                  t
        j                  j                  | |            sA|j                  |       S | g |fg}|D ]  \  }	}
}|	|d }|D ]s  }t        j                  |      }|s|j                         }|j                  d      }|r`t
        j                  j!                  |      \  }}|j#                  |      sst
        j                  j                  ||t	        |      d       }|d   xr |d   j!                  d      xs g |d<   |r |j                  |      r|dt	        |        }t%        j                  d|      }|rd|j'                         z  }t
        j                  j                  ||      }|j)                  |g       }t
        j                  j                  |	|      |d	<   |j                  |       v  |S )
z
    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`.
    N/z%s/source_filenameoptions_z	(.*)_(.*)z%s.%sfilename)r   THUMBNAIL_PREFIXTHUMBNAIL_SUBDIRendswithlenoswalklistdirpathisfilejoinappendre_thumbnail_filematch	groupdictpopsplit
startswithregroups
setdefault)r   	recursiveprefixsubdirthumbnail_fileslen_pathallfilesfiledir_subdirsrel_dirthumbdr   source_pathmr	   thumbnail_files                      S/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/management/__init__.pyall_thumbnailsr/      s     ~**~**O==t|4yHggdmJJt$ 	#Dww~~bggll467T"	# b% ! # %guxy/ 	%D%++D1E!Aee$56O/1ww}}_/M,_&11&9"$'',,V!>#@Y<CAiL,>,>s,CIrAiL'**62!-CK<0 7A")AHHJ"6ww||G_=H,77"ENGGLLt4AjM!!!$1	%%6     c                    |t         j                  }|t         j                  }|t         j                  }|t         j                  }t
        j                  j                  |       \  }}t
        j                  j                  ||||      }t
        j                  j                  |      sg S t        |d|d      }|j                  |g       S )al  
    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
    F )r   r   r    )r   
MEDIA_ROOTr
   r   THUMBNAIL_BASEDIRr   r   r   r   isdirr/   get)	relative_source_pathrootbasedirr    r   
source_dirr	   thumbs_pathr$   s	            r.   thumbnails_for_filer<   @   s     |""~**~**,,77==)=>J'',,tWj&AK77==%	;%"$&E99Xr""r0   c                 6    t        | ||||      }t        |      S )z3
    Delete all thumbnails for a source image.
    )r<   _delete_using_thumbs_list)r7   r8   r9   r    r   thumbss         r.   delete_thumbnailsr@   ^   s%    
 !!5tWf!')F$V,,r0   c                 f    d}| D ]"  }|d   }	 t        j                  |       |dz  }$ |S #  Y +xY w)Nr   r	      )r   remove)r?   deleted
thumb_dictr	   s       r.   r>   r>   h   sM    G 
j)	IIh qLG N		s   ,0c                 f    d}t        | |      j                         D ]  }|t        |      z  } |S )z
    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.
    r   )r   )r/   valuesr>   )r   r   totalr?   s       r.   delete_all_thumbnailsrI   u   s=     E ;BBD 3*6223Lr0   )TNN)NNNN)T)r   r   easy_thumbnails.confr   compiler   r/   r<   r@   r>   rI    r0   r.   <module>rM      sR    	 	 )BJJ  / 0 
2j BF,0#< @D*.-

r0   