2022-09-04 22:30:40 +00:00
|
|
|
from functools import lru_cache
|
|
|
|
from typing import Any
|
|
|
|
|
2022-09-04 22:41:46 +00:00
|
|
|
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
|
2022-09-04 22:30:40 +00:00
|
|
|
|
|
|
|
from .async_helpers import run_in_executor
|
|
|
|
from .settings import SETTINGS
|
|
|
|
|
2022-09-04 22:41:46 +00:00
|
|
|
_WEBDAV_CLIENT = WebDAVclient({
|
2022-09-04 22:30:40 +00:00
|
|
|
"webdav_hostname": SETTINGS.webdav_url,
|
|
|
|
"webdav_login": SETTINGS.dav_username,
|
|
|
|
"webdav_password": SETTINGS.dav_password,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@lru_cache
|
2022-09-04 22:41:46 +00:00
|
|
|
def webdav_resource(remote_path: Any) -> WebDAVResource:
|
2022-09-04 22:30:40 +00:00
|
|
|
return _WEBDAV_CLIENT.resource(remote_path)
|
|
|
|
|
|
|
|
|
|
|
|
@run_in_executor
|
|
|
|
def webdav_list(remote_path: str) -> list:
|
|
|
|
return _WEBDAV_CLIENT.list(remote_path)
|
|
|
|
|
|
|
|
|
2022-09-04 22:41:46 +00:00
|
|
|
_CALDAV_CLIENT = CalDAVclient(
|
2022-09-04 22:30:40 +00:00
|
|
|
url=SETTINGS.caldav_url,
|
|
|
|
username=SETTINGS.dav_username,
|
|
|
|
password=SETTINGS.dav_password,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-09-04 22:41:46 +00:00
|
|
|
def caldav_principal() -> CalDAVPrincipal:
|
2022-09-04 22:30:40 +00:00
|
|
|
return _CALDAV_CLIENT.principal()
|