Skip to content

Commit 9ff646e

Browse files
authored
Merge pull request #94 from vmezzela/format-patches-next
Convert format-patches to plugins
2 parents 62016cb + 47101d8 commit 9ff646e

File tree

5 files changed

+84
-70
lines changed

5 files changed

+84
-70
lines changed

klpbuild/klplib/cmd.py

-6
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ def create_parser() -> argparse.ArgumentParser:
8888
add_arg_lp_name(diff_opts)
8989
add_arg_lp_filter(diff_opts)
9090

91-
fmt = sub.add_parser(
92-
"format-patches", help="SLE specific. Extract patches from kgraft-patches"
93-
)
94-
add_arg_lp_name(fmt)
95-
add_arg_lp_filter(fmt)
96-
fmt.add_argument("-v", "--version", type=int, required=True, help="Version to be added, like vX")
9791

9892
patches = sub.add_parser("get-patches")
9993
add_arg_lp_name(patches)

klpbuild/klplib/ksrc.py

-60
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import logging
77
import re
8-
import shutil
98
import subprocess
109
import sys
1110
from datetime import datetime
@@ -47,65 +46,6 @@ def __init__(self, lp_filter):
4746

4847
self.lp_filter = lp_filter
4948

50-
def format_patches(self, lp_name, version):
51-
ver = f"v{version}"
52-
# index 1 will be the test file
53-
index = 2
54-
55-
kgr_patches = get_user_path('kgr_patches_dir')
56-
if not kgr_patches:
57-
logging.warning("kgr_patches_dir not found, patches will be incomplete")
58-
59-
# Remove dir to avoid leftover patches with different names
60-
patches_dir = utils.get_workdir(lp_name)/"patches"
61-
shutil.rmtree(patches_dir, ignore_errors=True)
62-
63-
test_src = utils.get_tests_path(lp_name)
64-
subprocess.check_output(
65-
[
66-
"/usr/bin/git",
67-
"-C",
68-
str(get_user_path('kgr_patches_tests_dir')),
69-
"format-patch",
70-
"-1",
71-
f"{test_src}",
72-
"--cover-letter",
73-
"--start-number",
74-
"1",
75-
"--subject-prefix",
76-
f"PATCH {ver}",
77-
"--output-directory",
78-
f"{patches_dir}",
79-
]
80-
)
81-
82-
# Filter only the branches related to this BSC
83-
for branch in utils.get_lp_branches(lp_name, kgr_patches):
84-
logging.info(branch)
85-
bname = branch.replace(lp_name + "_", "")
86-
bs = " ".join(bname.split("_"))
87-
bsc = lp_name.replace("bsc", "bsc#")
88-
89-
prefix = f"PATCH {ver} {bsc} {bs}"
90-
91-
subprocess.check_output(
92-
[
93-
"/usr/bin/git",
94-
"-C",
95-
str(kgr_patches),
96-
"format-patch",
97-
"-1",
98-
branch,
99-
"--start-number",
100-
f"{index}",
101-
"--subject-prefix",
102-
f"{prefix}",
103-
"--output-directory",
104-
f"{patches_dir}",
105-
]
106-
)
107-
108-
index += 1
10949

11050
# Currently this function returns the date of the patch and it's subject
11151
@staticmethod

klpbuild/klplib/plugins.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def try_run_plugin(name, args):
2828
"""
2929
logging.debug("Trying to run plugin %s", name)
3030

31-
module = __get_plugin(name)
31+
real_name = name.replace("-", "_")
32+
module = __get_plugin(real_name)
3233
assert hasattr(module, "run"), f"Module {name} is not a plugin!"
3334

3435
run_func = getattr(module, "run")

klpbuild/main.py

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ def main():
5050
elif args.cmd == "get-patches":
5151
GitHelper(args.lp_filter).get_commits(args.cve, get_workdir(args.lp_name))
5252

53-
elif args.cmd == "format-patches":
54-
GitHelper(args.lp_filter).format_patches(args.lp_name, args.version)
55-
5653
elif args.cmd == "status":
5754
IBS(args.lp_name, args.lp_filter).status(args.wait)
5855

klpbuild/plugins/format_patches.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Copyright (C) 2021-2025 SUSE
4+
# Author: Marcos Paulo de Souza <[email protected]>
5+
6+
import logging
7+
import shutil
8+
import subprocess
9+
10+
from klpbuild.klplib import utils
11+
from klpbuild.klplib.cmd import add_arg_lp_name
12+
from klpbuild.klplib.config import get_user_path
13+
14+
PLUGIN_CMD = "format-patches"
15+
16+
def register_argparser(subparser):
17+
fmt = subparser.add_parser(
18+
"format-patches", help="SLE specific. Extract patches from kgraft-patches"
19+
)
20+
add_arg_lp_name(fmt)
21+
fmt.add_argument("-v", "--version", type=int, required=True, help="Version to be added, like vX")
22+
23+
24+
def run(lp_name, version):
25+
ver = f"v{version}"
26+
# index 1 will be the test file
27+
index = 2
28+
29+
kgr_patches = get_user_path('kgr_patches_dir')
30+
if not kgr_patches:
31+
logging.warning("kgr_patches_dir not found, patches will be incomplete")
32+
33+
# Remove dir to avoid leftover patches with different names
34+
patches_dir = utils.get_workdir(lp_name)/"patches"
35+
shutil.rmtree(patches_dir, ignore_errors=True)
36+
37+
test_src = utils.get_tests_path(lp_name)
38+
subprocess.check_output(
39+
[
40+
"/usr/bin/git",
41+
"-C",
42+
str(get_user_path('kgr_patches_tests_dir')),
43+
"format-patch",
44+
"-1",
45+
f"{test_src}",
46+
"--cover-letter",
47+
"--start-number",
48+
"1",
49+
"--subject-prefix",
50+
f"PATCH {ver}",
51+
"--output-directory",
52+
f"{patches_dir}",
53+
]
54+
)
55+
56+
# Filter only the branches related to this BSC
57+
for branch in utils.get_lp_branches(lp_name, kgr_patches):
58+
logging.info(branch)
59+
bname = branch.replace(lp_name + "_", "")
60+
bs = " ".join(bname.split("_"))
61+
bsc = lp_name.replace("bsc", "bsc#")
62+
63+
prefix = f"PATCH {ver} {bsc} {bs}"
64+
65+
subprocess.check_output(
66+
[
67+
"/usr/bin/git",
68+
"-C",
69+
str(kgr_patches),
70+
"format-patch",
71+
"-1",
72+
branch,
73+
"--start-number",
74+
f"{index}",
75+
"--subject-prefix",
76+
f"{prefix}",
77+
"--output-directory",
78+
f"{patches_dir}",
79+
]
80+
)
81+
82+
index += 1

0 commit comments

Comments
 (0)