1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2012 The Chromium OS Authors.
3 # Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
10 from patman import gitutil
11 from u_boot_pylib import command
14 def find_get_maintainer(script_file_name):
15 """Try to find where `script_file_name` is.
17 It searches in PATH and falls back to a path relative to the top
18 of the current git repository.
20 get_maintainer = shutil.which(script_file_name)
24 git_relative_script = os.path.join(gitutil.get_top_level(),
26 if os.path.exists(git_relative_script):
27 return git_relative_script
30 def get_maintainer(script_file_name, fname, verbose=False):
31 """Run `script_file_name` on a file.
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.
37 If `script_file_name` does not exist we fail silently.
40 script_file_name: The file name of the get_maintainer.pl script
42 fname: File name of the patch to process with get_maintainer.pl.
45 A list of email addresses to CC to.
47 # Expand `script_file_name` into a file name and its arguments, if
49 cmd_args = shlex.split(script_file_name)
50 file_name = cmd_args[0]
51 arguments = cmd_args[1:]
53 get_maintainer = find_get_maintainer(file_name)
54 if not get_maintainer:
56 print("WARNING: Couldn't find get_maintainer.pl")
59 stdout = command.output(get_maintainer, *arguments, fname)
60 lines = stdout.splitlines()
61 return [x.replace('"', '') for x in lines]