Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 3 | # Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com> |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 4 | # |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 5 | |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 6 | import os |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 7 | import shlex |
| 8 | import shutil |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 9 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 10 | from patman import gitutil |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 11 | from u_boot_pylib import command |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 12 | |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 13 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 14 | def find_get_maintainer(script_file_name): |
| 15 | """Try to find where `script_file_name` is. |
Simon Glass | c9fa886 | 2020-06-07 06:45:48 -0600 | [diff] [blame] | 16 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 17 | It searches in PATH and falls back to a path relative to the top |
| 18 | of the current git repository. |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 19 | """ |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 20 | get_maintainer = shutil.which(script_file_name) |
| 21 | if get_maintainer: |
| 22 | return get_maintainer |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 23 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 24 | git_relative_script = os.path.join(gitutil.get_top_level(), |
| 25 | script_file_name) |
| 26 | if os.path.exists(git_relative_script): |
| 27 | return git_relative_script |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 28 | |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 29 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 30 | def get_maintainer(script_file_name, fname, verbose=False): |
| 31 | """Run `script_file_name` on a file. |
| 32 | |
| 33 | `script_file_name` should be a get_maintainer.pl-like script that |
| 34 | takes a patch file name as an input and return the email addresses |
| 35 | of the associated maintainers to standard output, one per line. |
| 36 | |
| 37 | If `script_file_name` does not exist we fail silently. |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 38 | |
| 39 | Args: |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 40 | script_file_name: The file name of the get_maintainer.pl script |
| 41 | (or compatible). |
| 42 | fname: File name of the patch to process with get_maintainer.pl. |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 43 | |
| 44 | Returns: |
| 45 | A list of email addresses to CC to. |
| 46 | """ |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 47 | # Expand `script_file_name` into a file name and its arguments, if |
| 48 | # any. |
| 49 | cmd_args = shlex.split(script_file_name) |
| 50 | file_name = cmd_args[0] |
| 51 | arguments = cmd_args[1:] |
| 52 | |
| 53 | get_maintainer = find_get_maintainer(file_name) |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 54 | if not get_maintainer: |
| 55 | if verbose: |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 56 | print("WARNING: Couldn't find get_maintainer.pl") |
Doug Anderson | c2c84bc | 2012-12-03 14:43:16 +0000 | [diff] [blame] | 57 | return [] |
| 58 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 59 | stdout = command.output(get_maintainer, *arguments, fname) |
Stefan BrĂ¼ns | 5d3a5fa | 2017-12-31 23:21:17 +0100 | [diff] [blame] | 60 | lines = stdout.splitlines() |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 61 | return [x.replace('"', '') for x in lines] |