logWrite replaced with logging module

This commit is contained in:
2023-06-23 11:25:27 +02:00
parent 23467a88ef
commit 4b43e76822
5 changed files with 50 additions and 27 deletions

View File

@@ -1,3 +1,4 @@
import logging
import re
from datetime import datetime, timedelta, timezone
from os import makedirs, path, remove, system
@@ -43,14 +44,18 @@ from modules.security import (
get_current_active_user,
get_user,
)
from modules.utils import configGet, logWrite
from modules.utils import configGet
logger = logging.getLogger(__name__)
async def compress_image(image_path: str):
image_type = Magic(mime=True).from_file(image_path)
if image_type not in ["image/jpeg", "image/png"]:
logWrite(f"Not compressing {image_path} because its mime is '{image_type}'")
logger.info(
"Not compressing %s because its mime is '%s'", image_path, image_type
)
return
size_before = path.getsize(image_path) / 1024
@@ -66,12 +71,15 @@ async def compress_image(image_path: str):
return
task.start()
logWrite(f"Compressing '{Path(image_path).name}'...")
logger.info("Compressing '%s'...", Path(image_path).name)
task.join()
size_after = path.getsize(image_path) / 1024
logWrite(
f"Compressed '{Path(image_path).name}' from {size_before} Kb to {size_after} Kb"
logger.info(
"Compressed '%s' from %s Kb to %s Kb",
Path(image_path).name,
size_before,
size_after,
)