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
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -29,7 +30,12 @@ class WebDAV:
|
||||||
Liste aller Dateien im Ordner `directory`, die zur RegEx `regex` passen
|
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)]
|
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
|
`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
|
@classmethod
|
||||||
@(_rb_ttl := AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1))
|
@(_rb_ttl := AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1))
|
||||||
|
@ -50,7 +61,12 @@ class WebDAV:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
buffer = BytesIO()
|
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)
|
buffer.seek(0)
|
||||||
|
|
||||||
return buffer.read()
|
return buffer.read()
|
||||||
|
@ -69,7 +85,12 @@ class WebDAV:
|
||||||
Bytes `buffer` in Datei in Pfad `path` schreiben
|
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:
|
try:
|
||||||
# hack: zugehörigen Cache-Eintrag entfernen
|
# hack: zugehörigen Cache-Eintrag entfernen
|
||||||
|
|
Loading…
Reference in a new issue