#!/usr/bin/python3 -u # # SPDX: GPL-2.0-or-later # # Compare native and mingw RPM packages and report on any differences # in the version, license, url, source and patch fields. import os import os.path import re import subprocess import sys debug = False; refresh = False def run(cmd, **args): if debug: print("CMD: %s" % " ".join(cmd)) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **args) (out, err) = proc.communicate() out = out.decode("utf8").splitlines() err = err.decode("utf8").splitlines() if debug: for line in out: print("STDOUT: %s", line) for line in err: print("STDERR: %s", line) return (out,err) class RPMSpec(object): def __init__(self, name): self.name = name self.sources = [] self.patches = [] self.license = None self.version = None self.url = None self.update_git() self.load_spec() def __repr__(self): rep = ["Package %s" % self.name] rep.append("URL %s" % self.url) rep.append("License %s" % self.license) rep.append("Version %s" % self.version) for src in self.sources: rep.append("Source %s" % src) for patch in self.patches: rep.append("Patch %s" % patch) return "\n".join(rep) def update_git(self): if not os.path.exists(self.name): run(["fedpkg", "clone", self.name]) elif refresh: run(["git", "reset", "--hard"], cwd=self.name) run(["git", "checkout", "master"], cwd=self.name) run(["git", "pull"], cwd=self.name) def load_spec(self): (out, err) = run(["rpmspec", "--parse", self.name + ".spec"], cwd=self.name) for line in out: m = re.match(r'''Version:\s*(.*)''', line) if m: self.version = m.group(1) m = re.match(r'''URL:\s*(.*)''', line) if m: self.url = m.group(1) m = re.match(r'''License:\s*(.*)''', line) if m: self.license = m.group(1) m = re.match(r'''Source\d*:\s*(.*)''', line) if m: self.sources.append(m.group(1)) m = re.match(r'''Patch\d*:\s*(.*)''', line) if m: self.patches.append(m.group(1)) def compare_list(name, label, a, b): errs = False for i in range(min(len(a), len(b))): if a[i] != b[i]: errs = True print("\u001b[34mERROR\u001b[30m %s: %s mismatched %s != %s" % (name, label, a[i], b[i])) if len(a) > len(b): for i in range(len(b), len(a)): errs = True print("\u001b[34mERROR\u001b[30m %s: %s missing %s" % (name, label, a[i])) if len(b) > len(a): for i in range(len(a), len(b)): errs = True print("\u001b[34mERROR\u001b[30m %s: %s extra %s" % (name, label, b[i])) return errs def compare_str(name, label, a, b): if a != b: print("\u001b[34mERROR\u001b[30m %s: %s %s != %s" % (name, label, a, b)) return True return False def compare(native, mingw): errs = False if compare_str(mingw.name, "Version", native.version, mingw.version): errs = True if compare_str(mingw.name, "URL", native.url, mingw.url): errs = True if compare_str(mingw.name, "License", native.license, mingw.license): errs = True if compare_list(mingw.name, "Sources", native.sources, mingw.sources): errs = True if compare_list(mingw.name, "Patches", native.patches, mingw.patches): errs = True return errs anyerrs = False for package in sys.argv[1:]: print("\u001b[33mCHECK\u001b[30m %s" % "mingw-" + package) try: native = RPMSpec(package) except Exception as e: print("\u001b[34mSKIP\u001b[30m %s" % package) continue mingw = RPMSpec("mingw-" + package) if debug: print("%s\n" % native) if debug: print("%s\n" % mingw) errs = compare(native, mingw) if errs: print("\u001b[31mFAIL\u001b[30m %s" % mingw.name) anyerrs = True else: print ("\u001b[32mPASS\u001b[30m %s" % mingw.name) if anyerrs: sys.exit(1) sys.exit(0)