def handle_file(pth): '''Optimizes an image and stores an original if KEEP_ORIGINALS is set''' logging.info('Optimizing file %s', pth) if KEEP_ORIGINALS: if pth in store.originals: # we have previously optimized this file and know where to store it storedat = store_original(pth, store.originals[pth]) else: storedat = store_original(pth) # the original gets briefly added to ignore so watchdog doesnt pick it up ignore_file(pth) optimize_with_touch(pth) if KEEP_ORIGINALS: # only keep the file if we actually optimized it if same_file(storedat, pth): storedat.remove() else: store_original_location(pth, storedat)
def check_image(self, img): img = self.img_path(img) sz = img.size optimize_with_touch(img) self.assertTrue(sz >= img.size)