minor refacs (imports, unuseds)
This commit is contained in:
parent
b6798df29c
commit
3a255db15a
12 changed files with 36 additions and 39 deletions
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"])
|
||||
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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"])
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue