1# Copyright (c) 2012 The Chromium OS Authors.
2#
3# See file CREDITS for list of people who contributed to this
4# project.
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; either version 2 of
9# the License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19# MA 02111-1307 USA
20#
21
22import command
23import gitutil
24import os
25
26def FindGetMaintainer():
27    """Look for the get_maintainer.pl script.
28
29    Returns:
30        If the script is found we'll return a path to it; else None.
31    """
32    try_list = [
33        os.path.join(gitutil.GetTopLevel(), 'scripts'),
34        ]
35    # Look in the list
36    for path in try_list:
37        fname = os.path.join(path, 'get_maintainer.pl')
38        if os.path.isfile(fname):
39            return fname
40
41    return None
42
43def GetMaintainer(fname, verbose=False):
44    """Run get_maintainer.pl on a file if we find it.
45
46    We look for get_maintainer.pl in the 'scripts' directory at the top of
47    git.  If we find it we'll run it.  If we don't find get_maintainer.pl
48    then we fail silently.
49
50    Args:
51        fname: Path to the patch file to run get_maintainer.pl on.
52
53    Returns:
54        A list of email addresses to CC to.
55    """
56    get_maintainer = FindGetMaintainer()
57    if not get_maintainer:
58        if verbose:
59            print "WARNING: Couldn't find get_maintainer.pl"
60        return []
61
62    stdout = command.Output(get_maintainer, '--norolestats', fname)
63    return stdout.splitlines()
64