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:
self.modules.remove(mod)
# load configuration files
- self.load_configs()
+ self._load_configs()
# set timetable dict (last execution, next execution and frequency)
# set priorities
'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]
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)
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"
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__]
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(
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
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']
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: