From b2af7490ffa490c79d0a66e4dafa42ef2c37493d Mon Sep 17 00:00:00 2001 From: mulin_huang Date: Tue, 22 Mar 2022 11:29:45 +0800 Subject: [PATCH] [host-service] Fix the path of host_modules Signed-off-by: MuLin --- src/sonic-host-services/scripts/sonic-host-server | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sonic-host-services/scripts/sonic-host-server b/src/sonic-host-services/scripts/sonic-host-server index a9fdc2eb25fd..3d53e3c19547 100755 --- a/src/sonic-host-services/scripts/sonic-host-server +++ b/src/sonic-host-services/scripts/sonic-host-server @@ -6,6 +6,7 @@ import os.path import glob import importlib import sys +import site import dbus import dbus.service @@ -15,7 +16,13 @@ from gi.repository import GObject def register_modules(): """Register all host modules""" - mod_path = '/usr/local/lib/python3.7/dist-packages/host_modules' + mod_path = "" + for package_path in site.getsitepackages(): + candidate = os.path.join(package_path, 'host_modules') + if os.path.isdir(candidate): + mod_path = candidate + print("host modules path:", mod_path) + break sys.path.append(mod_path) for mod_file in glob.glob(os.path.join(mod_path, '*.py')): if os.path.isfile(mod_file) and not mod_file.endswith('__init__.py'):