|
@@ -23,6 +23,8 @@ import isc.util.process
|
|
|
import signal
|
|
|
import os
|
|
|
from optparse import OptionParser
|
|
|
+import glob
|
|
|
+import os.path
|
|
|
|
|
|
isc.util.process.rename()
|
|
|
|
|
@@ -66,7 +68,26 @@ def signal_handler(signal, frame):
|
|
|
cm.running = False
|
|
|
|
|
|
def load_plugins(path, cm):
|
|
|
- pass
|
|
|
+ """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)
|
|
|
+ try:
|
|
|
+ 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)
|
|
|
+ finally:
|
|
|
+ # Restore the search path
|
|
|
+ sys.path = sys.path[1:]
|
|
|
|
|
|
def main():
|
|
|
options = parse_options()
|