
    8Wa                         d Z ddlZddlZddlmZ ddlmZ  ej        e          Z	e	
                                ej        k    ZddddZd	 Zd
 Zd ZdS )z
Optimized images (jpg and png)
Assumes that jpegtran and optipng are isntalled on path.
http://jpegclub.org/jpegtran/
http://optipng.sourceforge.net/
Copyright (c) 2012 Irfan Ahmad (http://i.com.pk)
    N)call)signals)z7svgo {flags} --input="{filename}" --output="{filename}"--quiet )zUjpegtran {flags} -copy none -optimize -progressive -outfile "{filename}" "{filename}"r   z-v)zoptipng {flags} "{filename}"r   r   )z.svgz.jpgz.pngc                     t          j        | j        d                   D ]Y\  }}}|D ]P}t           j                            |          d         t
                                          v rt          ||           QZdS )zP
    Optimized jpg and png images

    :param pelican: The Pelican instance
    OUTPUT_PATH   N)oswalksettingspathsplitextCOMMANDSkeysoptimize)pelicandirpath_	filenamesnames        ^/var/www/html/maison-a-villennes.fr/sources/pelican-plugins/optimize_images/optimize_images.pyoptimize_imagesr      s     "$)9-)H!I!I ( (I 	( 	(Dw%%a(HMMOO;;$'''	(( (    c                 N   t           j                            | |          }t                              d|           t           j                            |          d         }t          |         \  }}}t          r|n|}|                    ||          }t          |d           dS )z
    Check if the name is a type of file that should be optimized.
    And optimizes it if required.

    :param dirpath: Path of the file to be optimzed
    :param name: A file name to be optimized
    zoptimizing %sr	   )filenameflagsT)shellN)
r
   r   joinloggerinfor   r   SHOW_OUTPUTformatr   )r   r   filepathextcommandsilentverboser   s           r   r   r   *   s     w||GX..H
KK***
'

8
$
$Q
'C'}GVW".GGEnnhen<<Gr   c                  N    t           j                            t                     d S )N)r   	finalizedconnectr    r   r   registerr,   <   s    o.....r   )__doc__loggingr
   
subprocessr   r   r   	getLogger__name__r   getEffectiveLevelDEBUGr!   r   r   r   r,   r+   r   r   <module>r4      s      				            		8	$	$ &&((GM9
 Wo;	 	( 	( 	(  $/ / / / /r   