35 lines
822 B
Python
35 lines
822 B
Python
from functools import lru_cache
|
|
from typing import Any
|
|
|
|
import caldav
|
|
from webdav3 import client as WebDAVclient
|
|
|
|
from .async_helpers import run_in_executor
|
|
from .settings import SETTINGS
|
|
|
|
_WEBDAV_CLIENT = WebDAVclient.Client({
|
|
"webdav_hostname": SETTINGS.webdav_url,
|
|
"webdav_login": SETTINGS.dav_username,
|
|
"webdav_password": SETTINGS.dav_password,
|
|
})
|
|
|
|
|
|
@lru_cache
|
|
def webdav_resource(remote_path: Any) -> WebDAVclient.Resource:
|
|
return _WEBDAV_CLIENT.resource(remote_path)
|
|
|
|
|
|
@run_in_executor
|
|
def webdav_list(remote_path: str) -> list:
|
|
return _WEBDAV_CLIENT.list(remote_path)
|
|
|
|
|
|
_CALDAV_CLIENT = caldav.DAVClient(
|
|
url=SETTINGS.caldav_url,
|
|
username=SETTINGS.dav_username,
|
|
password=SETTINGS.dav_password,
|
|
)
|
|
|
|
|
|
def caldav_principal() -> caldav.Principal:
|
|
return _CALDAV_CLIENT.principal()
|