Make wsdl_dir path resolving more robust (#10967)

Relying on importlib to resolve the path to the wsdl directory is more
robust, since it traverses all site-packages directories, that are part
of the PYTHONPATH.
This commit is contained in:
Martin Weinelt 2024-04-13 19:25:58 +02:00 committed by GitHub
parent 3788df5bc6
commit b65656fa87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,9 @@
"""Configure and control camera via onvif.""" """Configure and control camera via onvif."""
import logging import logging
import site
from enum import Enum from enum import Enum
from importlib.util import find_spec
from pathlib import Path
import numpy import numpy
from onvif import ONVIFCamera, ONVIFError from onvif import ONVIFCamera, ONVIFError
@ -50,10 +51,7 @@ class OnvifController:
cam.onvif.port, cam.onvif.port,
cam.onvif.user, cam.onvif.user,
cam.onvif.password, cam.onvif.password,
wsdl_dir=site.getsitepackages()[0].replace( wsdl_dir=Path(find_spec("onvif").origin).parent / "../wsdl",
"dist-packages", "site-packages"
)
+ "/wsdl",
), ),
"init": False, "init": False,
"active": False, "active": False,