Simon Glass | e3986d9 | 2019-10-31 07:42:52 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2011 The Chromium OS Authors. |
| 5 | # |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | |
| 7 | """See README for more information""" |
| 8 | |
Jan Kiszka | de65b12 | 2023-04-22 16:42:48 +0200 | [diff] [blame] | 9 | try: |
Simon Glass | abf7004 | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 10 | from importlib import resources |
Jan Kiszka | de65b12 | 2023-04-22 16:42:48 +0200 | [diff] [blame] | 11 | except ImportError: |
| 12 | # for Python 3.6 |
Simon Glass | abf7004 | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 13 | import importlib_resources as resources |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 14 | import os |
| 15 | import re |
| 16 | import sys |
Simon Glass | c9360f16 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 17 | import traceback |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 18 | |
Simon Glass | 21229c9 | 2023-11-04 10:25:22 -0600 | [diff] [blame] | 19 | # Allow 'from patman import xxx to work' |
| 20 | # pylint: disable=C0413 |
| 21 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 22 | sys.path.append(os.path.join(our_path, '..')) |
Simon Glass | 0d7a8c4 | 2020-04-17 18:08:52 -0600 | [diff] [blame] | 23 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 24 | # Our modules |
Simon Glass | 18f8830 | 2023-11-04 10:25:20 -0600 | [diff] [blame] | 25 | from patman import cmdline |
Simon Glass | 7d5b04e | 2020-07-05 21:41:49 -0600 | [diff] [blame] | 26 | from patman import control |
Simon Glass | 4583c00 | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 27 | from u_boot_pylib import terminal |
| 28 | from u_boot_pylib import test_util |
| 29 | from u_boot_pylib import tools |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 30 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 31 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 32 | def run_patman(): |
| 33 | """Run patamn |
Simon Glass | 9649e15 | 2015-07-30 13:47:41 -0600 | [diff] [blame] | 34 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 35 | 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 Glass | 18f8830 | 2023-11-04 10:25:20 -0600 | [diff] [blame] | 39 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 40 | if not args.debug: |
| 41 | sys.tracebacklimit = 0 |
Simon Glass | c9360f16 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 42 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 43 | # Run our meagre tests |
| 44 | if args.cmd == 'test': |
Simon Glass | 21229c9 | 2023-11-04 10:25:22 -0600 | [diff] [blame] | 45 | # pylint: disable=C0415 |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 46 | from patman import func_test |
| 47 | from patman import test_checkpatch |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 48 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 49 | 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 Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 53 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 54 | sys.exit(0 if result.wasSuccessful() else 1) |
Tom Rini | 7208396 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 55 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 56 | # 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 Glass | 21229c9 | 2023-11-04 10:25:22 -0600 | [diff] [blame] | 61 | 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 Glass | 6bb74de | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 70 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 71 | elif args.full_help: |
Simon Glass | abf7004 | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 72 | with resources.path('patman', 'README.rst') as readme: |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 73 | 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 Glass | dc6df97 | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 79 | |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 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 Glass | 21229c9 | 2023-11-04 10:25:22 -0600 | [diff] [blame] | 87 | except Exception as exc: |
| 88 | terminal.tprint(f'patman: {type(exc).__name__}: {exc}', |
Simon Glass | e296a3c | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 89 | 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 | |
| 97 | if __name__ == "__main__": |
| 98 | sys.exit(run_patman()) |