Skip to content

Commit

Permalink
pushservice replace imp with importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
atvcaptain committed Jul 12, 2024
1 parent e76b574 commit c9486a3
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pushservice/src/Modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import traceback

# Plugin framework
import imp
import importlib.util
import inspect

# Plugin internal
Expand Down Expand Up @@ -59,24 +59,21 @@ def loadModules(self, path, base):
if name == "__init__":
continue

spec = None
try:
fp, pathname, description = imp.find_module(name, [path])
spec = importlib.util.find_spec(name, [path])
except Exception as e:
print(_("PushService Find module exception: ") + str(e))
fp = None
print("PushService Find module exception: " + str(e))

if not fp:
print(_("PushService No module found: ") + str(name))
if spec is None:
print("PushService No module found: " + str(name))
continue

try:
module = imp.load_module(name, fp, pathname, description)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as e:
print(_("PushService Load exception: ") + str(e))
finally:
# Since we may exit via an exception, close fp explicitly.
if fp:
fp.close()
print("PushService Load exception: " + str(e))

if not module:
print(_("PushService No module available: ") + str(name))
Expand Down

0 comments on commit c9486a3

Please sign in to comment.