Skip to content

Commit

Permalink
New configuration UI
Browse files Browse the repository at this point in the history
  • Loading branch information
infeeeee committed Nov 27, 2023
1 parent e84389a commit 48082da
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 346 deletions.
13 changes: 9 additions & 4 deletions IoTuring/ClassManager/ClassManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):
# THIS MUST BE IMPLEMENTED IN SUBCLASSES, IS THE CLASS I WANT TO SEARCH !!!!
self.baseClass = None

def GetClassFromName(self, wantedName):
def GetClassFromName(self, wantedName) -> type:
# From name, load the correct module and extract the class
for module in self.modulesFilename: # Search the module file
moduleName = self.ModuleNameFromPath(module)
Expand All @@ -43,28 +43,33 @@ def GetClassFromName(self, wantedName):
loadedModule = self.LoadModule(module)
# Now get the class
return self.GetClassFromModule(loadedModule)
return None
raise Exception(f"No class found: {wantedName}")

def LoadModule(self, path): # Get module and load it from the path
try:
loader = importlib.machinery.SourceFileLoader(
self.ModuleNameFromPath(path), path)
spec = importlib.util.spec_from_loader(loader.name, loader)

if not spec:
raise Exception("Spec not found")

module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
moduleName = os.path.split(path)[1][:-3]
sys.modules[moduleName] = module
return module
except Exception as e:
self.Log(self.LOG_ERROR, "Error while loading module " +
path + ": " + str(e))
return module

# From the module passed, I search for a Class that has classNmae=moduleName
# From the module passed, I search for a Class that has className=moduleName
def GetClassFromModule(self, module):
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj):
if(name == module.__name__):
return obj
raise Exception(f"No class found: {module.__name__}")

# List files in the _path directory and get only files in subfolders
def GetModulesFilename(self, _path):
Expand Down
Loading

0 comments on commit 48082da

Please sign in to comment.