blob: f645b38b6470542ea7b31a54167861eecc943b40 [file] [log] [blame]
Simon Glassefeac062019-10-31 07:42:52 -06001#!/usr/bin/env python3
Tom Rini10e47792018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass26132882012-01-14 15:12:45 +00003#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
Simon Glass26132882012-01-14 15:12:45 +00006
7"""See README for more information"""
8
Jan Kiszka6d7c40c2023-04-22 16:42:48 +02009try:
Simon Glass66a573b2023-11-04 10:25:24 -060010 from importlib import resources
Jan Kiszka6d7c40c2023-04-22 16:42:48 +020011except ImportError:
12 # for Python 3.6
Simon Glass66a573b2023-11-04 10:25:24 -060013 import importlib_resources as resources
Simon Glass26132882012-01-14 15:12:45 +000014import os
15import re
16import sys
Simon Glassdbac7162020-07-05 21:41:59 -060017import traceback
Simon Glass26132882012-01-14 15:12:45 +000018
Simon Glassd1b6ecf2023-11-04 10:25:22 -060019# Allow 'from patman import xxx to work'
20# pylint: disable=C0413
21our_path = os.path.dirname(os.path.realpath(__file__))
22sys.path.append(os.path.join(our_path, '..'))
Simon Glassbdaad402020-04-17 18:08:52 -060023
Simon Glass26132882012-01-14 15:12:45 +000024# Our modules
Simon Glass22ce6412023-11-04 10:25:20 -060025from patman import cmdline
Simon Glass24725af2020-07-05 21:41:49 -060026from patman import control
Simon Glass131444f2023-02-23 18:18:04 -070027from u_boot_pylib import terminal
28from u_boot_pylib import test_util
29from u_boot_pylib import tools
Simon Glass26132882012-01-14 15:12:45 +000030
Simon Glass26132882012-01-14 15:12:45 +000031
Simon Glassf42ad6a2023-11-04 10:25:21 -060032def run_patman():
33 """Run patamn
Simon Glass2b68b362015-07-30 13:47:41 -060034
Simon Glassf42ad6a2023-11-04 10:25:21 -060035 This is the main program. It collects arguments and runs either the tests or
36 the control module.
37 """
38 args = cmdline.parse_args()
Simon Glass22ce6412023-11-04 10:25:20 -060039
Simon Glassf42ad6a2023-11-04 10:25:21 -060040 if not args.debug:
41 sys.tracebacklimit = 0
Simon Glassdbac7162020-07-05 21:41:59 -060042
Simon Glassf42ad6a2023-11-04 10:25:21 -060043 # Run our meagre tests
44 if args.cmd == 'test':
Simon Glassd1b6ecf2023-11-04 10:25:22 -060045 # pylint: disable=C0415
Simon Glassf42ad6a2023-11-04 10:25:21 -060046 from patman import func_test
47 from patman import test_checkpatch
Simon Glass26132882012-01-14 15:12:45 +000048
Simon Glassf42ad6a2023-11-04 10:25:21 -060049 result = test_util.run_test_suites(
50 'patman', False, False, False, None, None, None,
51 [test_checkpatch.TestPatch, func_test.TestFunctional,
52 'gitutil', 'settings'])
Simon Glass26132882012-01-14 15:12:45 +000053
Simon Glassf42ad6a2023-11-04 10:25:21 -060054 sys.exit(0 if result.wasSuccessful() else 1)
Tom Rini5a9ecb22020-07-24 08:42:06 -040055
Simon Glassf42ad6a2023-11-04 10:25:21 -060056 # Process commits, produce patches files, check them, email them
57 elif args.cmd == 'send':
58 # Called from git with a patch filename as argument
59 # Printout a list of additional CC recipients for this patch
60 if args.cc_cmd:
Simon Glassd1b6ecf2023-11-04 10:25:22 -060061 re_line = re.compile(r'(\S*) (.*)')
62 with open(args.cc_cmd, 'r', encoding='utf-8') as inf:
63 for line in inf.readlines():
64 match = re_line.match(line)
65 if match and match.group(1) == args.patchfiles[0]:
66 for cca in match.group(2).split('\0'):
67 cca = cca.strip()
68 if cca:
69 print(cca)
Tom Rini5a9ecb22020-07-24 08:42:06 -040070
Simon Glassf42ad6a2023-11-04 10:25:21 -060071 elif args.full_help:
Simon Glass66a573b2023-11-04 10:25:24 -060072 with resources.path('patman', 'README.rst') as readme:
Simon Glassf42ad6a2023-11-04 10:25:21 -060073 tools.print_full_help(str(readme))
74 else:
75 # If we are not processing tags, no need to warning about bad ones
76 if not args.process_tags:
77 args.ignore_bad_tags = True
78 control.send(args)
79
80 # Check status of patches in patchwork
81 elif args.cmd == 'status':
82 ret_code = 0
83 try:
84 control.patchwork_status(args.branch, args.count, args.start, args.end,
85 args.dest_branch, args.force,
86 args.show_comments, args.patchwork_url)
Simon Glassd1b6ecf2023-11-04 10:25:22 -060087 except Exception as exc:
88 terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
Simon Glassf42ad6a2023-11-04 10:25:21 -060089 colour=terminal.Color.RED)
90 if args.debug:
91 print()
92 traceback.print_exc()
93 ret_code = 1
94 sys.exit(ret_code)
95
Simon Glass3db916d2020-10-29 21:46:35 -060096
Simon Glassf42ad6a2023-11-04 10:25:21 -060097if __name__ == "__main__":
98 sys.exit(run_patman())