blob: af4ba15bcdd7924aa183317d2bf479fa91414e34 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Doug Andersonc2c84bc2012-12-03 14:43:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
3#
Doug Andersonc2c84bc2012-12-03 14:43:16 +00004
Doug Andersonc2c84bc2012-12-03 14:43:16 +00005import os
6
Simon Glassa997ea52020-04-17 18:09:04 -06007from patman import command
Simon Glassa997ea52020-04-17 18:09:04 -06008
Simon Glassc9fa8862020-06-07 06:45:48 -06009def FindGetMaintainer(try_list):
Doug Andersonc2c84bc2012-12-03 14:43:16 +000010 """Look for the get_maintainer.pl script.
11
Simon Glassc9fa8862020-06-07 06:45:48 -060012 Args:
13 try_list: List of directories to try for the get_maintainer.pl script
14
Doug Andersonc2c84bc2012-12-03 14:43:16 +000015 Returns:
16 If the script is found we'll return a path to it; else None.
17 """
Doug Andersonc2c84bc2012-12-03 14:43:16 +000018 # Look in the list
19 for path in try_list:
20 fname = os.path.join(path, 'get_maintainer.pl')
21 if os.path.isfile(fname):
22 return fname
23
24 return None
25
Simon Glassc9fa8862020-06-07 06:45:48 -060026def GetMaintainer(dir_list, fname, verbose=False):
Doug Andersonc2c84bc2012-12-03 14:43:16 +000027 """Run get_maintainer.pl on a file if we find it.
28
29 We look for get_maintainer.pl in the 'scripts' directory at the top of
30 git. If we find it we'll run it. If we don't find get_maintainer.pl
31 then we fail silently.
32
33 Args:
Simon Glassc9fa8862020-06-07 06:45:48 -060034 dir_list: List of directories to try for the get_maintainer.pl script
Doug Andersonc2c84bc2012-12-03 14:43:16 +000035 fname: Path to the patch file to run get_maintainer.pl on.
36
37 Returns:
38 A list of email addresses to CC to.
39 """
Simon Glassc9fa8862020-06-07 06:45:48 -060040 get_maintainer = FindGetMaintainer(dir_list)
Doug Andersonc2c84bc2012-12-03 14:43:16 +000041 if not get_maintainer:
42 if verbose:
Paul Burtonc3931342016-09-27 16:03:50 +010043 print("WARNING: Couldn't find get_maintainer.pl")
Doug Andersonc2c84bc2012-12-03 14:43:16 +000044 return []
45
46 stdout = command.Output(get_maintainer, '--norolestats', fname)
Stefan BrĂ¼ns5d3a5fa2017-12-31 23:21:17 +010047 lines = stdout.splitlines()
48 return [ x.replace('"', '') for x in lines ]