Commit e58e69f0 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac810] Plugin loader

parent b91c7c25
......@@ -23,6 +23,8 @@ import isc.util.process
import signal
import os
from optparse import OptionParser
import glob
import os.path
......@@ -66,7 +68,26 @@ def signal_handler(signal, frame):
cm.running = False
def load_plugins(path, cm):
"""Load all python files in the given path and treat them as plugins."""
# Find the python files
plugins = glob.glob(path + os.sep + '*.py')
# Search this directory first, but leave the others there for the imports
# of the modules
sys.path.insert(0, path)
for plugin in plugins:
# Generate the name of the plugin
filename = os.path.basename(plugin)
name = filename[:-3]
# Load it
module = __import__(name)
# Ask it to provide the spec and checking function
(spec, check_func) = module.load()
# And insert it into the manager
cm.set_virtual_module(spec, check_func)
# Restore the search path
sys.path = sys.path[1:]
def main():
options = parse_options()
......@@ -23,7 +23,7 @@ class MockSpec:
def get_module_name(self):
return "mock_config_plugin"
def mock_check_config(config)
def mock_check_config(config):
"""Mock function to check config. Does nothing, only returns
an "error" string to indicate it's this one."""
return "Mock config plugin"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment