From 73283e7294c054abedbbc0af477e772497fbcf9f Mon Sep 17 00:00:00 2001 From: paulfantom Date: Mon, 13 Jun 2016 12:46:35 +0200 Subject: [PATCH] distinguish 'private' functions --- plugins.d/python.d.plugin | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins.d/python.d.plugin b/plugins.d/python.d.plugin index d6a415e7..350e5679 100755 --- a/plugins.d/python.d.plugin +++ b/plugins.d/python.d.plugin @@ -29,7 +29,7 @@ class PythonCharts(object): self.configs = modules_configs # load modules - self.modules = self.load_modules(modules_path,modules) + self.modules = self._load_modules(modules_path,modules) # check if loaded modules are on disabled modules list for mod in self.modules: @@ -37,7 +37,7 @@ class PythonCharts(object): self.modules.remove(mod) # load configuration files - self.load_configs() + self._load_configs() # set timetable dict (last execution, next execution and frequency) # set priorities @@ -59,7 +59,7 @@ class PythonCharts(object): 'next' : now - (now % interval) + interval, 'freq' : interval} - def import_plugin(self, path, name=None): + def _import_plugin(self, path, name=None): # try to import module using only its path if name is None: name = path.split('/')[-1] @@ -72,7 +72,7 @@ class PythonCharts(object): debug(str(e)) return None - def load_modules(self, path, modules): + def _load_modules(self, path, modules): # check if plugin directory exists if not os.path.isdir(path): debug("cannot find charts directory ", path) @@ -83,20 +83,20 @@ class PythonCharts(object): loaded = [] if len(modules) > 0: for m in modules: - mod = self.import_plugin(path + m + ".chart.py") + 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) + 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): + def _load_configs(self): # function modifies every loaded module in self.modules for m in self.modules: configfile = self.configs + m.__name__ + ".conf" @@ -110,7 +110,7 @@ class PythonCharts(object): configfile + "' not found. Using defaults.") - def disable_module(self, mod, reason=None): + def _disable_module(self, mod, reason=None): # modifies self.modules self.modules.remove(mod) del self.timetable[mod.__name__] @@ -141,18 +141,18 @@ class PythonCharts(object): for mod in self.modules: try: if not mod.check(): - self.disable_module(mod, "failed check") + self._disable_module(mod, "failed check") except AttributeError: - self.disable_module(mod, "no check") + self._disable_module(mod, "no check") except (UnboundLocalError, Exception) as e: - self.disable_module(mod, "misbehaving. Reason: " + str(e)) + self._disable_module(mod, "misbehaving. Reason: " + str(e)) def create(self): # try to execute create() on every loaded module for mod in self.modules: try: if not mod.create(): - self.disable_module(mod, "failed create") + self._disable_module(mod, "failed create") else: chart = mod.__name__ sys.stdout.write( @@ -166,11 +166,11 @@ class PythonCharts(object): sys.stdout.write("DIMENSION run_time 'run time' absolute 1 1\n\n") sys.stdout.flush() except AttributeError: - self.disable_module(mod, "no create") + self._disable_module(mod, "no create") except (UnboundLocalError, Exception) as e: - self.disable_module(mod, "misbehaving. Reason: " + str(e)) + self._disable_module(mod, "misbehaving. Reason: " + str(e)) - def update_module(self, mod): + def _update_module(self, mod): # try to execute update() on every module and draw run time graph t_start = time.time() # check if it is time to execute module update() function @@ -182,13 +182,13 @@ class PythonCharts(object): else: since_last = int((t_start - self.timetable[mod.__name__]['last']) * 1000000) if not mod.update(since_last): - self.disable_module(mod, "update failed") + self._disable_module(mod, "update failed") return except AttributeError: - self.disable_module(mod, "no update") + self._disable_module(mod, "no update") return except (UnboundLocalError, Exception) as e: - self.disable_module(mod, "misbehaving. Reason: " + str(e)) + self._disable_module(mod, "misbehaving. Reason: " + str(e)) return t_end = time.time() self.timetable[mod.__name__]['next'] = t_end - (t_end % self.timetable[mod.__name__]['freq']) + self.timetable[mod.__name__]['freq'] @@ -211,7 +211,7 @@ class PythonCharts(object): t_begin = time.time() next_runs = [] for mod in self.modules: - self.update_module(mod) + self._update_module(mod) try: next_runs.append(self.timetable[mod.__name__]['next']) except KeyError: -- 2.39.2