import os
import re
import tempfile
-import imp
+if sys.version_info[:2] >= (3,12):
+ import importlib
+ import importlib.util
+else: import imp
import types
import gettext
import traceback
continue
# load the module that has name nameCmd in dirPath
- (file_, pathname, description) = imp.find_module(nameCmd, [dirPath])
- module = imp.load_module(nameCmd, file_, pathname, description)
+ if sys.version_info[:2] >= (3,12):
+ spec = importlib.machinery.PathFinder().find_spec(nameCmd, [dirPath])
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ else:
+ (file_, pathname, description) = imp.find_module(nameCmd, [dirPath])
+ module = imp.load_module(nameCmd, file_, pathname, description)
def run_command(args='',
options=None,
# Try to execute the script, catch the exception if it fails
try:
# import the module (in the sense of python)
- pymodule = imp.load_source(cmd_name, hook_script_path)
+ if sys.version_info[:2] >= (3,12):
+ spec = importlib.machinery.PathFinder().find_spec(cmd_name, hook_script_path)
+ pymodule = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(pymodule)
+ else:
+ pymodule = imp.load_source(cmd_name, hook_script_path)
# format a message to be printed at hook execution
msg = src.printcolors.printcWarning(_("Run hook script"))
raise src.SatException(_("Command '%s' does not exist") % module)
# load the module
- (file_, pathname, description) = imp.find_module(module, [cmdsdir])
- module = imp.load_module(module, file_, pathname, description)
+ if sys.version_info[:2] >= (3,12):
+ spec = importlib.util.find_spec(module)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ else:
+ (file_, pathname, description) = imp.find_module(module, [cmdsdir])
+ module = imp.load_module(module, file_, pathname, description)
return module
##################################################################