Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop deprecated imp module use #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dentos-poe-agent/opt/poeagent/bin/poecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import binascii
import re
import imp
import sys
import subprocess
import os
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions dentos-poe-agent/opt/poeagent/bin/poed.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import errno
import threading
import signal
import imp
import time
import json
import fcntl
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions dentos-poe-agent/opt/poeagent/inc/poe_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import syslog
import fcntl
import traceback
import importlib.util
from pathlib import Path

# POE Driver Attributes
Expand Down Expand Up @@ -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