logging and naming
This commit is contained in:
parent
f4b781912b
commit
33359aae43
4 changed files with 14 additions and 5 deletions
|
@ -3,6 +3,7 @@ Python representation of the "config.txt" file inside the WebDAV directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from logging import getLogger
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
@ -12,6 +13,9 @@ from webdav3.exceptions import RemoteResourceNotFound
|
||||||
|
|
||||||
from .dav_common import caldav_list
|
from .dav_common import caldav_list
|
||||||
from .dav_file import DavFile
|
from .dav_file import DavFile
|
||||||
|
from .settings import SETTINGS
|
||||||
|
|
||||||
|
_logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TickerConfig(BaseModel):
|
class TickerConfig(BaseModel):
|
||||||
|
@ -61,7 +65,7 @@ class Config(BaseModel):
|
||||||
Load the configuration instance from the server using `TOML`.
|
Load the configuration instance from the server using `TOML`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
dav_file = DavFile("config.txt")
|
dav_file = DavFile(SETTINGS.config_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return cls.parse_obj(
|
return cls.parse_obj(
|
||||||
|
@ -69,12 +73,16 @@ class Config(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
except RemoteResourceNotFound:
|
except RemoteResourceNotFound:
|
||||||
|
_logger.warn(
|
||||||
|
f"Config file {SETTINGS.config_path!r} not found, creating ..."
|
||||||
|
)
|
||||||
|
|
||||||
cfg = cls()
|
cfg = cls()
|
||||||
cfg.calendar.aggregate["All Events"] = list(await caldav_list())
|
cfg.calendar.aggregate["All Events"] = list(await caldav_list())
|
||||||
|
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
toml_dump(cfg.dict(), buffer)
|
toml_dump(cfg.dict(), buffer)
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
await dav_file.dump(buffer.read())
|
await dav_file.write(buffer.read())
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
|
|
@ -130,7 +130,7 @@ async def _get_calendar_events(
|
||||||
This can return an iterator - only the outer function is
|
This can return an iterator - only the outer function is
|
||||||
cached.
|
cached.
|
||||||
"""
|
"""
|
||||||
_logger.info(f"updating {calendar_name!r} ...")
|
_logger.info(f"downloading {calendar_name!r} ...")
|
||||||
|
|
||||||
calendar = caldav_principal().calendar(calendar_name)
|
calendar = caldav_principal().calendar(calendar_name)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ async def _get_buffer(
|
||||||
|
|
||||||
@run_in_executor
|
@run_in_executor
|
||||||
def _inner() -> BytesIO:
|
def _inner() -> BytesIO:
|
||||||
_logger.info(f"updating {remote_path!r} ...")
|
_logger.info(f"downloading {remote_path!r} ...")
|
||||||
|
|
||||||
resource = webdav_resource(remote_path)
|
resource = webdav_resource(remote_path)
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
|
@ -85,7 +85,7 @@ class DavFile:
|
||||||
bytes = await self.bytes
|
bytes = await self.bytes
|
||||||
return bytes.decode(encoding="utf-8")
|
return bytes.decode(encoding="utf-8")
|
||||||
|
|
||||||
async def dump(self, content: bytes) -> None:
|
async def write(self, content: bytes) -> None:
|
||||||
"""
|
"""
|
||||||
Write bytes into file.
|
Write bytes into file.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -55,6 +55,7 @@ class Settings(BaseSettings):
|
||||||
|
|
||||||
webdav: DavSettings = DavSettings()
|
webdav: DavSettings = DavSettings()
|
||||||
webdav_prefix: str = "/ovdashboard"
|
webdav_prefix: str = "/ovdashboard"
|
||||||
|
config_path: str = "config.txt"
|
||||||
caldav: DavSettings = DavSettings()
|
caldav: DavSettings = DavSettings()
|
||||||
|
|
||||||
cache_seconds: int = 30
|
cache_seconds: int = 30
|
||||||
|
|
Loading…
Reference in a new issue