Compare commits

..

No commits in common. "8b35bb704463776b5acebdca5fd82816f6be1453" and "baeff5c2943b168db1b713e3220e8ccb0d664092" have entirely different histories.

7 changed files with 8 additions and 87 deletions

View file

@ -23,7 +23,6 @@ class TickerConfig(BaseModel):
Section "[ticker]" in "config.txt".
"""
file_name: str = "ticker"
separator: str = " +++ "
comment_marker: str = "#"
color: str = "primary"
@ -56,9 +55,6 @@ class Config(BaseModel):
Main representation of "config.txt".
"""
image_dir: str = "image"
text_dir: str = "text"
ticker: TickerConfig = TickerConfig()
image: ImageConfig = ImageConfig()
calendar: CalendarConfig = CalendarConfig()

View file

@ -68,23 +68,6 @@ def webdav_check() -> bool:
return True
def webdav_ensure_path(remote_path: str) -> None:
remote_path = f"{SETTINGS.webdav_prefix}/{remote_path}"
if _WEBDAV_CLIENT.check(remote_path):
_logger.debug(
"WebDAV path %s found.",
repr(remote_path),
)
return
_logger.info(
"WebDAV path %s not found, creating ...",
repr(remote_path),
)
_WEBDAV_CLIENT.mkdir(remote_path)
@lru_cache(maxsize=SETTINGS.cache_size)
def webdav_resource(remote_path: Any) -> WebDAVResource:
"""

View file

@ -4,7 +4,6 @@ Dependables for defining Routers.
import re
from dataclasses import dataclass
from logging import getLogger
from typing import Iterator, Protocol
from fastapi import HTTPException, status
@ -13,8 +12,6 @@ from webdav3.exceptions import RemoteResourceNotFound
from ..config import Config
from ..dav_common import caldav_list, webdav_list
_logger = getLogger(__name__)
class NameLister(Protocol):
"""
@ -40,7 +37,7 @@ class FileNameLister:
File names listed will be in `remote_path` and will match the RegEx `re`.
"""
path_name: str
remote_path: str
re: re.Pattern[str]
@property
@ -48,20 +45,14 @@ class FileNameLister:
return {
**_RESPONSE_OK,
status.HTTP_404_NOT_FOUND: {
"description": f"{self.path_name!r} not found",
"description": f"{self.remote_path!r} not found",
"content": None,
},
}
@property
async def remote_path(self) -> str:
cfg = await Config.get()
return str(cfg.dict()[self.path_name])
async def __call__(self) -> Iterator[str]:
try:
file_names = await webdav_list(await self.remote_path)
file_names = await webdav_list(self.remote_path)
return (
name
@ -70,10 +61,6 @@ class FileNameLister:
)
except RemoteResourceNotFound:
_logger.error(
"WebDAV path %s lost!",
repr(await self.remote_path),
)
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

View file

@ -6,7 +6,6 @@ Router "cal_aggregate" provides:
- getting aggregate calendar events by name prefix
"""
from logging import getLogger
from typing import Iterator
from fastapi import APIRouter, Depends
@ -16,8 +15,6 @@ from ..dav_calendar import CalEvent, DavCalendar
from ._common import CalAggregateLister, PrefixFinder, PrefixUnique
from .calendar import calendar_unique
_logger = getLogger(__name__)
router = APIRouter(prefix="/aggregate", tags=["calendar"])
cal_aggregate_lister = CalAggregateLister()
@ -25,11 +22,6 @@ cal_aggregate_finder = PrefixFinder(cal_aggregate_lister)
cal_aggregate_unique = PrefixUnique(cal_aggregate_finder)
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
@router.get("/list", response_model=list[str])
async def list_aggregate_calendars(
names: Iterator[str] = Depends(cal_aggregate_lister),

View file

@ -6,7 +6,6 @@ Router "calendar" provides:
- getting calendar events by calendar name prefix
"""
from logging import getLogger
from typing import Iterator
from fastapi import APIRouter, Depends
@ -14,8 +13,6 @@ from fastapi import APIRouter, Depends
from ..dav_calendar import CalEvent, DavCalendar
from ._common import CalendarNameLister, PrefixFinder, PrefixUnique
_logger = getLogger(__name__)
router = APIRouter(prefix="/calendar", tags=["calendar"])
calendar_lister = CalendarNameLister()
@ -23,11 +20,6 @@ calendar_finder = PrefixFinder(calendar_lister)
calendar_unique = PrefixUnique(calendar_finder)
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
@router.get("/list", response_model=list[str])
async def list_calendars(
names: Iterator[str] = Depends(calendar_lister),

View file

@ -8,7 +8,6 @@ Router "image" provides:
import re
from io import BytesIO
from logging import getLogger
from typing import Iterator
from fastapi import APIRouter, Depends
@ -16,16 +15,13 @@ from fastapi.responses import StreamingResponse
from PIL import Image
from ..config import Config
from ..dav_common import webdav_ensure_path
from ..dav_file import DavFile
from ._common import FileNameLister, PrefixFinder, PrefixUnique
_logger = getLogger(__name__)
router = APIRouter(prefix="/image", tags=["image"])
image_lister = FileNameLister(
path_name="image_dir",
remote_path="img",
re=re.compile(
r"\.(gif|jpe?g|tiff?|png|bmp)$",
flags=re.IGNORECASE,
@ -36,13 +32,6 @@ image_finder = PrefixFinder(image_lister)
image_unique = PrefixUnique(image_finder)
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
webdav_ensure_path(await image_lister.remote_path)
@router.get(
"/list",
response_model=list[str],
@ -76,7 +65,7 @@ async def get_image(
) -> StreamingResponse:
cfg = await Config.get()
dav_file = DavFile(f"{await image_lister.remote_path}/{name}")
dav_file = DavFile(f"{image_lister.remote_path}/{name}")
img = Image.open(
BytesIO(await dav_file.as_bytes)
).convert(

View file

@ -10,23 +10,19 @@ Router "text" provides:
"""
import re
from logging import getLogger
from typing import Iterator
from fastapi import APIRouter, Depends
from markdown import markdown
from ..config import Config
from ..dav_common import webdav_ensure_path
from ..dav_file import DavFile
from ._common import FileNameLister, PrefixFinder, PrefixUnique
_logger = getLogger(__name__)
router = APIRouter(prefix="/text", tags=["text"])
text_lister = FileNameLister(
path_name="text_dir",
remote_path="text",
re=re.compile(
r"\.(txt|md)$",
flags=re.IGNORECASE,
@ -37,20 +33,8 @@ text_finder = PrefixFinder(text_lister)
text_unique = PrefixUnique(text_finder)
@router.on_event("startup")
async def start_router() -> None:
_logger.debug(f"{router.prefix} router starting.")
webdav_ensure_path(await text_lister.remote_path)
async def get_ticker_lines() -> Iterator[str]:
cfg = await Config.get()
file_name = await text_unique(cfg.ticker.file_name)
ticker = await DavFile(
f"{await text_lister.remote_path}/{file_name}",
).as_string
ticker = await DavFile("text/ticker.txt").as_string
return (
line.strip()
@ -121,9 +105,7 @@ async def find_texts(
async def get_text_content(
name: str = Depends(text_unique),
) -> str:
return await DavFile(
f"{await text_lister.remote_path}/{name}",
).as_string
return await DavFile(f"{text_lister.remote_path}/{name}").as_string
@router.get(