blob: f645b38b6470542ea7b31a54167861eecc943b40 [file] [log] [blame]
Simon Glasse3986d92019-10-31 07:42:52 -06001#!/usr/bin/env python3
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +00003#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
Simon Glass0d24de92012-01-14 15:12:45 +00006
7"""See README for more information"""
8
Jan Kiszkade65b122023-04-22 16:42:48 +02009try:
Simon Glassabf70042023-11-04 10:25:24 -060010 from importlib import resources
Jan Kiszkade65b122023-04-22 16:42:48 +020011except ImportError:
12 # for Python 3.6
Simon Glassabf70042023-11-04 10:25:24 -060013 import importlib_resources as resources
Simon Glass0d24de92012-01-14 15:12:45 +000014import os
15import re
16import sys
Simon Glassc9360f162020-07-05 21:41:59 -060017import traceback
Simon Glass0d24de92012-01-14 15:12:45 +000018
Simon Glass21229c92023-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 Glass0d7a8c42020-04-17 18:08:52 -060023
Simon Glass0d24de92012-01-14 15:12:45 +000024# Our modules
Simon Glass18f88302023-11-04 10:25:20 -060025from patman import cmdline
Simon Glass7d5b04e2020-07-05 21:41:49 -060026from patman import control
Simon Glass4583c002023-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 Glass0d24de92012-01-14 15:12:45 +000030
Simon Glass0d24de92012-01-14 15:12:45 +000031
Simon Glasse296a3c2023-11-04 10:25:21 -060032def run_patman():
33 """Run patamn
Simon Glass9649e152015-07-30 13:47:41 -060034
Simon Glasse296a3c2023-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 Glass18f88302023-11-04 10:25:20 -060039
Simon Glasse296a3c2023-11-04 10:25:21 -060040 if not args.debug:
41 sys.tracebacklimit = 0
Simon Glassc9360f162020-07-05 21:41:59 -060042
Simon Glasse296a3c2023-11-04 10:25:21 -060043 # Run our meagre tests
44 if args.cmd == 'test':
Simon Glass21229c92023-11-04 10:25:22 -060045 # pylint: disable=C0415
Simon Glasse296a3c2023-11-04 10:25:21 -060046 from patman import func_test
47 from patman import test_checkpatch
Simon Glass0d24de92012-01-14 15:12:45 +000048
Simon Glasse296a3c2023-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 Glass0d24de92012-01-14 15:12:45 +000053
Simon Glasse296a3c2023-11-04 10:25:21 -060054 sys.exit(0 if result.wasSuccessful() else 1)
Tom Rini72083962020-07-24 08:42:06 -040055
Simon Glasse296a3c2023-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 Glass21229c92023-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)
Simon Glass6bb74de2020-07-05 21:41:55 -060070
Simon Glasse296a3c2023-11-04 10:25:21 -060071 elif args.full_help:
Simon Glassabf70042023-11-04 10:25:24 -060072 with resources.path('patman', 'README.rst') as readme:
Simon Glasse296a3c2023-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)
Simon Glassdc6df972020-10-29 21:46:35 -060079
Simon Glasse296a3c2023-11-04 10:25:21 -060080 # 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 Glass21229c92023-11-04 10:25:22 -060087 except Exception as exc:
88 terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
Simon Glasse296a3c2023-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
96
97if __name__ == "__main__":
98 sys.exit(run_patman())