fix(loaders): use modern module loader

main
Marshall Hallenbeck 2023-03-26 02:45:16 -04:00
parent 9100fbbd9a
commit 0a03c80e66
2 changed files with 11 additions and 8 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import types
from importlib.machinery import SourceFileLoader
import os
import sys
@ -56,7 +56,9 @@ class module_loader:
def load_module(self, module_path):
try:
module = SourceFileLoader('payload_module', module_path).load_module().CMEModule()
loader = SourceFileLoader('protocol', module_path)
module = types.ModuleType(loader.name)
loader.exec_module(mod)
if self.module_is_sane(module, module_path):
return module
except Exception as e:

View File

@ -1,18 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import imp
import types
from importlib.machinery import SourceFileLoader
import os
import sys
import cme
class protocol_loader:
class protocol_loader:
def __init__(self):
self.cme_path = os.path.expanduser('~/.cme')
def load_protocol(self, protocol_path):
protocol = imp.load_source('protocol', protocol_path)
loader = SourceFileLoader('protocol', protocol_path)
protocol = types.ModuleType(loader.name)
loader.exec_module(protocol)
#if self.module_is_sane(module, module_path):
return protocol
@ -27,7 +28,7 @@ class protocol_loader:
protocol_path = os.path.join(path, protocol)
protocol_name = protocol[:-3]
protocols[protocol_name] = {'path' : protocol_path}
protocols[protocol_name] = {'path': protocol_path}
db_file_path = os.path.join(path, protocol_name, 'database.py')
db_nav_path = os.path.join(path, protocol_name, 'db_navigator.py')