get_maintainer.py 1.4 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. def FindGetMaintainer(try_list):
  7. """Look for the get_maintainer.pl script.
  8. Args:
  9. try_list: List of directories to try 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. # Look in the list
  14. for path in try_list:
  15. fname = os.path.join(path, 'get_maintainer.pl')
  16. if os.path.isfile(fname):
  17. return fname
  18. return None
  19. def GetMaintainer(dir_list, fname, verbose=False):
  20. """Run get_maintainer.pl on a file if we find it.
  21. We look for get_maintainer.pl in the 'scripts' directory at the top of
  22. git. If we find it we'll run it. If we don't find get_maintainer.pl
  23. then we fail silently.
  24. Args:
  25. dir_list: List of directories to try for the get_maintainer.pl script
  26. fname: Path to the patch file to run get_maintainer.pl on.
  27. Returns:
  28. A list of email addresses to CC to.
  29. """
  30. get_maintainer = FindGetMaintainer(dir_list)
  31. if not get_maintainer:
  32. if verbose:
  33. print("WARNING: Couldn't find get_maintainer.pl")
  34. return []
  35. stdout = command.Output(get_maintainer, '--norolestats', fname)
  36. lines = stdout.splitlines()
  37. return [ x.replace('"', '') for x in lines ]