mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
31 lines
759 B
Python
31 lines
759 B
Python
import re
|
|
from io import BytesIO
|
|
|
|
from webdav3.client import Client as WebDAVclient
|
|
|
|
from .settings import SETTINGS
|
|
|
|
_WEBDAV_CLIENT = WebDAVclient({
|
|
"webdav_hostname": SETTINGS.webdav.url,
|
|
"webdav_login": SETTINGS.webdav.username,
|
|
"webdav_password": SETTINGS.webdav.password,
|
|
"disable_check": SETTINGS.webdav.disable_check,
|
|
})
|
|
|
|
|
|
async def dav_list_files(regex: re.Pattern, directory: str = "") -> list[str]:
|
|
ls = _WEBDAV_CLIENT.list(directory)
|
|
return [
|
|
f"{directory}/{path}"
|
|
for path in ls
|
|
if regex.search(path)
|
|
]
|
|
|
|
|
|
async def dav_get_file(path: str) -> BytesIO:
|
|
resource = _WEBDAV_CLIENT.resource(path)
|
|
buffer = BytesIO()
|
|
resource.write_to(buffer)
|
|
buffer.seek(0)
|
|
|
|
return buffer
|