Simon Glass | efeac06 | 2019-10-31 07:42:52 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2011 The Chromium OS Authors. |
| 5 | # |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | |
| 7 | """See README for more information""" |
| 8 | |
Jan Kiszka | 6d7c40c | 2023-04-22 16:42:48 +0200 | [diff] [blame] | 9 | try: |
Simon Glass | 66a573b | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 10 | from importlib import resources |
Jan Kiszka | 6d7c40c | 2023-04-22 16:42:48 +0200 | [diff] [blame] | 11 | except ImportError: |
| 12 | # for Python 3.6 |
Simon Glass | 66a573b | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 13 | import importlib_resources as resources |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 14 | import os |
| 15 | import re |
| 16 | import sys |
Simon Glass | dbac716 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 17 | import traceback |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 18 | |
Simon Glass | d1b6ecf | 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 | bdaad40 | 2020-04-17 18:08:52 -0600 | [diff] [blame] | 23 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 24 | # Our modules |
Simon Glass | 22ce641 | 2023-11-04 10:25:20 -0600 | [diff] [blame] | 25 | from patman import cmdline |
Simon Glass | 24725af | 2020-07-05 21:41:49 -0600 | [diff] [blame] | 26 | from patman import control |
Simon Glass | 131444f | 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 | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 30 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 31 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 32 | def run_patman(): |
| 33 | """Run patamn |
Simon Glass | 2b68b36 | 2015-07-30 13:47:41 -0600 | [diff] [blame] | 34 | |
Simon Glass | f42ad6a | 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 | 22ce641 | 2023-11-04 10:25:20 -0600 | [diff] [blame] | 39 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 40 | if not args.debug: |
| 41 | sys.tracebacklimit = 0 |
Simon Glass | dbac716 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 42 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 43 | # Run our meagre tests |
| 44 | if args.cmd == 'test': |
Simon Glass | d1b6ecf | 2023-11-04 10:25:22 -0600 | [diff] [blame] | 45 | # pylint: disable=C0415 |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 46 | from patman import func_test |
| 47 | from patman import test_checkpatch |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 48 | |
Simon Glass | f42ad6a | 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 | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 53 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 54 | sys.exit(0 if result.wasSuccessful() else 1) |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 55 | |
Simon Glass | f42ad6a | 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 | d1b6ecf | 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) |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 70 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 71 | elif args.full_help: |
Simon Glass | 66a573b | 2023-11-04 10:25:24 -0600 | [diff] [blame] | 72 | with resources.path('patman', 'README.rst') as readme: |
Simon Glass | f42ad6a | 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) |
| 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 Glass | d1b6ecf | 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 | f42ad6a | 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 | |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 96 | |
Simon Glass | f42ad6a | 2023-11-04 10:25:21 -0600 | [diff] [blame] | 97 | if __name__ == "__main__": |
| 98 | sys.exit(run_patman()) |