a
    œ"WfS  ã                   @   sX   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 G dd„ deƒZdS )	é    N)Úsettings)ÚBaseCommand)Úget_backend)Úget_thumb_filename)Úget_image_filesc                   @   s,   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdS )	ÚCommandzŠ
    Creates thumbnail files for the CKEditor file image browser.
    Useful if starting to use django-ckeditor with existing images.
    c                 O   s¢   t tdd ƒr’tƒ }tƒ D ]j}|  |¡s| j d| ¡ z| |¡ W q ty€ } z$| j d|› d|› �¡ W Y d }~qd }~0 0 q| j d¡ n| j d¡ d S )NZCKEDITOR_IMAGE_BACKENDzCreating thumbnail for %szCouldn't create thumbnail for z: ZFinishedzNo thumbnail backend is enabled)	Úgetattrr   r   r   Ú_thumbnail_existsÚstdoutÚwriteZcreate_thumbnailÚ	Exception)ÚselfÚargsÚoptionsÚbackendÚimageÚe© r   úy/var/www/sistema_ama/venv/lib/python3.9/site-packages/ckeditor_uploader/management/commands/generateckeditorthumbnails.pyÚhandle   s    

0zCommand.handlec                 C   s   |   t|ƒ¡}tj |¡S ©N)Ú_to_absolute_pathr   ÚosÚpathÚisfile)r   Ú
image_pathZ
thumb_pathr   r   r   r	      s    zCommand._thumbnail_existsc                 C   s   t j tj| ¡S r   )r   r   Újoinr   Z
MEDIA_ROOT)r   r   r   r   r   #   s    zCommand._to_absolute_pathN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   Ústaticmethodr   r   r   r   r   r      s
   r   )r   Zdjango.confr   Zdjango.core.management.baser   Zckeditor_uploader.backendsr   Zckeditor_uploader.utilsr   Zckeditor_uploader.viewsr   r   r   r   r   r   Ú<module>   s   