[PATCH 01/30] patman: Move all non-test logic into control module
Simon Glass
sjg at chromium.org
Tue Apr 29 15:21:58 CEST 2025
It is easier for tests if the top-level control logic is all in one
module. Create a new do_patman() function to handle this. Move the
existing code into it.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/patman/__main__.py | 49 ++----------------------------------
tools/patman/control.py | 54 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 49 deletions(-)
diff --git a/tools/patman/__main__.py b/tools/patman/__main__.py
index 36f1c08507c..0d08a53cbab 100755
--- a/tools/patman/__main__.py
+++ b/tools/patman/__main__.py
@@ -6,15 +6,8 @@
"""See README for more information"""
-try:
- from importlib import resources
-except ImportError:
- # for Python 3.6
- import importlib_resources as resources
import os
-import re
import sys
-import traceback
# Allow 'from patman import xxx to work'
# pylint: disable=C0413
@@ -24,9 +17,7 @@ sys.path.append(os.path.join(our_path, '..'))
# Our modules
from patman import cmdline
from patman import control
-from u_boot_pylib import terminal
from u_boot_pylib import test_util
-from u_boot_pylib import tools
def run_patman():
@@ -54,44 +45,8 @@ def run_patman():
sys.exit(0 if result.wasSuccessful() else 1)
# Process commits, produce patches files, check them, email them
- elif args.cmd == 'send':
- # Called from git with a patch filename as argument
- # Printout a list of additional CC recipients for this patch
- if args.cc_cmd:
- re_line = re.compile(r'(\S*) (.*)')
- with open(args.cc_cmd, 'r', encoding='utf-8') as inf:
- for line in inf.readlines():
- match = re_line.match(line)
- if match and match.group(1) == args.patchfiles[0]:
- for cca in match.group(2).split('\0'):
- cca = cca.strip()
- if cca:
- print(cca)
-
- elif args.full_help:
- with resources.path('patman', 'README.rst') as readme:
- tools.print_full_help(str(readme))
- else:
- # If we are not processing tags, no need to warning about bad ones
- if not args.process_tags:
- args.ignore_bad_tags = True
- control.send(args)
-
- # Check status of patches in patchwork
- elif args.cmd == 'status':
- ret_code = 0
- try:
- control.patchwork_status(args.branch, args.count, args.start, args.end,
- args.dest_branch, args.force,
- args.show_comments, args.patchwork_url)
- except Exception as exc:
- terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
- colour=terminal.Color.RED)
- if args.debug:
- print()
- traceback.print_exc()
- ret_code = 1
- sys.exit(ret_code)
+ else:
+ control.do_patman(args)
if __name__ == "__main__":
diff --git a/tools/patman/control.py b/tools/patman/control.py
index b8a45912058..990e07f8766 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -9,12 +9,21 @@ the features of patman.
"""
import os
+import re
import sys
+import traceback
+
+try:
+ from importlib import resources
+except ImportError:
+ # for Python 3.6
+ import importlib_resources as resources
-from patman import checkpatch
-from patman import patchstream
from u_boot_pylib import gitutil
from u_boot_pylib import terminal
+from u_boot_pylib import tools
+from patman import checkpatch
+from patman import patchstream
def setup():
@@ -245,3 +254,44 @@ def patchwork_status(branch, count, start, end, dest_branch, force,
from patman import status
status.check_patchwork_status(series, found[0], branch, dest_branch, force,
show_comments, url)
+
+
+def do_patman(args):
+ if args.cmd == 'send':
+ # Called from git with a patch filename as argument
+ # Printout a list of additional CC recipients for this patch
+ if args.cc_cmd:
+ re_line = re.compile(r'(\S*) (.*)')
+ with open(args.cc_cmd, 'r', encoding='utf-8') as inf:
+ for line in inf.readlines():
+ match = re_line.match(line)
+ if match and match.group(1) == args.patchfiles[0]:
+ for cca in match.group(2).split('\0'):
+ cca = cca.strip()
+ if cca:
+ print(cca)
+
+ elif args.full_help:
+ with resources.path('patman', 'README.rst') as readme:
+ tools.print_full_help(str(readme))
+ else:
+ # If we are not processing tags, no need to warning about bad ones
+ if not args.process_tags:
+ args.ignore_bad_tags = True
+ send(args)
+
+ # Check status of patches in patchwork
+ elif args.cmd == 'status':
+ ret_code = 0
+ try:
+ patchwork_status(args.branch, args.count, args.start, args.end,
+ args.dest_branch, args.force, args.show_comments,
+ args.patchwork_url)
+ except Exception as exc:
+ terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
+ colour=terminal.Color.RED)
+ if args.debug:
+ print()
+ traceback.print_exc()
+ ret_code = 1
+ sys.exit(ret_code)
--
2.43.0
More information about the U-Boot
mailing list