#!/usr/bin/env python3 """Naprawia sumy w recepturze util-linux: - suma tarballa 2.42.2 byla pozostaloscia po 2.41.x (stala suma po podbiciu wersji) - suma patcha byla SKIP (brak pliku util-linux-2.42.2-consolidate-1.patch) """ import re import sys import yaml P = "/var/lib/pagan-sync/recipes/core/util-linux/PAGBUILD.yaml" OLD_TAR = "e596083744e746be7d2823b62b43f4418dd7bf56303b4dc09e6fe8112fe3d7ed" NEW_TAR = "03a05d3adf9602ef128f2da05b84b3205ce60c351e5737c0370f74000679ce8a" NEW_PATCH = "aca752c29e3249dbe4320c8178d8c12da8f2207860d71d7232e1210bff1470c8" APPLY = "--apply" in sys.argv text = open(P, newline="", encoding="utf-8").read() before = yaml.safe_load(text) if text.count(OLD_TAR) != 1: print(f"BLAD: oczekiwano 1 wystapienia starej sumy, jest {text.count(OLD_TAR)}") sys.exit(1) new = text.replace(OLD_TAR, NEW_TAR) # podmien pierwszy '- SKIP' w bloku sha256sums na sume patcha m = re.search(r"(?m)^sha256sums:\n((?:- .*\n)+)", new) if not m: print("BLAD: nie znaleziono bloku sha256sums w formacie listy") sys.exit(1) block = m.group(1) if block.count("- SKIP\n") != 1: print(f"BLAD: oczekiwano 1x SKIP w bloku, jest {block.count('- SKIP')}") sys.exit(1) new_block = block.replace("- SKIP\n", f"- {NEW_PATCH}\n", 1) new = new[:m.start(1)] + new_block + new[m.end(1):] after = yaml.safe_load(new) # walidacja src = after["source"] sums = after["sha256sums"] ok = (sums[0] == NEW_TAR and sums[1] == NEW_PATCH and len(src) == len(sums)) other_keys_same = all( before.get(k) == after.get(k) for k in set(before) | set(after) if k != "sha256sums" ) print("pkgver:", after.get("pkgver")) for s, h in zip(src, sums): print(f" {h[:20]}... {s}") print("suma tarballa OK:", sums[0] == NEW_TAR) print("suma patcha OK :", sums[1] == NEW_PATCH) print("pozostale klucze bez zmian:", other_keys_same) if not (ok and other_keys_same): sys.exit(1) if APPLY: with open(P, "w", newline="", encoding="utf-8") as f: f.write(new) print("\nZAPISANO") else: print("\nDRY-RUN (dodaj --apply)")