[PATCH v1 1/5] maintainer_utils.py: Add a store method
Richard Earnshaw via Sourceware Forge <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <bmm.hlit9bvuc0.gcc.gcc.rearnsha.222.1.1@forge-stage.sourceware.org> |
From: Richard Earnshaw <[email protected]> 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. --- 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 1b4432428752a..5d44576d7579b 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 6bbcd8c7e3b22..693bd8cd95362 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 9dfc6f0fea62b..d3af121d075c9 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") -- 2.54.0