qapi/gen.py: update write() to be more idiomatic
commitcc6263c44b3ad70a8cb884518e78e70c17f180d0
authorJohn Snow <jsnow@redhat.com>
Fri, 9 Oct 2020 16:15:52 +0000 (9 12:15 -0400)
committerMarkus Armbruster <armbru@redhat.com>
Sat, 10 Oct 2020 09:37:49 +0000 (10 11:37 +0200)
treea0354a4313a853d4647cd2ed4b770eb209390da7
parent0cbd5b0516814a07004d6bd22e5c323f8314273f
qapi/gen.py: update write() to be more idiomatic

Make the file handling here just a tiny bit more idiomatic.
(I realize this is heavily subjective.)

Use exist_ok=True for os.makedirs and remove the exception,
use fdopen() to wrap the file descriptor in a File-like object,
and use a context manager for managing the file pointer.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201009161558.107041-31-jsnow@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi/gen.py