https://gcc.gnu.org/g:b1317619f571a916d3c256644c219e08ecac113f
commit r17-3870-gb1317619f571a916d3c256644c219e08ecac113f Author: Richard Earnshaw <[email protected]> Date: Wed Aug 19 16:48:50 2026 +0100 maintainer_utils.py: Add a store method Add a method that will write out the MAINTAINERS.yml data with a suitable leading comment. This avoids the need, should it arise of having multiple scripts needing to do something similar. Adjust add-write-after.py to use this. Update MAINTAINERS.yml to include the new comment. ChangeLog: * MAINTAINERS.yml: Add initial comment contrib/ChangeLog: * maintainer_utils.py(store): New function. * add-write-after.py(main): Use it. Diff: --- MAINTAINERS.yml | 4 ++++ contrib/add-write-after.py | 11 +++++------ contrib/maintainer_utils.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 5f1e05bf0b3b..e14432c67ee1 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1,3 +1,7 @@ +# If you edit this file, please validate with: +# contrib/maintainer_utils.py <MAINTAINERS.yml> +# before committing. + users: - sn: Abson cn: Spencer Abson diff --git a/contrib/add-write-after.py b/contrib/add-write-after.py index 6bbcd8c7e3b2..693bd8cd9536 100755 --- a/contrib/add-write-after.py +++ b/contrib/add-write-after.py @@ -141,13 +141,12 @@ def main(): data['users'] = sorted(data['users'], key = lambda k: (unilower(k['sn']), unilower(k['cn']))) - if opts.outfilename and opts.outfilename != '-': - outfd = open (opts.outfilename, "w", encoding="utf-8") - elif opts.outfilename and opts.outfilename == '-': - outfd = sys.stdout + if opts.outfilename and opts.outfilename == '-': + maintutils.store(data) else: - outfd = open (args[0], "w", encoding="utf-8") - yaml.dump (data, outfd, allow_unicode = True, sort_keys = False) + maintutils.store( + data, + file=opts.outfilename if opts.outfilename else args[0]) return 0 if __name__ == "__main__": diff --git a/contrib/maintainer_utils.py b/contrib/maintainer_utils.py index 9dfc6f0fea62..d3af121d075c 100755 --- a/contrib/maintainer_utils.py +++ b/contrib/maintainer_utils.py @@ -296,6 +296,20 @@ def load(file): return data +def store(data, file=None, fd=sys.stdout): + # Make sure we don't write something that is not conformant + validate(data) + if file: + fd = open(file, "w", encoding="utf-8") + print("# If you edit this file, please validate with:", + file=fd) + print("# contrib/maintainer_utils.py <MAINTAINERS.yml>", + file=fd) + print("# before committing.\n", file=fd) + yaml.dump(data, fd, allow_unicode=True, sort_keys=False) + if file: + fd.close() + def main(): if len(sys.argv) != 2: print(f"Usage: {sys.argv[0]} path-to-MAINTAINERS.yml")
