if interval is None:
interval = 1
self.default_priority = 90000
- # check if plugin directory exists
- if not os.path.isdir(modules_path):
- debug("cannot find charts directory ", modules_path)
- sys.stdout.write("DISABLE\n")
- sys.exit(1)
# set configuration directory
self.configs = modules_configs
# load modules
- self.modules = []
- if len(modules) > 0:
- for m in modules:
- mod = self.import_plugin(modules_path + m + ".chart.py")
- if mod is not None:
- self.modules.append(mod)
- else:
- self.autoload_modules(modules_path)
+ self.modules = self.load_modules(modules_path,modules)
- # check if there are any modules loaded
- if len(self.modules) == 0:
- debug("cannot find modules", modules_path)
- sys.stdout.write("DISABLE\n")
- sys.exit(1)
-
- # check if loaded modules is on disabled modules list
+ # check if loaded modules are on disabled modules list
for mod in self.modules:
if mod.__name__ in modules_disabled:
self.modules.remove(mod)
debug(str(e))
return None
- def autoload_modules(self, path):
- # scan directory specified in path and load all modules from there
- # function modifies self.modules
- names = os.listdir(path)
- for mod in names:
- m = self.import_plugin(path + mod)
- if m is not None:
- debug("loading chart: '" + path + mod + "'")
- self.modules.append(m)
+ def load_modules(self, path, modules):
+ # check if plugin directory exists
+ if not os.path.isdir(path):
+ debug("cannot find charts directory ", path)
+ sys.stdout.write("DISABLE\n")
+ sys.exit(1)
+
+ # load modules
+ loaded = []
+ if len(modules) > 0:
+ for m in modules:
+ mod = self.import_plugin(path + m + ".chart.py")
+ if mod is not None:
+ loaded.append(mod)
+ else:
+ # scan directory specified in path and load all modules from there
+ names = os.listdir(path)
+ for mod in names:
+ m = self.import_plugin(path + mod)
+ if m is not None:
+ debug("loading chart: '" + path + mod + "'")
+ loaded.append(m)
+ return loaded
def load_configs(self):
# function modifies every loaded module in self.modules