diff --git a/api/ovdashboard_api/core/calevent.py b/api/ovdashboard_api/core/calevent.py index 337716c..0823072 100644 --- a/api/ovdashboard_api/core/calevent.py +++ b/api/ovdashboard_api/core/calevent.py @@ -4,19 +4,19 @@ Definition of an asyncio compatible CalDAV calendar. Caches events using `timed_alru_cache`. """ +import functools +import logging from datetime import datetime -from functools import total_ordering -from logging import getLogger from typing import Annotated, Self from pydantic import BaseModel, ConfigDict, StringConstraints from vobject.base import Component -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) type StrippedStr = Annotated[str, StringConstraints(strip_whitespace=True)] -@total_ordering +@functools.total_ordering class CalEvent(BaseModel): """ A CalDAV calendar event. diff --git a/api/ovdashboard_api/core/config.py b/api/ovdashboard_api/core/config.py index 37001fe..f0c0f36 100644 --- a/api/ovdashboard_api/core/config.py +++ b/api/ovdashboard_api/core/config.py @@ -2,8 +2,8 @@ Python representation of the "config.txt" file inside the WebDAV directory. """ +import logging import tomllib -from logging import getLogger from typing import Any from pydantic import BaseModel @@ -13,7 +13,7 @@ from webdav3.exceptions import RemoteResourceNotFound from .settings import SETTINGS from .webdav import WebDAV -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) class TickerUIConfig(BaseModel): diff --git a/api/ovdashboard_api/core/dav_common.py b/api/ovdashboard_api/core/dav_common.py index f25f65a..c8c66e7 100644 --- a/api/ovdashboard_api/core/dav_common.py +++ b/api/ovdashboard_api/core/dav_common.py @@ -2,14 +2,14 @@ Definition of WebDAV and CalDAV clients. """ -from logging import getLogger +import logging from os import path from pathlib import Path from .. import __file__ as OVD_INIT from .webdav import WebDAV -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) def webdav_ensure_path(remote_path: str) -> bool: diff --git a/api/ovdashboard_api/core/webdav.py b/api/ovdashboard_api/core/webdav.py index 5679853..3f410cc 100644 --- a/api/ovdashboard_api/core/webdav.py +++ b/api/ovdashboard_api/core/webdav.py @@ -2,10 +2,10 @@ import logging import re from io import BytesIO +import requests from asyncify import asyncify from cache import AsyncTTL from cache.key import KEY -from requests import Response from webdav3.client import Client as WebDAVclient from .settings import SETTINGS @@ -21,7 +21,7 @@ class WebDAV: path, data=None, headers_ext=None, - ) -> Response: + ) -> requests.Response: res = super().execute_request(action, path, data, headers_ext) # the "Content-Length" header can randomly be missing on txt files, diff --git a/api/ovdashboard_api/routers/v1/_common.py b/api/ovdashboard_api/routers/v1/_common.py index 62d1db7..be0b53c 100644 --- a/api/ovdashboard_api/routers/v1/_common.py +++ b/api/ovdashboard_api/routers/v1/_common.py @@ -2,9 +2,9 @@ Dependables for defining Routers. """ +import logging import re from dataclasses import dataclass, field -from logging import getLogger from typing import Awaitable, Callable, Generic, ParamSpec, Self, TypeVar from fastapi import Depends, HTTPException, params, status @@ -14,7 +14,7 @@ from ...core.caldav import CalDAV from ...core.config import Config, get_config from ...core.webdav import WebDAV -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) _RESPONSE_OK = { status.HTTP_200_OK: { diff --git a/api/ovdashboard_api/routers/v1/aggregate.py b/api/ovdashboard_api/routers/v1/aggregate.py index 1238c7e..2dd3a2e 100644 --- a/api/ovdashboard_api/routers/v1/aggregate.py +++ b/api/ovdashboard_api/routers/v1/aggregate.py @@ -6,8 +6,7 @@ Router "aggregate" provides: - getting aggregate calendar events by name prefix """ -from logging import getLogger -from typing import Iterator +import logging from fastapi import APIRouter, Depends @@ -16,7 +15,7 @@ from ...core.calevent import CalEvent from ...core.config import Config, get_config from ._common import LM_AGGREGATES, LM_CALENDARS -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/aggregate", tags=["calendar"]) @@ -31,9 +30,9 @@ async def start_router() -> None: responses=LM_AGGREGATES.lister.responses, ) async def list_aggregate_calendars( - names: Iterator[str] = Depends(LM_AGGREGATES.lister.func), + names: list[str] = Depends(LM_AGGREGATES.lister.func), ) -> list[str]: - return list(names) + return names @router.get( @@ -41,9 +40,9 @@ async def list_aggregate_calendars( responses=LM_AGGREGATES.filter.responses, ) async def find_aggregate_calendars( - names: Iterator[str] = Depends(LM_AGGREGATES.filter.func), + names: list[str] = Depends(LM_AGGREGATES.filter.func), ) -> list[str]: - return list(names) + return names @router.get( diff --git a/api/ovdashboard_api/routers/v1/calendar.py b/api/ovdashboard_api/routers/v1/calendar.py index aa6ec33..8e78be2 100644 --- a/api/ovdashboard_api/routers/v1/calendar.py +++ b/api/ovdashboard_api/routers/v1/calendar.py @@ -6,7 +6,7 @@ Router "calendar" provides: - getting calendar events by calendar name prefix """ -from logging import getLogger +import logging from fastapi import APIRouter, Depends @@ -14,7 +14,7 @@ from ...core.caldav import CalDAV, CalEvent from ...core.config import CalendarUIConfig, Config, get_config from ._common import LM_CALENDARS -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/calendar", tags=["calendar"]) diff --git a/api/ovdashboard_api/routers/v1/file.py b/api/ovdashboard_api/routers/v1/file.py index e922c4f..cafb309 100644 --- a/api/ovdashboard_api/routers/v1/file.py +++ b/api/ovdashboard_api/routers/v1/file.py @@ -6,8 +6,8 @@ Router "file" provides: - getting files by name prefix """ +import logging from io import BytesIO -from logging import getLogger from fastapi import APIRouter, Depends from fastapi.responses import StreamingResponse @@ -17,7 +17,7 @@ from ...core.dav_common import webdav_ensure_files, webdav_ensure_path from ...core.webdav import WebDAV from ._common import LM_FILE, RP_FILE -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) _magic = Magic(mime=True) router = APIRouter(prefix="/file", tags=["file"]) diff --git a/api/ovdashboard_api/routers/v1/image.py b/api/ovdashboard_api/routers/v1/image.py index f726507..a7f191c 100644 --- a/api/ovdashboard_api/routers/v1/image.py +++ b/api/ovdashboard_api/routers/v1/image.py @@ -6,8 +6,8 @@ Router "image" provides: - getting image files in a uniform format by name prefix """ +import logging from io import BytesIO -from logging import getLogger from fastapi import APIRouter, Depends from fastapi.responses import StreamingResponse @@ -18,8 +18,7 @@ from ...core.dav_common import webdav_ensure_files, webdav_ensure_path from ...core.webdav import WebDAV from ._common import LM_IMAGE, RP_IMAGE -_logger = getLogger(__name__) -_PATH_NAME = "image_dir" +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/image", tags=["image"]) diff --git a/api/ovdashboard_api/routers/v1/misc.py b/api/ovdashboard_api/routers/v1/misc.py index 5e06169..e8a4995 100644 --- a/api/ovdashboard_api/routers/v1/misc.py +++ b/api/ovdashboard_api/routers/v1/misc.py @@ -5,8 +5,8 @@ Router "misc" provides: - getting the device IP """ -from importlib.metadata import version -from logging import getLogger +import importlib.metadata +import logging from socket import AF_INET, SOCK_DGRAM, socket from fastapi import APIRouter, Depends @@ -14,7 +14,7 @@ from fastapi import APIRouter, Depends from ...core.config import Config, LogoUIConfig, ServerUIConfig, get_config from ...core.settings import SETTINGS -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/misc", tags=["misc"]) @@ -43,7 +43,7 @@ async def get_ip() -> str: @router.get("/version") async def get_version() -> str: - return version("ovdashboard-api") + return importlib.metadata.version("ovdashboard-api") @router.get("/config/server") diff --git a/api/ovdashboard_api/routers/v1/text.py b/api/ovdashboard_api/routers/v1/text.py index 7c14a98..9afee69 100644 --- a/api/ovdashboard_api/routers/v1/text.py +++ b/api/ovdashboard_api/routers/v1/text.py @@ -7,17 +7,16 @@ Router "text" provides: - getting text file HTML content by name prefix (using Markdown) """ -from logging import getLogger +import logging +import markdown from fastapi import APIRouter, Depends -from markdown import markdown from ...core.dav_common import webdav_ensure_files, webdav_ensure_path from ...core.webdav import WebDAV from ._common import LM_TEXT, RP_TEXT -_logger = getLogger(__name__) -_PATH_NAME = "text_dir" +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/text", tags=["text"]) @@ -80,4 +79,4 @@ async def get_raw_text_by_prefix( async def get_html_by_prefix( text: str = Depends(_get_raw_text_by_prefix), ) -> str: - return markdown(text) + return markdown.markdown(text) diff --git a/api/ovdashboard_api/routers/v1/ticker.py b/api/ovdashboard_api/routers/v1/ticker.py index bbb2704..58f4a1b 100644 --- a/api/ovdashboard_api/routers/v1/ticker.py +++ b/api/ovdashboard_api/routers/v1/ticker.py @@ -6,18 +6,18 @@ Router "ticker" provides: - getting the ticker's UI config """ -from logging import getLogger +import logging from typing import Iterator +import markdown from fastapi import APIRouter, Depends -from markdown import markdown from ...core.config import Config, TickerUIConfig, get_config from ...core.dav_common import webdav_ensure_files, webdav_ensure_path from ...core.webdav import WebDAV from ._common import LM_TEXT, RP_TEXT -_logger = getLogger(__name__) +_logger = logging.getLogger(__name__) router = APIRouter(prefix="/ticker", tags=["text"]) @@ -73,7 +73,7 @@ async def get_ticker_content( async def get_ticker( ticker_content: str = Depends(get_ticker_content), ) -> str: - return markdown(ticker_content) + return markdown.markdown(ticker_content) @router.get("/raw")