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: |
| 10 | import importlib.resources |
| 11 | except ImportError: |
| 12 | # for Python 3.6 |
| 13 | import importlib_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 | 0d7a8c4 | 2020-04-17 18:08:52 -0600 | [diff] [blame] | 19 | if __name__ == "__main__": |
Simon Glass | b4fa949 | 2020-04-17 18:09:05 -0600 | [diff] [blame] | 20 | # Allow 'from patman import xxx to work' |
Simon Glass | 0d7a8c4 | 2020-04-17 18:08:52 -0600 | [diff] [blame] | 21 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 22 | sys.path.append(os.path.join(our_path, '..')) |
| 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 |
Maxim Cournoyer | 52c1c33 | 2022-12-19 17:32:43 -0500 | [diff] [blame] | 27 | from patman import func_test |
Simon Glass | 4583c00 | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 28 | from u_boot_pylib import terminal |
| 29 | from u_boot_pylib import test_util |
| 30 | from u_boot_pylib import tools |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 31 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 32 | |
Simon Glass | 9649e15 | 2015-07-30 13:47:41 -0600 | [diff] [blame] | 33 | if __name__ != "__main__": |
| 34 | pass |
| 35 | |
Simon Glass | 18f8830 | 2023-11-04 10:25:20 -0600 | [diff] [blame^] | 36 | args = cmdline.parse_args() |
| 37 | |
Simon Glass | c9360f16 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 38 | if not args.debug: |
| 39 | sys.tracebacklimit = 0 |
| 40 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 41 | # Run our meagre tests |
Simon Glass | 6bb74de | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 42 | if args.cmd == 'test': |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 43 | from patman import func_test |
Simon Glass | a545dc1 | 2023-02-23 18:18:07 -0700 | [diff] [blame] | 44 | from patman import test_checkpatch |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 45 | |
Alper Nebi Yasak | d8318fe | 2022-04-02 20:06:06 +0300 | [diff] [blame] | 46 | result = test_util.run_test_suites( |
| 47 | 'patman', False, False, False, None, None, None, |
Simon Glass | 1d0f30e | 2022-01-22 05:07:28 -0700 | [diff] [blame] | 48 | [test_checkpatch.TestPatch, func_test.TestFunctional, |
Simon Glass | 4583c00 | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 49 | 'gitutil', 'settings']) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 50 | |
Alper Nebi Yasak | d8318fe | 2022-04-02 20:06:06 +0300 | [diff] [blame] | 51 | sys.exit(0 if result.wasSuccessful() else 1) |
Tom Rini | 7208396 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 52 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 53 | # Process commits, produce patches files, check them, email them |
Simon Glass | 6bb74de | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 54 | elif 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 Cournoyer | a5197fc | 2022-12-16 20:45:29 -0500 | [diff] [blame] | 70 | with importlib.resources.path('patman', 'README.rst') as readme: |
| 71 | tools.print_full_help(str(readme)) |
Simon Glass | 6bb74de | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 72 | else: |
Simon Glass | 0fb560d | 2021-01-23 08:56:15 -0700 | [diff] [blame] | 73 | # 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 Glass | 6bb74de | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 76 | control.send(args) |
Simon Glass | dc6df97 | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 77 | |
| 78 | # Check status of patches in patchwork |
| 79 | elif args.cmd == 'status': |
| 80 | ret_code = 0 |
| 81 | try: |
Simon Glass | 8f9ba3a | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 82 | control.patchwork_status(args.branch, args.count, args.start, args.end, |
Simon Glass | dc4b2a9 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 83 | args.dest_branch, args.force, |
Simon Glass | a55be35 | 2020-11-03 13:54:15 -0700 | [diff] [blame] | 84 | args.show_comments, args.patchwork_url) |
Simon Glass | dc6df97 | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 85 | except Exception as e: |
Simon Glass | 098b10f | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 86 | terminal.tprint('patman: %s: %s' % (type(e).__name__, e), |
Maxim Cournoyer | 291ab6c | 2022-12-16 20:45:27 -0500 | [diff] [blame] | 87 | colour=terminal.Color.RED) |
Simon Glass | dc6df97 | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 88 | if args.debug: |
| 89 | print() |
| 90 | traceback.print_exc() |
| 91 | ret_code = 1 |
| 92 | sys.exit(ret_code) |