diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-08-26 21:41:54 +0100 |
---|---|---|
committer | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-08-28 15:58:16 +0100 |
commit | e9826e1a29dd045a1a6c680d0d709906da13488b (patch) | |
tree | 5bc2093efa1f67c38320518f39d30c0a4235fe1c /src | |
parent | 242d7e8381850fa03bbff9969e20e946af38f850 (diff) | |
download | virt-bootstrap.git-e9826e1a29dd045a1a6c680d0d709906da13488b.tar.gz virt-bootstrap.git-e9826e1a29dd045a1a6c680d0d709906da13488b.tar.xz virt-bootstrap.git-e9826e1a29dd045a1a6c680d0d709906da13488b.zip |
get_mime_type: Properly close stdout handle
This aims to fix the warning of Python3:
ResourceWarning: unclosed file <_io.BufferedReader name=3>
Diffstat (limited to 'src')
-rw-r--r-- | src/virtBootstrap/utils.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py index 923309a..9d477db 100644 --- a/src/virtBootstrap/utils.py +++ b/src/virtBootstrap/utils.py @@ -179,12 +179,13 @@ def get_mime_type(path): """ Get the mime type of a file. """ - return ( - subprocess.Popen( - ["/usr/bin/file", "--mime-type", path], - stdout=subprocess.PIPE - ).stdout.read().decode('utf-8').split()[1] + proc = subprocess.Popen( + ["/usr/bin/file", "--mime-type", path], + stdout=subprocess.PIPE ) + proc.wait() + with proc.stdout as output: + return output.read().decode('utf-8').split()[1] def create_qcow2(tar_file, layer_file, backing_file=None, size=DEF_QCOW2_SIZE): |