def execute_(self, notification): for schedule in self._schedules: if schedule.name == notification.title(): try: schedule.execute_actions() except: import traceback logutil.error(schedule.name, traceback.format_exc()) schedule.reset()
def timer_callback(self): self._timer = None for schedule in self._schedules: try: schedule.execute() except: import traceback logutil.error(schedule.name, traceback.format_exc()) interval = 60 self._timer = Timer(interval, self.timer_callback) self._timer.start()
def _execute(self): logutil.info(self.name, 'Execute') parameters = {}.copy() for action in self.actions: try: module_name, func_name = action['Name'].split('.') module = import_module('actions.' + module_name) func = getattr(module, func_name) parameters = func(dict(list(parameters.items()) + list(action.get('Parameters', {}).items()))) if parameters is None: parameters = {}.copy() except Exception: import traceback logutil.error(self.name, traceback.format_exc()) traceback.print_exc() logutil.newline() return logutil.info(self.name, 'Success') logutil.newline()
def call(command, cwd=None): _install_package_if_not_exists(command) logutil.info("Execute", " ".join(command)) popen = Popen(command, stdout=PIPE, stderr=PIPE, env=_get_env(), cwd=cwd) out, err = popen.communicate() if popen.returncode != 0: logutil.error("Return Code", popen.returncode) logutil.error("Output", out.decode("utf8", errors="ignore")) logutil.error("Error", err.decode("utf8", errors="ignore")) return popen.returncode, out.decode("utf8", errors="ignore"), err.decode("utf8", errors="ignore")