change from sync to async and from flask to quart
Build and Push Docker Container / build-and-push (push) Successful in 1m35s

This commit is contained in:
2026-01-06 13:36:43 +01:00
parent 962d8b1043
commit 6e74b5fb57
6 changed files with 85 additions and 90 deletions
+19 -11
View File
@@ -1,16 +1,24 @@
import aiofiles.os
import aiofiles
import os
def read_file(path, callback=None):
if os.path.exists(path):
with open(path, 'r') as f:
data = callback(f)
return data
else:
async def read_file(path: str, callback=None):
if not await aiofiles.os.path.exists(path):
return None
def save_file(path, data, callback=None, *args, **kwargs):
if not os.path.exists(path):
os.makedirs(os.path.dirname(path), exist_ok=True)
async with aiofiles.open(path, "r") as f:
if callback:
return await callback(f)
return await f.read()
with open(path, 'w') as f:
callback(data, f, *args, **kwargs)
async def save_file(path: str, data, callback=None, *args, **kwargs):
dir_path = os.path.dirname(path)
if dir_path:
await aiofiles.os.makedirs(dir_path, exist_ok=True)
async with aiofiles.open(path, "w") as f:
if callback:
await callback(data, f, *args, **kwargs)
else:
await f.write(data)