]> arthur.barton.de Git - netdata.git/commitdiff
move module loading to one function
authorpaulfantom <paulfantom@gmail.com>
Mon, 13 Jun 2016 10:34:27 +0000 (12:34 +0200)
committerpaulfantom <paulfantom@gmail.com>
Mon, 13 Jun 2016 10:34:27 +0000 (12:34 +0200)
plugins.d/python.d.plugin

index d68a0ff782c2d6f7869eb8ba144fa2c93f7614e3..d6a415e7d28d0fbad55211303f128dc29b7e5a6c 100755 (executable)
@@ -25,31 +25,13 @@ class PythonCharts(object):
         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)
@@ -90,15 +72,29 @@ class PythonCharts(object):
             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