get_maintainer.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2012 The Chromium OS Authors.
  3. # Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
  4. #
  5. import os
  6. import shlex
  7. import shutil
  8. from patman import gitutil
  9. from u_boot_pylib import command
  10. def find_get_maintainer(script_file_name):
  11. """Try to find where `script_file_name` is.
  12. It searches in PATH and falls back to a path relative to the top
  13. of the current git repository.
  14. """
  15. get_maintainer = shutil.which(script_file_name)
  16. if get_maintainer:
  17. return get_maintainer
  18. git_relative_script = os.path.join(gitutil.get_top_level(),
  19. script_file_name)
  20. if os.path.exists(git_relative_script):
  21. return git_relative_script
  22. def get_maintainer(script_file_name, fname, verbose=False):
  23. """Run `script_file_name` on a file.
  24. `script_file_name` should be a get_maintainer.pl-like script that
  25. takes a patch file name as an input and return the email addresses
  26. of the associated maintainers to standard output, one per line.
  27. If `script_file_name` does not exist we fail silently.
  28. Args:
  29. script_file_name: The file name of the get_maintainer.pl script
  30. (or compatible).
  31. fname: File name of the patch to process with get_maintainer.pl.
  32. Returns:
  33. A list of email addresses to CC to.
  34. """
  35. # Expand `script_file_name` into a file name and its arguments, if
  36. # any.
  37. cmd_args = shlex.split(script_file_name)
  38. file_name = cmd_args[0]
  39. arguments = cmd_args[1:]
  40. get_maintainer = find_get_maintainer(file_name)
  41. if not get_maintainer:
  42. if verbose:
  43. print("WARNING: Couldn't find get_maintainer.pl")
  44. return []
  45. stdout = command.output(get_maintainer, *arguments, fname)
  46. lines = stdout.splitlines()
  47. return [x.replace('"', '') for x in lines]