#NEWLINE# def squeeze( path ) : #NEWLINE# #INDENT# 'Returns path of optimized image or None if something went wrong.' #NEWLINE# if ( not isfile ( path ) ) : #NEWLINE# #INDENT# logger . error ( ( "'%s' does not point to a file." % path ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# if settings . DIET_DEBUG : #NEWLINE# #INDENT# call ( ( "cp '%(file)s' '%(file)s'.orig" % { #NEWLINE# #INDENT# 'file' : path , #NEWLINE# #UNINDENT# } ) , shell = True , stdout = PIPE ) #NEWLINE# #UNINDENT# filetype = determinetype ( path ) #NEWLINE# squeeze_cmd = '' #NEWLINE# if ( filetype == 'jpeg' ) : #NEWLINE# #INDENT# squeeze_cmd = squeeze_jpeg ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( filetype == 'gif' ) : #NEWLINE# #INDENT# squeeze_cmd = squeeze_gif ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( filetype == 'png' ) : #NEWLINE# #INDENT# squeeze_cmd = squeeze_png ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if squeeze_cmd : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# retcode = call ( ( squeeze_cmd % { #NEWLINE# #INDENT# 'file' : path , #NEWLINE# #UNINDENT# } ) , shell = True , stdout = PIPE ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger . error ( 'Squeezing failed with parameters:' ) #NEWLINE# logger . error ( ( squeeze_cmd [ filetype ] % { #NEWLINE# #INDENT# 'file' : path , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# logger . exception ( ) #NEWLINE# return None #NEWLINE# #UNINDENT# if ( retcode != 0 ) : #NEWLINE# #INDENT# logger . error ( 'Squeezing failed. Likely because you are missing one of required utilities.' ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# return path