diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-10-12 14:33:30 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-10-12 17:01:54 +0100 |
commit | d0111fbd2de1d046b14046f2cb0ded14d058cfdd (patch) | |
tree | 2e531268b9b9aee9ea6a5ecfd5efeb5fe6b4bf0b /morphlib | |
parent | e3aa8ba25847397a03a665492a0cbe4541814246 (diff) | |
download | morph-d0111fbd2de1d046b14046f2cb0ded14d058cfdd.tar.gz |
Fix use of GzipFile to not assume "with" protocol
This fixes a bunch of tests so they pass on squeeze, which has a version
of Python whose GzipFile doesn't support the "with" protocol.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/builder2.py | 7 | ||||
-rw-r--r-- | morphlib/plugins/trebuchet_plugin.py | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 856587a2..565fdf4f 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -706,9 +706,10 @@ class DiskImageBuilder(SystemKindBuilder): # pragma: no cover self.app.status(msg='Compressing disk image', chatty=True) with os.fdopen(image_file_fd, "rb") as ifh: - with gzip.GzipFile(fileobj=handle, mode="wb", - compresslevel=1) as ofh: - shutil.copyfileobj(ifh, ofh, 1024 * 1024) + ofh = gzip.GzipFile( + fileobj=handle, mode="wb", compresslevel=1) + shutil.copyfileobj(ifh, ofh, 1024 * 1024) + ofh.close() except: os.remove(image_name) diff --git a/morphlib/plugins/trebuchet_plugin.py b/morphlib/plugins/trebuchet_plugin.py index 1c44bf29..4fa25e91 100644 --- a/morphlib/plugins/trebuchet_plugin.py +++ b/morphlib/plugins/trebuchet_plugin.py @@ -40,8 +40,9 @@ class MountableImage(object): try: with os.fdopen(tempfd, "wb") as outfh: - with gzip.open(path, "rb") as infh: - morphlib.util.copyfileobj(infh, outfh) + infh = gzip.open(path, "rb") + morphlib.util.copyfileobj(infh, outfh) + infh.close() except: os.unlink(self.temp_path) raise |