blob: 22b091808a1914f541d4162b4b8da91c7b4614a3 [file] [log] [blame]
Doug Andersonc2c84bc2012-12-03 14:43:16 +00001# Copyright (c) 2012 The Chromium OS Authors.
2#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Doug Andersonc2c84bc2012-12-03 14:43:16 +00004#
5
6import command
7import gitutil
8import os
9
10def FindGetMaintainer():
11 """Look for the get_maintainer.pl script.
12
13 Returns:
14 If the script is found we'll return a path to it; else None.
15 """
16 try_list = [
17 os.path.join(gitutil.GetTopLevel(), 'scripts'),
18 ]
19 # Look in the list
20 for path in try_list:
21 fname = os.path.join(path, 'get_maintainer.pl')
22 if os.path.isfile(fname):
23 return fname
24
25 return None
26
27def GetMaintainer(fname, verbose=False):
28 """Run get_maintainer.pl on a file if we find it.
29
30 We look for get_maintainer.pl in the 'scripts' directory at the top of
31 git. If we find it we'll run it. If we don't find get_maintainer.pl
32 then we fail silently.
33
34 Args:
35 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 """
40 get_maintainer = FindGetMaintainer()
41 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 ]