distinguish 'private' functions
paulfantom committed
Jun 13, 2016 at 12:46 UTC
73283e7294c054abedbbc0af477e772497fbcf9f
1 file changed
+19
-19
plugins.d/python.d.plugin
+19
-19
@@ -29,7 +29,7 @@ class PythonCharts(object):
29
self.configs = modules_configs
30
31
# load modules
32
- self.modules = self.load_modules(modules_path,modules)
32
+ self.modules = self._load_modules(modules_path,modules)
33
34
# check if loaded modules are on disabled modules list
35
for mod in self.modules:
@@ -37,7 +37,7 @@ class PythonCharts(object):
37
self.modules.remove(mod)
38
39
# load configuration files
40
- self.load_configs()
40
+ self._load_configs()
41
42
# set timetable dict (last execution, next execution and frequency)
43
# set priorities
@@ -59,7 +59,7 @@ class PythonCharts(object):
59
'next' : now - (now % interval) + interval,
60
'freq' : interval}
61
62
- def import_plugin(self, path, name=None):
62
+ def _import_plugin(self, path, name=None):
63
# try to import module using only its path
64
if name is None:
65
name = path.split('/')[-1]
@@ -72,7 +72,7 @@ class PythonCharts(object):
72
debug(str(e))
73
return None
74
75
- def load_modules(self, path, modules):
75
+ def _load_modules(self, path, modules):
76
# check if plugin directory exists
77
if not os.path.isdir(path):
78
debug("cannot find charts directory ", path)
@@ -83,20 +83,20 @@ class PythonCharts(object):
83
loaded = []
84
if len(modules) > 0:
85
for m in modules:
86
- mod = self.import_plugin(path + m + ".chart.py")
86
+ mod = self._import_plugin(path + m + ".chart.py")
87
if mod is not None:
88
loaded.append(mod)
89
else:
90
# scan directory specified in path and load all modules from there
91
names = os.listdir(path)
92
for mod in names:
93
- m = self.import_plugin(path + mod)
93
+ m = self._import_plugin(path + mod)
94
if m is not None:
95
debug("loading chart: '" + path + mod + "'")
96
loaded.append(m)
97
return loaded
98
99
- def load_configs(self):
99
+ def _load_configs(self):
100
# function modifies every loaded module in self.modules
101
for m in self.modules:
102
configfile = self.configs + m.__name__ + ".conf"
@@ -110,7 +110,7 @@ class PythonCharts(object):
110
configfile +
111
"' not found. Using defaults.")
112
113
- def disable_module(self, mod, reason=None):
113
+ def _disable_module(self, mod, reason=None):
114
# modifies self.modules
115
self.modules.remove(mod)
116
del self.timetable[mod.__name__]
@@ -141,18 +141,18 @@ class PythonCharts(object):
141
for mod in self.modules:
142
try:
143
if not mod.check():
144
- self.disable_module(mod, "failed check")
144
+ self._disable_module(mod, "failed check")
145
except AttributeError:
146
- self.disable_module(mod, "no check")
146
+ self._disable_module(mod, "no check")
147
except (UnboundLocalError, Exception) as e:
148
- self.disable_module(mod, "misbehaving. Reason: " + str(e))
148
+ self._disable_module(mod, "misbehaving. Reason: " + str(e))
149
150
def create(self):
151
# try to execute create() on every loaded module
152
for mod in self.modules:
153
try:
154
if not mod.create():
155
- self.disable_module(mod, "failed create")
155
+ self._disable_module(mod, "failed create")
156
else:
157
chart = mod.__name__
158
sys.stdout.write(
@@ -166,11 +166,11 @@ class PythonCharts(object):
166
sys.stdout.write("DIMENSION run_time 'run time' absolute 1 1\n\n")
167
sys.stdout.flush()
168
except AttributeError:
169
- self.disable_module(mod, "no create")
169
+ self._disable_module(mod, "no create")
170
except (UnboundLocalError, Exception) as e:
171
- self.disable_module(mod, "misbehaving. Reason: " + str(e))
171
+ self._disable_module(mod, "misbehaving. Reason: " + str(e))
172
173
- def update_module(self, mod):
173
+ def _update_module(self, mod):
174
# try to execute update() on every module and draw run time graph
175
t_start = time.time()
176
# check if it is time to execute module update() function
@@ -182,13 +182,13 @@ class PythonCharts(object):
182
else:
183
since_last = int((t_start - self.timetable[mod.__name__]['last']) * 1000000)
184
if not mod.update(since_last):
185
- self.disable_module(mod, "update failed")
185
+ self._disable_module(mod, "update failed")
186
return
187
except AttributeError:
188
- self.disable_module(mod, "no update")
188
+ self._disable_module(mod, "no update")
189
return
190
except (UnboundLocalError, Exception) as e:
191
- self.disable_module(mod, "misbehaving. Reason: " + str(e))
191
+ self._disable_module(mod, "misbehaving. Reason: " + str(e))
192
return
193
t_end = time.time()
194
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):
211
t_begin = time.time()
212
next_runs = []
213
for mod in self.modules:
214
- self.update_module(mod)
214
+ self._update_module(mod)
215
try:
216
next_runs.append(self.timetable[mod.__name__]['next'])
217
except KeyError: