From 59e10137770e8f2a8fe828e01888cced606ce84a Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 24 Jan 2018 14:26:57 -0500 Subject: [PATCH] change propose-library-branches to use yamlutils We now have a way to preserve the order and other general formatting settings when rewriting a YAML file, so use it instead of tacking a blob of text onto the end of the file. Change-Id: Icd3a6a4d75e3e86acbec66503f4b99951460c2f7 Signed-off-by: Doug Hellmann --- .../cmds/propose_library_branches.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/openstack_releases/cmds/propose_library_branches.py b/openstack_releases/cmds/propose_library_branches.py index 47f3d8ca7a..172f9d4089 100644 --- a/openstack_releases/cmds/propose_library_branches.py +++ b/openstack_releases/cmds/propose_library_branches.py @@ -26,13 +26,6 @@ from openstack_releases import defaults from openstack_releases import yamlutils -BRANCH_TEMPLATE = """ -branches: - - name: stable/{series} - location: {version} -""" - - def main(): parser = argparse.ArgumentParser() parser.add_argument( @@ -125,11 +118,9 @@ def main(): continue latest_release = releases[-1] - # NOTE(dhellmann): PyYAML doesn't preserve layout when you - # write the data back out, so do the formatting ourselves. - new_block = BRANCH_TEMPLATE.format( - version=latest_release['version'], - series=args.series, - ).strip() + '\n' - with open(filename, 'a') as f: - f.write(new_block) + deliverable_data['branches'].append({ + 'name': 'stable/' + args.series, + 'location': latest_release['version'], + }) + with open(filename, 'w', encoding='utf-8') as f: + f.write(yamlutils.dumps(deliverable_data))