Loading aurbot +18 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,16 @@ from urllib.request import urlopen, Request # extra import from systemd.daemon import notify def fmt_exc(exc, separator=":"): '''Format a chained exception as a string''' fmt = f"{exc}" exc = exc.__cause__ while exc: fmt += f"{separator} {exc}" exc = exc.__cause__ return fmt class Error(BaseException): '''Error handling.''' Loading Loading @@ -216,7 +226,7 @@ class Package(): # Gentleman quit. con.quit() except Exception as exp: self.error(f"Unable to send message via smtp: {exp}") self.error(f"Unable to send message via smtp: {fmt_exc(exp)}") def send_build_report(self, status, logfile): '''Send build notification.''' Loading Loading @@ -261,7 +271,7 @@ class Package(): try: check_call(cmd, stdin=DEVNULL, stdout=log, stderr=log, shell=True, close_fds=True) except Exception as exp: raise Exception(f"{capname} failure: {exp}") from exp raise Exception(f"{capname} failure") from exp end_time = time() self.info(f"{capname} duration: {end_time - start_time:.2f}s") log.write(f"{capname} duration: {end_time - start_time:.2f}\n") Loading Loading @@ -295,7 +305,7 @@ class Package(): self._local.lastsuccess = self._aur.lastmodified status = "successful" except Exception as exp: self.error(f"Update failure: {exp}") self.error(f"Update failure: {fmt_exc(exp)}") chdir(cwd) # we have to register after chdir in the original directory self._local.lastsuccess = self._aur.lastmodified Loading @@ -313,7 +323,7 @@ class Package(): if self._config.get("maintainer") == str(self._aur.maintainer): self._build() else: self.error(f"Invalid maintainer") self.error("Invalid maintainer") # we notify by mail only once the maintainer is invalid if self._local.lastmaintainer != str(self._aur.maintainer): self.send_maintainer_report() Loading Loading @@ -341,7 +351,7 @@ class Package(): try: self._aur = AURPackage(self.name, self._config.getint("timeout")) except Exception as exp: self.error(f"Unable to get AUR package info: {exp}") self.error(f"Unable to get AUR package info: {fmt_exc(exp)}") return check_delta # few debug printing self.debug(f"AUR last modified: {self._aur.lastmodified}") Loading Loading @@ -436,7 +446,7 @@ class Robot(): if len(self._config.sections()) == 0: raise Error("Empty configuration") except Exception as exp: raise Error(f"Unable to load config file: {exp}") raise Error("Unable to load config file") from exp def start(self): '''Start the robot rock.''' Loading @@ -463,10 +473,10 @@ if __name__ == '__main__': except KeyboardInterrupt: exit(Error.ERR_ABORT) except Error as exp: critical(exp) critical(fmt_exc(exp)) exit(Error.ERR_CRITICAL) except Exception as exp: critical(exp) critical(fmt_exc(exp)) if getLogger().getEffectiveLevel() != DEBUG: error("Unknown error. Please report it with --debug.") else: Loading Loading
aurbot +18 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,16 @@ from urllib.request import urlopen, Request # extra import from systemd.daemon import notify def fmt_exc(exc, separator=":"): '''Format a chained exception as a string''' fmt = f"{exc}" exc = exc.__cause__ while exc: fmt += f"{separator} {exc}" exc = exc.__cause__ return fmt class Error(BaseException): '''Error handling.''' Loading Loading @@ -216,7 +226,7 @@ class Package(): # Gentleman quit. con.quit() except Exception as exp: self.error(f"Unable to send message via smtp: {exp}") self.error(f"Unable to send message via smtp: {fmt_exc(exp)}") def send_build_report(self, status, logfile): '''Send build notification.''' Loading Loading @@ -261,7 +271,7 @@ class Package(): try: check_call(cmd, stdin=DEVNULL, stdout=log, stderr=log, shell=True, close_fds=True) except Exception as exp: raise Exception(f"{capname} failure: {exp}") from exp raise Exception(f"{capname} failure") from exp end_time = time() self.info(f"{capname} duration: {end_time - start_time:.2f}s") log.write(f"{capname} duration: {end_time - start_time:.2f}\n") Loading Loading @@ -295,7 +305,7 @@ class Package(): self._local.lastsuccess = self._aur.lastmodified status = "successful" except Exception as exp: self.error(f"Update failure: {exp}") self.error(f"Update failure: {fmt_exc(exp)}") chdir(cwd) # we have to register after chdir in the original directory self._local.lastsuccess = self._aur.lastmodified Loading @@ -313,7 +323,7 @@ class Package(): if self._config.get("maintainer") == str(self._aur.maintainer): self._build() else: self.error(f"Invalid maintainer") self.error("Invalid maintainer") # we notify by mail only once the maintainer is invalid if self._local.lastmaintainer != str(self._aur.maintainer): self.send_maintainer_report() Loading Loading @@ -341,7 +351,7 @@ class Package(): try: self._aur = AURPackage(self.name, self._config.getint("timeout")) except Exception as exp: self.error(f"Unable to get AUR package info: {exp}") self.error(f"Unable to get AUR package info: {fmt_exc(exp)}") return check_delta # few debug printing self.debug(f"AUR last modified: {self._aur.lastmodified}") Loading Loading @@ -436,7 +446,7 @@ class Robot(): if len(self._config.sections()) == 0: raise Error("Empty configuration") except Exception as exp: raise Error(f"Unable to load config file: {exp}") raise Error("Unable to load config file") from exp def start(self): '''Start the robot rock.''' Loading @@ -463,10 +473,10 @@ if __name__ == '__main__': except KeyboardInterrupt: exit(Error.ERR_ABORT) except Error as exp: critical(exp) critical(fmt_exc(exp)) exit(Error.ERR_CRITICAL) except Exception as exp: critical(exp) critical(fmt_exc(exp)) if getLogger().getEffectiveLevel() != DEBUG: error("Unknown error. Please report it with --debug.") else: Loading