mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
more asyncification for webdav
This commit is contained in:
parent
b73185e4fb
commit
a11c16d17b
1 changed files with 25 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
import re
|
||||
from io import BytesIO
|
||||
|
||||
|
@ -29,7 +30,12 @@ class WebDAV:
|
|||
Liste aller Dateien im Ordner `directory`, die zur RegEx `regex` passen
|
||||
"""
|
||||
|
||||
ls = cls._webdav_client.list(directory)
|
||||
loop = asyncio.get_running_loop()
|
||||
ls = await loop.run_in_executor(
|
||||
None,
|
||||
cls._webdav_client.list,
|
||||
directory,
|
||||
)
|
||||
|
||||
return [f"{directory}/{path}" for path in ls if regex.search(path)]
|
||||
|
||||
|
@ -40,7 +46,12 @@ class WebDAV:
|
|||
`True`, wenn an Pfad `path` eine Datei existiert
|
||||
"""
|
||||
|
||||
return cls._webdav_client.check(path)
|
||||
loop = asyncio.get_running_loop()
|
||||
return await loop.run_in_executor(
|
||||
None,
|
||||
cls._webdav_client.check,
|
||||
path,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@(_rb_ttl := AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1))
|
||||
|
@ -50,7 +61,12 @@ class WebDAV:
|
|||
"""
|
||||
|
||||
buffer = BytesIO()
|
||||
cls._webdav_client.resource(path).write_to(buffer)
|
||||
loop = asyncio.get_running_loop()
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
cls._webdav_client.resource(path).write_to,
|
||||
buffer,
|
||||
)
|
||||
buffer.seek(0)
|
||||
|
||||
return buffer.read()
|
||||
|
@ -69,7 +85,12 @@ class WebDAV:
|
|||
Bytes `buffer` in Datei in Pfad `path` schreiben
|
||||
"""
|
||||
|
||||
cls._webdav_client.resource(path).read_from(buffer)
|
||||
loop = asyncio.get_running_loop()
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
cls._webdav_client.resource(path).read_from,
|
||||
buffer,
|
||||
)
|
||||
|
||||
try:
|
||||
# hack: zugehörigen Cache-Eintrag entfernen
|
||||
|
|
Loading…
Reference in a new issue