53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
"""
|
|
Definition of WebDAV and CalDAV clients.
|
|
"""
|
|
|
|
from functools import lru_cache
|
|
from typing import Any
|
|
|
|
from caldav import DAVClient as CalDAVclient
|
|
from caldav import Principal as CalDAVPrincipal
|
|
from webdav3.client import Client as WebDAVclient
|
|
from webdav3.client import Resource as WebDAVResource
|
|
|
|
from .async_helpers import run_in_executor
|
|
from .settings import SETTINGS
|
|
|
|
_WEBDAV_CLIENT = WebDAVclient({
|
|
"webdav_hostname": SETTINGS.webdav.url,
|
|
"webdav_login": SETTINGS.webdav.username,
|
|
"webdav_password": SETTINGS.webdav.password,
|
|
})
|
|
|
|
|
|
@lru_cache
|
|
def webdav_resource(remote_path: Any) -> WebDAVResource:
|
|
"""
|
|
Gets a resource using the main WebDAV client.
|
|
"""
|
|
|
|
return _WEBDAV_CLIENT.resource(remote_path)
|
|
|
|
|
|
@run_in_executor
|
|
def webdav_list(remote_path: str) -> list[str]:
|
|
"""
|
|
Asynchroneously lists a WebDAV path using the main WebDAV client.
|
|
"""
|
|
|
|
return _WEBDAV_CLIENT.list(remote_path)
|
|
|
|
|
|
_CALDAV_CLIENT = CalDAVclient(
|
|
url=SETTINGS.caldav.url,
|
|
username=SETTINGS.caldav.username,
|
|
password=SETTINGS.caldav.password,
|
|
)
|
|
|
|
|
|
def caldav_principal() -> CalDAVPrincipal:
|
|
"""
|
|
Gets the `Principal` object of the main CalDAV client.
|
|
"""
|
|
|
|
return _CALDAV_CLIENT.principal()
|