blob: 0e559b5810be40450b1225d4a045ed74b920f734 [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:
10 import importlib.resources
11except ImportError:
12 # for Python 3.6
13 import importlib_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 Glass0d7a8c42020-04-17 18:08:52 -060019if __name__ == "__main__":
Simon Glassb4fa9492020-04-17 18:09:05 -060020 # Allow 'from patman import xxx to work'
Simon Glass0d7a8c42020-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 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
Maxim Cournoyer52c1c332022-12-19 17:32:43 -050027from patman import func_test
Simon Glass4583c002023-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 Glass0d24de92012-01-14 15:12:45 +000031
Simon Glass0d24de92012-01-14 15:12:45 +000032
Simon Glass9649e152015-07-30 13:47:41 -060033if __name__ != "__main__":
34 pass
35
Simon Glass18f88302023-11-04 10:25:20 -060036args = cmdline.parse_args()
37
Simon Glassc9360f162020-07-05 21:41:59 -060038if not args.debug:
39 sys.tracebacklimit = 0
40
Simon Glass0d24de92012-01-14 15:12:45 +000041# Run our meagre tests
Simon Glass6bb74de2020-07-05 21:41:55 -060042if args.cmd == 'test':
Simon Glassbf776672020-04-17 18:09:04 -060043 from patman import func_test
Simon Glassa545dc12023-02-23 18:18:07 -070044 from patman import test_checkpatch
Simon Glass0d24de92012-01-14 15:12:45 +000045
Alper Nebi Yasakd8318fe2022-04-02 20:06:06 +030046 result = test_util.run_test_suites(
47 'patman', False, False, False, None, None, None,
Simon Glass1d0f30e2022-01-22 05:07:28 -070048 [test_checkpatch.TestPatch, func_test.TestFunctional,
Simon Glass4583c002023-02-23 18:18:04 -070049 'gitutil', 'settings'])
Simon Glass0d24de92012-01-14 15:12:45 +000050
Alper Nebi Yasakd8318fe2022-04-02 20:06:06 +030051 sys.exit(0 if result.wasSuccessful() else 1)
Tom Rini72083962020-07-24 08:42:06 -040052
Simon Glass0d24de92012-01-14 15:12:45 +000053# Process commits, produce patches files, check them, email them
Simon Glass6bb74de2020-07-05 21:41:55 -060054elif args.cmd == 'send':
55 # Called from git with a patch filename as argument
56 # Printout a list of additional CC recipients for this patch
57 if args.cc_cmd:
58 fd = open(args.cc_cmd, 'r')
59 re_line = re.compile('(\S*) (.*)')
60 for line in fd.readlines():
61 match = re_line.match(line)
62 if match and match.group(1) == args.patchfiles[0]:
63 for cc in match.group(2).split('\0'):
64 cc = cc.strip()
65 if cc:
66 print(cc)
67 fd.close()
68
69 elif args.full_help:
Maxim Cournoyera5197fc2022-12-16 20:45:29 -050070 with importlib.resources.path('patman', 'README.rst') as readme:
71 tools.print_full_help(str(readme))
Simon Glass6bb74de2020-07-05 21:41:55 -060072 else:
Simon Glass0fb560d2021-01-23 08:56:15 -070073 # If we are not processing tags, no need to warning about bad ones
74 if not args.process_tags:
75 args.ignore_bad_tags = True
Simon Glass6bb74de2020-07-05 21:41:55 -060076 control.send(args)
Simon Glassdc6df972020-10-29 21:46:35 -060077
78# Check status of patches in patchwork
79elif args.cmd == 'status':
80 ret_code = 0
81 try:
Simon Glass8f9ba3a2020-10-29 21:46:36 -060082 control.patchwork_status(args.branch, args.count, args.start, args.end,
Simon Glassdc4b2a92020-10-29 21:46:38 -060083 args.dest_branch, args.force,
Simon Glassa55be352020-11-03 13:54:15 -070084 args.show_comments, args.patchwork_url)
Simon Glassdc6df972020-10-29 21:46:35 -060085 except Exception as e:
Simon Glass098b10f2022-01-29 14:14:18 -070086 terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
Maxim Cournoyer291ab6c2022-12-16 20:45:27 -050087 colour=terminal.Color.RED)
Simon Glassdc6df972020-10-29 21:46:35 -060088 if args.debug:
89 print()
90 traceback.print_exc()
91 ret_code = 1
92 sys.exit(ret_code)