blob: 87850295e7049a159d77b71081cc7ee001cf8042 [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:
10 import importlib.resources
11except ImportError:
12 # for Python 3.6
13 import importlib_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 Glassbdaad402020-04-17 18:08:52 -060019if __name__ == "__main__":
Simon Glass42143162020-04-17 18:09:05 -060020 # Allow 'from patman import xxx to work'
Simon Glassbdaad402020-04-17 18:08:52 -060021 our_path = os.path.dirname(os.path.realpath(__file__))
22 sys.path.append(os.path.join(our_path, '..'))
23
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
Maxim Cournoyercda00122022-12-19 17:32:43 -050027from patman import func_test
Simon Glass131444f2023-02-23 18:18:04 -070028from u_boot_pylib import terminal
29from u_boot_pylib import test_util
30from u_boot_pylib import tools
Simon Glass26132882012-01-14 15:12:45 +000031
Simon Glass26132882012-01-14 15:12:45 +000032
Simon Glassf42ad6a2023-11-04 10:25:21 -060033def run_patman():
34 """Run patamn
Simon Glass2b68b362015-07-30 13:47:41 -060035
Simon Glassf42ad6a2023-11-04 10:25:21 -060036 This is the main program. It collects arguments and runs either the tests or
37 the control module.
38 """
39 args = cmdline.parse_args()
Simon Glass22ce6412023-11-04 10:25:20 -060040
Simon Glassf42ad6a2023-11-04 10:25:21 -060041 if not args.debug:
42 sys.tracebacklimit = 0
Simon Glassdbac7162020-07-05 21:41:59 -060043
Simon Glassf42ad6a2023-11-04 10:25:21 -060044 # Run our meagre tests
45 if args.cmd == 'test':
46 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:
61 fd = open(args.cc_cmd, 'r')
62 re_line = re.compile('(\S*) (.*)')
63 for line in fd.readlines():
64 match = re_line.match(line)
65 if match and match.group(1) == args.patchfiles[0]:
66 for cc in match.group(2).split('\0'):
67 cc = cc.strip()
68 if cc:
69 print(cc)
70 fd.close()
Tom Rini5a9ecb22020-07-24 08:42:06 -040071
Simon Glassf42ad6a2023-11-04 10:25:21 -060072 elif args.full_help:
73 with importlib.resources.path('patman', 'README.rst') as readme:
74 tools.print_full_help(str(readme))
75 else:
76 # If we are not processing tags, no need to warning about bad ones
77 if not args.process_tags:
78 args.ignore_bad_tags = True
79 control.send(args)
80
81 # Check status of patches in patchwork
82 elif args.cmd == 'status':
83 ret_code = 0
84 try:
85 control.patchwork_status(args.branch, args.count, args.start, args.end,
86 args.dest_branch, args.force,
87 args.show_comments, args.patchwork_url)
88 except Exception as e:
89 terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
90 colour=terminal.Color.RED)
91 if args.debug:
92 print()
93 traceback.print_exc()
94 ret_code = 1
95 sys.exit(ret_code)
96
Simon Glass3db916d2020-10-29 21:46:35 -060097
Simon Glassf42ad6a2023-11-04 10:25:21 -060098if __name__ == "__main__":
99 sys.exit(run_patman())