Skip to content

Commit

Permalink
Add new script to extract patches that also works with %autopatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Sirringhaus committed Jun 10, 2022
1 parent e5addd5 commit 8bc6c70
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions extract_patches.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8bc6c70

Please sign in to comment.