Last active
November 19, 2015 01:34
-
-
Save CreateRemoteThread/c4f8bbc7a064553c0ecf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# plugins.py | |
import os | |
import imp | |
class pluginLoader: | |
def __init__(self,modDirectory): | |
self.pluginList = {} | |
self.modules = {} | |
self.moduleDirectory = modDirectory | |
for dirname, dirnames, filenames in os.walk(self.moduleDirectory): | |
for filename in filenames: | |
if filename.endswith(".py"): | |
moduleName = filename.replace(".py","") | |
info = imp.find_module(moduleName,[dirname]) | |
self.pluginList[moduleName] = info | |
self.modules[moduleName] = imp.load_module(moduleName,*self.pluginList[moduleName]) | |
# allow dynamic loading... | |
def loadModule(self,moduleName): | |
self.pluginList = {} | |
for dirname, dirnames, filenames in os.walk(self.moduleDirectory): | |
for filename in filenames: | |
if filename.endswith(".py"): | |
info = imp.find_module(moduleName,[dirname]) | |
self.pluginList[moduleName] = info | |
if moduleName not in self.pluginList.keys(): | |
raise BaseException("pluginLoader: module %s not found" % moduleName) | |
newModule = imp.load_module(moduleName,*self.pluginList[moduleName]) | |
newModule.run() | |
self.modules[moduleName] = newModule | |
return newModule | |
def keys(self): | |
return self.pluginList.keys() | |
def listModules(self): | |
return self.pluginList.keys() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment