get_maintainer.py 1.3 KB

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