-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new script to extract patches that also works with %autopatch
- Loading branch information
Martin Sirringhaus
committed
Jun 10, 2022
1 parent
e5addd5
commit 8bc6c70
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |