2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2012-12-03 14:43:16 +00:00
|
|
|
# Copyright (c) 2012 The Chromium OS Authors.
|
2022-12-20 05:28:46 +00:00
|
|
|
# Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
|
2012-12-03 14:43:16 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2022-12-20 05:28:46 +00:00
|
|
|
import shlex
|
|
|
|
import shutil
|
2012-12-03 14:43:16 +00:00
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
from patman import gitutil
|
2023-02-24 01:18:04 +00:00
|
|
|
from u_boot_pylib import command
|
2020-04-18 00:09:04 +00:00
|
|
|
|
2012-12-03 14:43:16 +00:00
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
def find_get_maintainer(script_file_name):
|
|
|
|
"""Try to find where `script_file_name` is.
|
2020-06-07 12:45:48 +00:00
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
It searches in PATH and falls back to a path relative to the top
|
|
|
|
of the current git repository.
|
2012-12-03 14:43:16 +00:00
|
|
|
"""
|
2022-12-20 05:28:46 +00:00
|
|
|
get_maintainer = shutil.which(script_file_name)
|
|
|
|
if get_maintainer:
|
|
|
|
return get_maintainer
|
|
|
|
|
|
|
|
git_relative_script = os.path.join(gitutil.get_top_level(),
|
|
|
|
script_file_name)
|
|
|
|
if os.path.exists(git_relative_script):
|
|
|
|
return git_relative_script
|
2012-12-03 14:43:16 +00:00
|
|
|
|
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
def get_maintainer(script_file_name, fname, verbose=False):
|
|
|
|
"""Run `script_file_name` on a file.
|
2012-12-03 14:43:16 +00:00
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
`script_file_name` should be a get_maintainer.pl-like script that
|
|
|
|
takes a patch file name as an input and return the email addresses
|
|
|
|
of the associated maintainers to standard output, one per line.
|
|
|
|
|
|
|
|
If `script_file_name` does not exist we fail silently.
|
2012-12-03 14:43:16 +00:00
|
|
|
|
|
|
|
Args:
|
2022-12-20 05:28:46 +00:00
|
|
|
script_file_name: The file name of the get_maintainer.pl script
|
|
|
|
(or compatible).
|
|
|
|
fname: File name of the patch to process with get_maintainer.pl.
|
2012-12-03 14:43:16 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of email addresses to CC to.
|
|
|
|
"""
|
2022-12-20 05:28:46 +00:00
|
|
|
# Expand `script_file_name` into a file name and its arguments, if
|
|
|
|
# any.
|
|
|
|
cmd_args = shlex.split(script_file_name)
|
|
|
|
file_name = cmd_args[0]
|
|
|
|
arguments = cmd_args[1:]
|
|
|
|
|
|
|
|
get_maintainer = find_get_maintainer(file_name)
|
2012-12-03 14:43:16 +00:00
|
|
|
if not get_maintainer:
|
|
|
|
if verbose:
|
2016-09-27 15:03:50 +00:00
|
|
|
print("WARNING: Couldn't find get_maintainer.pl")
|
2012-12-03 14:43:16 +00:00
|
|
|
return []
|
|
|
|
|
2022-12-20 05:28:46 +00:00
|
|
|
stdout = command.output(get_maintainer, *arguments, fname)
|
2017-12-31 22:21:17 +00:00
|
|
|
lines = stdout.splitlines()
|
2022-12-20 05:28:46 +00:00
|
|
|
return [x.replace('"', '') for x in lines]
|