From 8bc6c7018cd0a80be4e49034e9d5c8edd5816ca2 Mon Sep 17 00:00:00 2001 From: Martin Sirringhaus <> Date: Fri, 10 Jun 2022 11:01:54 +0200 Subject: [PATCH] Add new script to extract patches that also works with %autopatch --- extract_patches.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 extract_patches.py diff --git a/extract_patches.py b/extract_patches.py new file mode 100755 index 0000000..2557712 --- /dev/null +++ b/extract_patches.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import sys +from collections import OrderedDict + +def print_usage_and_exit(): + print("Usage: {0} /path/to/some.spec".format(sys.argv[0])) + print(" Extracts the patches in the applied order from a spec-file") + exit(1) + + +def main(): + if len(sys.argv) != 2: + print_usage_and_exit() + + spec_file = sys.argv[1]; + + patch_names = OrderedDict() + applied_patches = [] + in_prep = False + for line in open(spec_file): + if not in_prep and line.startswith("Patch"): + first, second = line.split(); + patch_num = int(first[5:-1]) + patch_name = second.strip() + patch_names[patch_num] = patch_name + + if line.startswith("%prep"): + in_prep = True + + # Newer spec-files have autopatch, so we can print all in order and stop + if in_prep and line.startswith("%autopatch"): + for patch in patch_names.values(): + print(patch); + return; + + if in_prep and line.startswith("%patch"): + num = int(line.split()[0][6:]) + applied_patches.append(patch_names[num]) + + # Once we enter %build, all patches have been read and can be printed + if in_prep and line.startswith("%build"): + for patch in applied_patches: + print(patch); + return; + +if __name__ == "__main__": + main() \ No newline at end of file