logging and naming

This commit is contained in:
Jörn-Michael Miehe 2022-09-06 22:55:23 +00:00
parent f4b781912b
commit 33359aae43
4 changed files with 14 additions and 5 deletions

View file

@ -3,6 +3,7 @@ Python representation of the "config.txt" file inside the WebDAV directory.
"""
from io import BytesIO
from logging import getLogger
from typing import Any
from pydantic import BaseModel
@ -12,6 +13,9 @@ from webdav3.exceptions import RemoteResourceNotFound
from .dav_common import caldav_list
from .dav_file import DavFile
from .settings import SETTINGS
_logger = getLogger(__name__)
class TickerConfig(BaseModel):
@ -61,7 +65,7 @@ class Config(BaseModel):
Load the configuration instance from the server using `TOML`.
"""
dav_file = DavFile("config.txt")
dav_file = DavFile(SETTINGS.config_path)
try:
return cls.parse_obj(
@ -69,12 +73,16 @@ class Config(BaseModel):
)
except RemoteResourceNotFound:
_logger.warn(
f"Config file {SETTINGS.config_path!r} not found, creating ..."
)
cfg = cls()
cfg.calendar.aggregate["All Events"] = list(await caldav_list())
buffer = BytesIO()
toml_dump(cfg.dict(), buffer)
buffer.seek(0)
await dav_file.dump(buffer.read())
await dav_file.write(buffer.read())
return cfg

View file

@ -130,7 +130,7 @@ async def _get_calendar_events(
This can return an iterator - only the outer function is
cached.
"""
_logger.info(f"updating {calendar_name!r} ...")
_logger.info(f"downloading {calendar_name!r} ...")
calendar = caldav_principal().calendar(calendar_name)

View file

@ -28,7 +28,7 @@ async def _get_buffer(
@run_in_executor
def _inner() -> BytesIO:
_logger.info(f"updating {remote_path!r} ...")
_logger.info(f"downloading {remote_path!r} ...")
resource = webdav_resource(remote_path)
buffer = BytesIO()
@ -85,7 +85,7 @@ class DavFile:
bytes = await self.bytes
return bytes.decode(encoding="utf-8")
async def dump(self, content: bytes) -> None:
async def write(self, content: bytes) -> None:
"""
Write bytes into file.
"""

View file

@ -55,6 +55,7 @@ class Settings(BaseSettings):
webdav: DavSettings = DavSettings()
webdav_prefix: str = "/ovdashboard"
config_path: str = "config.txt"
caldav: DavSettings = DavSettings()
cache_seconds: int = 30