1*4882a593Smuzhiyun# Copyright (c) 2012 The Chromium OS Authors. 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0+ 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun 6*4882a593Smuzhiyunimport command 7*4882a593Smuzhiyunimport gitutil 8*4882a593Smuzhiyunimport os 9*4882a593Smuzhiyun 10*4882a593Smuzhiyundef FindGetMaintainer(): 11*4882a593Smuzhiyun """Look for the get_maintainer.pl script. 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun Returns: 14*4882a593Smuzhiyun If the script is found we'll return a path to it; else None. 15*4882a593Smuzhiyun """ 16*4882a593Smuzhiyun try_list = [ 17*4882a593Smuzhiyun os.path.join(gitutil.GetTopLevel(), 'scripts'), 18*4882a593Smuzhiyun ] 19*4882a593Smuzhiyun # Look in the list 20*4882a593Smuzhiyun for path in try_list: 21*4882a593Smuzhiyun fname = os.path.join(path, 'get_maintainer.pl') 22*4882a593Smuzhiyun if os.path.isfile(fname): 23*4882a593Smuzhiyun return fname 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun return None 26*4882a593Smuzhiyun 27*4882a593Smuzhiyundef GetMaintainer(fname, verbose=False): 28*4882a593Smuzhiyun """Run get_maintainer.pl on a file if we find it. 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun We look for get_maintainer.pl in the 'scripts' directory at the top of 31*4882a593Smuzhiyun git. If we find it we'll run it. If we don't find get_maintainer.pl 32*4882a593Smuzhiyun then we fail silently. 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun Args: 35*4882a593Smuzhiyun fname: Path to the patch file to run get_maintainer.pl on. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun Returns: 38*4882a593Smuzhiyun A list of email addresses to CC to. 39*4882a593Smuzhiyun """ 40*4882a593Smuzhiyun get_maintainer = FindGetMaintainer() 41*4882a593Smuzhiyun if not get_maintainer: 42*4882a593Smuzhiyun if verbose: 43*4882a593Smuzhiyun print("WARNING: Couldn't find get_maintainer.pl") 44*4882a593Smuzhiyun return [] 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun stdout = command.Output(get_maintainer, '--norolestats', fname) 47*4882a593Smuzhiyun return stdout.splitlines() 48