Skip to content

Instantly share code, notes, and snippets.

@CreateRemoteThread
Last active November 19, 2015 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CreateRemoteThread/c4f8bbc7a064553c0ecf to your computer and use it in GitHub Desktop.
Save CreateRemoteThread/c4f8bbc7a064553c0ecf to your computer and use it in GitHub Desktop.
#!/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