Use 'with' method rather than having to call close

gzip.GzipFile() supports 'with' statement usage. Use that rather than
having to call close() explicitly. Plus with a 'with' statement if
there is an exception it will still call close()

Change-Id: I8535dffd66ffd7244b8bdcc4d79d6cf437a4d779
This commit is contained in:
John L. Villalovos 2018-01-30 23:51:26 -08:00
parent 487ad98067
commit 6b53f45e57
1 changed files with 2 additions and 3 deletions

View File

@ -292,9 +292,8 @@ def make_configdrive(path):
# Compress file
tmpfile.seek(0)
g = gzip.GzipFile(fileobj=tmpzipfile, mode='wb')
shutil.copyfileobj(tmpfile, g)
g.close()
with gzip.GzipFile(fileobj=tmpzipfile, mode='wb') as gz_file:
shutil.copyfileobj(tmpfile, gz_file)
tmpzipfile.seek(0)
return base64.encode_as_bytes(tmpzipfile.read())