[PATCH v1 4/5] maintainer_utils: Ensure the list of user data is sorted.
Richard Earnshaw via Sourceware Forge <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <bmm.hlit9bvuc0.gcc.gcc.rearnsha.222.1.4@forge-stage.sourceware.org> |
From: Richard Earnshaw <[email protected]> The YAML data for the list of maintainers is sorted by surname (sn) and full name (cn). Add a sort function that we use before storing the data, with a couple of additional keys (account and forgeid) to ensure the list is always fully ordered. When verifying the data check the sort order. Since the store routine now handles this, clean up add-write-after to remove the now unneeded sorting. contrib/ChangeLog: * maintainer_utils.py (_unilower): New function. (sort_users): Likewise. (verify): Check the sort order of the user data. (store): Sort the user data before writing it. * add-write-after.py (unilower): Delete (main): No need to sort the user data here now. --- contrib/add-write-after.py | 9 +-------- contrib/maintainer_utils.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/contrib/add-write-after.py b/contrib/add-write-after.py index c6c11bbcf5c87..690fdbfb80200 100755 --- a/contrib/add-write-after.py +++ b/contrib/add-write-after.py @@ -25,17 +25,12 @@ import os import pwd import re import sys -import unidecode import yaml from optparse import OptionParser import maintainer_utils as maintutils -def unilower(txt): - """return a lower-case version of txt, mapping accented characters - onto their ASCII near equivalents.""" - return unidecode.unidecode(txt).lower() def get_surname(name): parts = name.split() @@ -148,9 +143,7 @@ def main(): print("Note, this script can only be used to add new accounts.") return 1 data['users'].append (newuser) - data['users'] = sorted(data['users'], - key = lambda k: (unilower(k['sn']), - unilower(k['cn']))) + if opts.outfilename and opts.outfilename == '-': maintutils.store(data) else: diff --git a/contrib/maintainer_utils.py b/contrib/maintainer_utils.py index 8199fd588758f..4cf1ca32a7c88 100755 --- a/contrib/maintainer_utils.py +++ b/contrib/maintainer_utils.py @@ -244,6 +244,12 @@ def _check_schema(data): return +def _unilower(txt): + """return a lower-case version of txt, mapping accented characters + onto their ASCII near equivalents.""" + return unidecode.unidecode(txt).lower() + + def _check_dco(user): # An email addrss in a DCO entry must also be listed in either the # active emails list, or the inactive_emails list. @@ -253,6 +259,19 @@ def _check_dco(user): _error(f"User: {user['cn']} DCO {dco} not listed in other emails") +def sort_users(user_data): + """Sort the user data into canonical order.""" + return sorted( + user_data, + key = lambda k: ( + _unilower(k['sn']), + _unilower(k['cn']), + k.get('account', ''), + k.get('forgeid', ''), + ) + ) + + def validate(data): """Check the data against the schema and our own consistency checks""" _check_schema(data) @@ -303,6 +322,17 @@ def validate(data): _error(f"Multiple subsystem entries for '{n}'.") if not seen_writeafter: _error(f"User '{u['cn']}' lacks WriteAfter role.") + + sorted = sort_users(data['users']) + if sorted != data['users']: + _error("User data is incorrectly sorted.") + for right, wrong in zip(sorted, data['users']): + if right != wrong: + print( + f"First incorrect entry is for {wrong['cn']}", + file=sys.stderr + ) + break if error_count: sys.exit(1) return @@ -315,6 +345,7 @@ def load(file): def store(data, file=None, fd=sys.stdout): + data['users'] = sort_users(data['users']) # Make sure we don't write something that is not conformant validate(data) if file: -- 2.54.0