From 47e5be86a18d8f30f31c9ff3395efae1cbf22e0a Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Wed, 27 Sep 2023 13:39:25 +0200 Subject: [PATCH 1/3] poe_common: add a helper emulating deprecated imp.load_source() The imp module is deprecated and will be removed in the future, so add an API compatible load_source() helper function to poe_common.py. Signed-off-by: Jonas Gorski --- dentos-poe-agent/opt/poeagent/inc/poe_common.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dentos-poe-agent/opt/poeagent/inc/poe_common.py b/dentos-poe-agent/opt/poeagent/inc/poe_common.py index fbdd872..18157dc 100755 --- a/dentos-poe-agent/opt/poeagent/inc/poe_common.py +++ b/dentos-poe-agent/opt/poeagent/inc/poe_common.py @@ -20,6 +20,7 @@ import syslog import fcntl import traceback +import importlib.util from pathlib import Path # POE Driver Attributes @@ -297,3 +298,13 @@ def check_init_plat_ret_result(init_poe_result, sum_mode=0): elif type(itm_result) is int: sum_result += itm_result return (all_ret, sum_result) + +def load_source(name, pathname): + module = None + spec = None + + spec = importlib.util.spec_from_file_location(name, pathname) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + return module From 010fa1f131fff91efceea2359f27461c3f2cfe56 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Wed, 27 Sep 2023 13:50:24 +0200 Subject: [PATCH 2/3] poed: switch to new helper for load_source() Drop the deprecated import and switch to the new helper function. Silences the following warning on start up: > Sep 21 13:11:59 localhost systemd[1]: Started DentOS POE Agent. > Sep 21 13:11:59 localhost poed[938]: poed.py:28: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses > Sep 21 13:11:59 localhost poed[938]: import imp Signed-off-by: Jonas Gorski --- dentos-poe-agent/opt/poeagent/bin/poed.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dentos-poe-agent/opt/poeagent/bin/poed.py b/dentos-poe-agent/opt/poeagent/bin/poed.py index 97f76aa..8c463b9 100755 --- a/dentos-poe-agent/opt/poeagent/bin/poed.py +++ b/dentos-poe-agent/opt/poeagent/bin/poed.py @@ -25,7 +25,6 @@ import errno import threading import signal -import imp import time import json import fcntl @@ -184,7 +183,7 @@ def platform_src_path(self): def load_poe_plat(self): poe_plat = None try: - plat_src = imp.load_source("poe_plat", self.platform_src_path()) + plat_src = load_source("poe_plat", self.platform_src_path()) poe_plat = plat_src.get_poe_platform() except Exception as e: self.log.alert("Failed to load PoE platform. err: %s" % str(e)) From 1a345e4e05c8227aa5c01ec3cd36ca43f2b880f2 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Wed, 27 Sep 2023 13:52:35 +0200 Subject: [PATCH 3/3] poecli: switch to new helper for load_source() Drop the deprecated import and switch to the new helper function. Silences the following warning on start up: > root@localhost:~# poecli > poecli.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses > import imp Signed-off-by: Jonas Gorski --- dentos-poe-agent/opt/poeagent/bin/poecli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dentos-poe-agent/opt/poeagent/bin/poecli.py b/dentos-poe-agent/opt/poeagent/bin/poecli.py index e626297..d246c14 100755 --- a/dentos-poe-agent/opt/poeagent/bin/poecli.py +++ b/dentos-poe-agent/opt/poeagent/bin/poecli.py @@ -21,7 +21,6 @@ import binascii import re -import imp import sys import subprocess import os @@ -64,7 +63,7 @@ def platform_src_path(self): print_stderr("Failed to get platform path. err: %s" % str(e)) def load_poe_platform(self): - plat_src = imp.load_source("poe_plat", self.platform_src_path()) + plat_src = load_source("poe_plat", self.platform_src_path()) poe_plat = plat_src.get_poe_platform() return poe_plat