From 36bcdd092fb53464a1be490120c6d5a272c53426 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Thu, 13 Aug 2020 12:02:38 +0200 Subject: [PATCH] improved logging --- master.py | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/master.py b/master.py index f799dff..09690a2 100644 --- a/master.py +++ b/master.py @@ -64,7 +64,8 @@ def build(pkgbuild, repo): os.chdir(pathlib.Path(pkgbuild).parent) res = subprocess.run(["sudo", "extra-x86_64-build"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if res.returncode: - logging.warning("[%s/%s] Build failed: %s", repo, name, res) + logging.warning("[%s/%s] Build failed. Check repo/logs for more information.", repo, name) + # write packagename to failed list with open(os.path.join(config["basedir"]["repo"], repo + "_failed.txt"), "a") as f: f.write(name + "\n") @@ -72,21 +73,23 @@ def build(pkgbuild, repo): # write logs to file if not os.path.exists(os.path.join(config["basedir"]["repo"], "logs", repo)): pathlib.Path(os.path.join(config["basedir"]["repo"], "logs", repo)).mkdir(parents=True, exist_ok=True) - with open(os.path.join(config["basedir"]["repo"], "logs", repo, name + ".log"), "w") as log: log.write(res.stdout.decode()) - subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir(sys.path[0]) return # signing pkgs = glob.glob("*.pkg.tar.zst") for pkg in pkgs: - s_res = subprocess.run(["gpg", "--batch", "--detach-sign", pkg], capture_output=True) + s_res = subprocess.run(["gpg", "--batch", "--detach-sign", pkg], stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) if s_res.returncode: - logging.error("[%s/%s] Signing failed: %s", repo, name, s_res) - subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True) + logging.error("[%s/%s] Signing failed: %s", repo, name, s_res.stdout.decode()) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir(sys.path[0]) return @@ -100,24 +103,27 @@ def build(pkgbuild, repo): # repo r_res = subprocess.run(["repo-add", "-s", "-v", os.path.join(config["basedir"]["repo"], repo, "os", config["arch"], repo + ".db.tar.xz"), - pkgs[0]], capture_output=True) + pkgs[0]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if r_res.returncode: - logging.error("[%s/%s] Repo action failed: %s", repo, name, r_res) - subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True) + logging.error("[%s/%s] Repo action failed: %s", repo, name, r_res.stdout.decode()) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir(sys.path[0]) return p_res = subprocess.run( ["paccache", "-rc", os.path.join(config["basedir"]["repo"], repo, "os", config["arch"]), "-k", "1"], - capture_output=True) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if p_res.returncode: - logging.error("[%s/%s] Repo cleanup failed: %s", repo, name, p_res) - subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True) + logging.error("[%s/%s] Repo cleanup failed: %s", repo, name, p_res.stdout.decode()) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir(sys.path[0]) return # cleanup - subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir(sys.path[0]) logging.info("[%s/%s] Build successful (%s)", repo, name, time.time() - start_time) @@ -147,8 +153,11 @@ def import_keys(pkgbuild): k = k.replace("'", "") k = k.replace("\"", "") if len(k) == 40: - logging.debug(subprocess.run( - ["gpg", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", k], capture_output=True)) + logging.debug("[GPG] %s", + subprocess.run( + ["gpg", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", k], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) logging.info("[GPG] Imported key %s", k) @@ -160,13 +169,15 @@ def package_exists(name, repo): def update_git2svn(): if not os.path.exists(config["basedir"]["svn2git"]): - logging.debug(subprocess.run( + logging.debug("[GIT] %s", subprocess.run( ["git", "clone", "https://github.com/archlinux/svntogit-packages.git", config["basedir"]["svn2git"]], - check=True, capture_output=True)) + check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()) else: os.chdir(config["basedir"]["svn2git"]) - logging.debug(subprocess.run(["git", "clean", "-xdf"], check=True, capture_output=True)) - logging.debug(subprocess.run(["git", "pull"], check=True, capture_output=True)) + logging.debug("[GIT] %s", subprocess.run(["git", "clean", "-xdf"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) + logging.debug("[GIT] %s", subprocess.run(["git", "pull"], check=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT).stdout.decode()) os.chdir("..")