diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2020-04-07 15:55:17 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2020-04-07 15:55:17 +0100 |
commit | a0b254efe5013ec2f60ec6f04a5ac8db304aba6d (patch) | |
tree | 34d0ae9c82f462e0c560c06d90f2ae2feb619878 /oslo_policy/generator.py | |
parent | ced4d8eae4a6399251840fb5ef95eb74ec497464 (diff) | |
download | oslo-policy-a0b254efe5013ec2f60ec6f04a5ac8db304aba6d.tar.gz |
Cleanup warnings
Zuul has taken to including warnings in the locations that they're
raised in. We have a few of these in recent jobs so go ahead and clean
them up.
Change-Id: Ifcce20159d872ffd1447ca10f126ae2f2162f956
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'oslo_policy/generator.py')
-rw-r--r-- | oslo_policy/generator.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py index fd9f159..48a9972 100644 --- a/oslo_policy/generator.py +++ b/oslo_policy/generator.py @@ -277,6 +277,9 @@ def _generate_sample(namespaces, output_file=None, output_format='yaml', ',\n '.join(sections_text), '\n}\n')) + if output_file != sys.stdout: + output_file.close() + def _generate_policy(namespace, output_file=None): """Generate a policy file showing what will be used. @@ -304,6 +307,9 @@ def _generate_policy(namespace, output_file=None): for section in _sort_and_format_by_section(policies, include_help=False): output_file.write(section) + if output_file != sys.stdout: + output_file.close() + def _list_redundant(namespace): """Generate a list of configured policies which match defaults. @@ -396,12 +402,11 @@ def upgrade_policy(args=None, conf=None): _upgrade_policies(policies, default_policies) if conf.output_file: - if conf.format == 'yaml': - yaml.safe_dump(policies, open(conf.output_file, 'w'), - default_flow_style=False) - elif conf.format == 'json': - jsonutils.dump(policies, open(conf.output_file, 'w'), - indent=4) + with open(conf.output_file, 'w') as fh: + if conf.format == 'yaml': + yaml.safe_dump(policies, fh, default_flow_style=False) + elif conf.format == 'json': + jsonutils.dump(policies, fh, indent=4) else: if conf.format == 'yaml': sys.stdout.write(yaml.safe_dump(policies, |