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: |
| 10 | import importlib.resources |
| 11 | except ImportError: |
| 12 | # for Python 3.6 |
| 13 | import importlib_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 | bdaad40 | 2020-04-17 18:08:52 -0600 | [diff] [blame] | 19 | if __name__ == "__main__": |
Simon Glass | 4214316 | 2020-04-17 18:09:05 -0600 | [diff] [blame] | 20 | # Allow 'from patman import xxx to work' |
Simon Glass | bdaad40 | 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 | 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 |
Maxim Cournoyer | cda0012 | 2022-12-19 17:32:43 -0500 | [diff] [blame] | 27 | from patman import func_test |
Simon Glass | 131444f | 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 | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 31 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 32 | |
Simon Glass | 2b68b36 | 2015-07-30 13:47:41 -0600 | [diff] [blame] | 33 | if __name__ != "__main__": |
| 34 | pass |
| 35 | |
Simon Glass | 22ce641 | 2023-11-04 10:25:20 -0600 | [diff] [blame^] | 36 | args = cmdline.parse_args() |
| 37 | |
Simon Glass | dbac716 | 2020-07-05 21:41:59 -0600 | [diff] [blame] | 38 | if not args.debug: |
| 39 | sys.tracebacklimit = 0 |
| 40 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 41 | # Run our meagre tests |
Simon Glass | 109e84e | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 42 | if args.cmd == 'test': |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 43 | from patman import func_test |
Simon Glass | c92395b | 2023-02-23 18:18:07 -0700 | [diff] [blame] | 44 | from patman import test_checkpatch |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 45 | |
Alper Nebi Yasak | ca1c588 | 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 | c27d22d | 2022-01-22 05:07:28 -0700 | [diff] [blame] | 48 | [test_checkpatch.TestPatch, func_test.TestFunctional, |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 49 | 'gitutil', 'settings']) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 50 | |
Alper Nebi Yasak | ca1c588 | 2022-04-02 20:06:06 +0300 | [diff] [blame] | 51 | sys.exit(0 if result.wasSuccessful() else 1) |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 52 | |
Simon Glass | 109e84e | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 53 | # Process commits, produce patches files, check them, email them |
| 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() |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 68 | |
Simon Glass | 109e84e | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 69 | elif args.full_help: |
Maxim Cournoyer | 124acc9 | 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 | 109e84e | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 72 | else: |
Simon Glass | 1f975b9 | 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 | 109e84e | 2020-07-05 21:41:55 -0600 | [diff] [blame] | 76 | control.send(args) |
Simon Glass | 3db916d | 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 | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 82 | control.patchwork_status(args.branch, args.count, args.start, args.end, |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 83 | args.dest_branch, args.force, |
Simon Glass | 3d80d79 | 2020-11-03 13:54:15 -0700 | [diff] [blame] | 84 | args.show_comments, args.patchwork_url) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 85 | except Exception as e: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 86 | terminal.tprint('patman: %s: %s' % (type(e).__name__, e), |
Maxim Cournoyer | fcf2e85 | 2022-12-16 20:45:27 -0500 | [diff] [blame] | 87 | colour=terminal.Color.RED) |
Simon Glass | 3db916d | 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) |