""" Definition of WebDAV and CalDAV clients. """ from logging import getLogger from os import path from pathlib import Path from .. import __file__ as OVD_INIT from .webdav import WebDAV _logger = getLogger(__name__) 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, )