@task(rate_limit='15/m')
@timeit
def compress_image(for_obj, for_field):
 for_ = getattr(for_obj, for_field)
 if (not (for_ and os.path.isfile(for_.path))):
  log_msg = 'No file to compress for: {model} {id}, {for_f}'
  log.info(log_msg.format(model=for_obj.__class__.__name__, id=for_obj.id, for_f=for_field))
  return
 if (not (os.path.splitext(for_.path)[1].lower() == '.png')):
  log_msg = 'File is not PNG for: {model} {id}, {for_f}'
  log.info(log_msg.format(model=for_obj.__class__.__name__, id=for_obj.id, for_f=for_field))
  return
 log_msg = 'Compressing {model} {id}: {for_f}'
 log.info(log_msg.format(model=for_obj.__class__.__name__, id=for_obj.id, for_f=for_field))
 file_path = for_.path
 if (settings.OPTIPNG_PATH is not None):
  subprocess.call([settings.OPTIPNG_PATH, '-quiet', '-preserve', file_path])

@ task ( rate_limit = '15/m' ) @ timeit def compress_image ( for_obj , for_field ) : for_ = getattr ( for_obj , for_field ) if ( not ( for_ and os . path . isfile ( for_ . path ) ) ) : log_msg = 'No file to compress for: {model} {id}, {for_f}' log . info ( log_msg . format ( model = for_obj . __class__ . __name__ , id = for_obj . id , for_f = for_field ) ) return if ( not ( os . path . splitext ( for_ . path ) [ 1 ] . lower ( ) == '.png' ) ) : log_msg = 'File is not PNG for: {model} {id}, {for_f}' log . info ( log_msg . format ( model = for_obj . __class__ . __name__ , id = for_obj . id , for_f = for_field ) ) return log_msg = 'Compressing {model} {id}: {for_f}' log . info ( log_msg . format ( model = for_obj . __class__ . __name__ , id = for_obj . id , for_f = for_field ) ) file_path = for_ . path if ( settings . OPTIPNG_PATH is not None ) : subprocess . call ( [ settings . OPTIPNG_PATH , '-quiet' , '-preserve' , file_path ] )
compress an image of given field for given object .