
    h2                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 	 d dlmZ  e j                  d      Zd	 Zy# e$ r d ZY  w xY w)
    N)ImageUnidentifiedImageError)ContentFile)NamedTemporaryFile)settings)check_outputc                     t        j                  | dt         j                  i|}|j                         \  }}|j	                         }|r7|j                  d      }|| d   }t        j                  ||      }||_        ||S )z
        Run command with arguments and return its output as a byte string.

        Backported from Python 2.7 as it's implemented as pure python on
        stdlib.
        stdoutargsr   )
subprocessPopenPIPEcommunicatepollgetCalledProcessErroroutput)	popenargskwargsprocessr   
unused_errretcodecmderrors           W/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/optimize/post_processor.pyr   r      s     ""%.:??:28:$002
,,.**V$C{l11'3?E!ELK    zeasy_thumbnails.optimizec                    	 | j                   }	 t        j                  |      5 }|j                  j                         }ddd       	 t        j                     }|sy	 | j                  }	 t               5 }| j                  d       |j                  | j                                |j!                          |j	                  |j"                        }t%        |t&        j(                  d      }|r&t*        j-                  dj	                  ||             n$t*        j/                  dj	                  |             t        |j"                  d      5 }t1        |j                               | _        |j5                  | j"                         |j7                  | j"                  |        ddd       ddd       y# t        $ r Y yw xY w# 1 sw Y   xY w# t        $ r Y yw xY w# t        t        t        f$ r Y yw xY w# 1 sw Y   WxY w# 1 sw Y   yxY w# t8        $ r}	t*        j;                  |	       Y d}	~	yd}	~	ww xY w)	z6Optimize thumbnail images by removing unnecessary dataNr   )filenameT)stderrshellz{0} returned {1}z{0} returned nothingrb)pathNotImplementedErrorr   openformatlowerr   r   THUMBNAIL_OPTIMIZE_COMMAND	TypeErrorKeyErrorstorager   seekwritereadflushnamer   r   STDOUTloggerwarninginfor   filedeletesave	Exceptionr   )
	thumbnailthumbnail_pathimgr%   optimize_commandr*   	temp_filer   fes
             r   optimize_thumbnailr?   $   s   "ZZ' 	(3 ZZ%%'F	(#>>vF   G! 	8YNN1OOINN,-OO/66	6O! ):):$HF&--.>GI 299:JKLinnd+ 8q!,QVVX!6	y~~.Y^^Y78	8 	87  	( 	( "  x!45  8 8	8 	8   Qs   F8 G GG G# ,
H 6CH	AG='H	/H 8	GGGG 	G G #G:9G:=H	H		HH H 	H=H88H=)loggingr   PILr   r   django.core.files.baser   django.core.files.tempr   easy_thumbnails.optimize.confr   r   ImportError	getLoggerr1   r?    r   r   <module>rH      sO      - . 5 2'. 
		5	613  s   A   A
A