3 # Copyright (C) 2022 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING. If not, write to
19 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
22 # Check that names in the file are sorted
23 # alphabetically by surname.
27 from difflib
import ndiff
28 from itertools
import dropwhile
, takewhile
32 locale
.setlocale(locale
.LC_ALL
, 'en_US.utf8')
36 if len(sys
.argv
) != 2:
37 print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
41 def sort_by_surname(line
):
42 name
= line
.split('\t')[0]
46 # Special-case some names
47 if name
== 'Stefan Schulze Frielinghaus':
49 elif name
== 'Kris Van Hees':
51 elif surname
== "d'Humieres":
55 return (unidecode
.unidecode(surname
), line
)
66 def check_group(name
, lines
):
70 if line
.startswith(' '):
71 print(f
'Line should not start with space: "{line}"')
74 lines
= [line
+ '\n' for line
in lines
]
75 sorted_lines
= sorted(lines
, key
=sort_by_surname
)
76 if lines
!= sorted_lines
:
78 diff
= ndiff(lines
, sorted_lines
)
79 print(f
'Wrong order for {name}:\n')
82 print(f
'{name} are fine!')
85 lines
= open(sys
.argv
[1]).read().splitlines()
87 needle
= 'Global Reviewers'
88 lines
= list(dropwhile(lambda x
: x
.strip() != needle
, lines
))
91 chunk
= list(takewhile(is_empty
, lines
))
92 check_group(needle
, chunk
)
94 needle
= 'Write After Approval'
95 lines
= list(dropwhile(lambda x
: needle
not in x
, lines
))
98 chunk
= list(takewhile(is_empty
, lines
))
99 check_group(needle
, chunk
)
101 needle
= 'Bug database only accounts'
102 lines
= list(dropwhile(lambda x
: needle
not in x
, lines
))
105 chunk
= list(takewhile(is_empty
, lines
))
106 check_group(needle
, chunk
)
108 needle
= 'Contributing under the DCO'
109 lines
= list(dropwhile(lambda x
: needle
not in x
, lines
))[1:]
110 lines
= list(dropwhile(lambda x
: not has_tab(x
), lines
))
111 check_group(needle
, lines
)