aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-11-04 10:25:21 -0600
committerSimon Glass <sjg@chromium.org>2023-11-14 20:04:00 -0700
commite296a3c73d22bf95f38318a8dac2dc0177a3b145 (patch)
tree10f19df9082e87c2833fc52bb64bf60869e18780 /tools
parent18f8830ab95328431a61960b30bfa1755515e8b9 (diff)
downloadu-boot-e296a3c73d22bf95f38318a8dac2dc0177a3b145.zip
u-boot-e296a3c73d22bf95f38318a8dac2dc0177a3b145.tar.gz
u-boot-e296a3c73d22bf95f38318a8dac2dc0177a3b145.tar.bz2
patman: Move the main program into a function
Add a new run_patman() function to hold the main logic. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/patman/__main__.py127
1 files changed, 67 insertions, 60 deletions
diff --git a/tools/patman/__main__.py b/tools/patman/__main__.py
index 0e559b5..8785029 100755
--- a/tools/patman/__main__.py
+++ b/tools/patman/__main__.py
@@ -30,63 +30,70 @@ from u_boot_pylib import test_util
from u_boot_pylib import tools
-if __name__ != "__main__":
- pass
-
-args = cmdline.parse_args()
-
-if not args.debug:
- sys.tracebacklimit = 0
-
-# Run our meagre tests
-if args.cmd == 'test':
- from patman import func_test
- from patman import test_checkpatch
-
- result = test_util.run_test_suites(
- 'patman', False, False, False, None, None, None,
- [test_checkpatch.TestPatch, func_test.TestFunctional,
- 'gitutil', 'settings'])
-
- 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:
- fd = open(args.cc_cmd, 'r')
- re_line = re.compile('(\S*) (.*)')
- for line in fd.readlines():
- match = re_line.match(line)
- if match and match.group(1) == args.patchfiles[0]:
- for cc in match.group(2).split('\0'):
- cc = cc.strip()
- if cc:
- print(cc)
- fd.close()
-
- elif args.full_help:
- with importlib.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 e:
- terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
- colour=terminal.Color.RED)
- if args.debug:
- print()
- traceback.print_exc()
- ret_code = 1
- sys.exit(ret_code)
+def run_patman():
+ """Run patamn
+
+ This is the main program. It collects arguments and runs either the tests or
+ the control module.
+ """
+ args = cmdline.parse_args()
+
+ if not args.debug:
+ sys.tracebacklimit = 0
+
+ # Run our meagre tests
+ if args.cmd == 'test':
+ from patman import func_test
+ from patman import test_checkpatch
+
+ result = test_util.run_test_suites(
+ 'patman', False, False, False, None, None, None,
+ [test_checkpatch.TestPatch, func_test.TestFunctional,
+ 'gitutil', 'settings'])
+
+ 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:
+ fd = open(args.cc_cmd, 'r')
+ re_line = re.compile('(\S*) (.*)')
+ for line in fd.readlines():
+ match = re_line.match(line)
+ if match and match.group(1) == args.patchfiles[0]:
+ for cc in match.group(2).split('\0'):
+ cc = cc.strip()
+ if cc:
+ print(cc)
+ fd.close()
+
+ elif args.full_help:
+ with importlib.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 e:
+ terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
+ colour=terminal.Color.RED)
+ if args.debug:
+ print()
+ traceback.print_exc()
+ ret_code = 1
+ sys.exit(ret_code)
+
+
+if __name__ == "__main__":
+ sys.exit(run_patman())