blob: 473f0feebf40b4ebb6a73c2be117925de24259c1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Doug Anderson21a19d72012-12-03 14:43:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
3#
Doug Anderson21a19d72012-12-03 14:43:16 +00004
Doug Anderson21a19d72012-12-03 14:43:16 +00005import os
6
Simon Glassbf776672020-04-17 18:09:04 -06007from patman import command
8from patman import gitutil
9
Doug Anderson21a19d72012-12-03 14:43:16 +000010def 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 Burtona920a172016-09-27 16:03:50 +010043 print("WARNING: Couldn't find get_maintainer.pl")
Doug Anderson21a19d72012-12-03 14:43:16 +000044 return []
45
46 stdout = command.Output(get_maintainer, '--norolestats', fname)
Stefan BrĂ¼nsd1ccaa42017-12-31 23:21:17 +010047 lines = stdout.splitlines()
48 return [ x.replace('"', '') for x in lines ]