get_maintainer.py 1.2 KB

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