check-MAINTAINERS.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2022 Free Software Foundation, Inc.
  3. #
  4. # This file is part of GCC.
  5. #
  6. # GCC is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # GCC is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GCC; see the file COPYING. If not, write to
  18. # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  19. # Boston, MA 02110-1301, USA.
  20. # Check that names in the file are sorted
  21. # alphabetically by surname.
  22. import locale
  23. import sys
  24. from difflib import ndiff
  25. from itertools import dropwhile, takewhile
  26. import unidecode
  27. locale.setlocale(locale.LC_ALL, 'en_US.utf8')
  28. exit_code = 0
  29. if len(sys.argv) != 2:
  30. print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
  31. sys.exit(1)
  32. def sort_by_surname(line):
  33. name = line.split('\t')[0]
  34. parts = name.split()
  35. surname = parts[-1]
  36. # Special-case some names
  37. if name == 'Stefan Schulze Frielinghaus':
  38. surname = parts[1]
  39. elif name == 'Kris Van Hees':
  40. surname = parts[1]
  41. elif surname == "d'Humieres":
  42. surname = 'Humieres'
  43. # Remove accents
  44. return (unidecode.unidecode(surname), line)
  45. def has_tab(line):
  46. return '\t' in line
  47. def is_empty(line):
  48. return line
  49. def check_group(name, lines):
  50. global exit_code
  51. for line in lines:
  52. if line.startswith(' '):
  53. print(f'Line should not start with space: "{line}"')
  54. exit_code = 2
  55. lines = [line + '\n' for line in lines]
  56. sorted_lines = sorted(lines, key=sort_by_surname)
  57. if lines != sorted_lines:
  58. exit_code = 1
  59. diff = ndiff(lines, sorted_lines)
  60. print(f'Wrong order for {name}:\n')
  61. print(''.join(diff))
  62. else:
  63. print(f'{name} are fine!')
  64. lines = open(sys.argv[1]).read().splitlines()
  65. needle = 'Global Reviewers'
  66. lines = list(dropwhile(lambda x: x.strip() != needle, lines))
  67. lines = lines[2:]
  68. chunk = list(takewhile(is_empty, lines))
  69. check_group(needle, chunk)
  70. needle = 'Write After Approval'
  71. lines = list(dropwhile(lambda x: needle not in x, lines))
  72. lines = lines[2:]
  73. chunk = list(takewhile(is_empty, lines))
  74. check_group(needle, chunk)
  75. needle = 'Bug database only accounts'
  76. lines = list(dropwhile(lambda x: needle not in x, lines))
  77. lines = lines[2:]
  78. chunk = list(takewhile(is_empty, lines))
  79. check_group(needle, chunk)
  80. needle = 'Contributing under the DCO'
  81. lines = list(dropwhile(lambda x: needle not in x, lines))[1:]
  82. lines = list(dropwhile(lambda x: not has_tab(x), lines))
  83. check_group(needle, lines)
  84. sys.exit(exit_code)