ovdashboard/api/ovdashboard_api/core/dav_common.py

61 lines
1.4 KiB
Python
Raw Normal View History

2023-10-20 08:43:15 +00:00
"""
Definition of WebDAV and CalDAV clients.
"""
2023-10-26 16:21:07 +00:00
import logging
2023-10-20 08:43:15 +00:00
from os import path
from pathlib import Path
from .. import __file__ as OVD_INIT
2023-11-09 11:13:48 +00:00
from .dav.webdav import WebDAV
2023-10-20 08:43:15 +00:00
2023-10-26 16:21:07 +00:00
_logger = logging.getLogger(__name__)
2023-10-20 08:43:15 +00:00
def webdav_ensure_path(remote_path: str) -> bool:
if WebDAV._webdav_client.check(remote_path):
_logger.debug(
"WebDAV path %s found.",
repr(remote_path),
)
return True
_logger.info(
"WebDAV path %s not found, creating ...",
repr(remote_path),
)
WebDAV._webdav_client.mkdir(remote_path)
return False
def get_skel_path(skel_file: str) -> Path:
skel_path = path.dirname(Path(OVD_INIT).absolute())
return Path(skel_path).joinpath("skel", skel_file)
def webdav_upload_skel(remote_path: str, *skel_files: str) -> None:
for skel_file in skel_files:
_logger.debug(
"Creating WebDAV file %s ...",
repr(skel_file),
)
WebDAV._webdav_client.upload_file(
f"{remote_path}/{skel_file}",
get_skel_path(skel_file),
)
def webdav_ensure_files(remote_path: str, *file_names: str) -> None:
missing_files = (
file_name
for file_name in file_names
if not WebDAV._webdav_client.check(f"{remote_path}/{file_name}")
)
webdav_upload_skel(
remote_path,
*missing_files,
)