[2/2] framework/backends/abstract: Fix doubling compression suffixes

Submitted by Dylan Baker on Aug. 21, 2015, 8:08 p.m.

Details

Message ID 1440187684-13391-2-git-send-email-baker.dylan.c@gmail.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Dylan Baker Aug. 21, 2015, 8:08 p.m.
This patch fixes the write_compressed method to not add an additional
compression suffix to files that already have a compression suffix.

This fixes the tests from the previous patch.

Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
---
 framework/backends/abstract.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/framework/backends/abstract.py b/framework/backends/abstract.py
index c892995..97d2d07 100644
--- a/framework/backends/abstract.py
+++ b/framework/backends/abstract.py
@@ -49,7 +49,13 @@  def write_compressed(filename):
     """
     mode = compression.get_mode()
     if mode != 'none':
-        filename = '{}.{}'.format(filename, mode)
+        suffix = os.path.splitext(filename)[1]
+        if suffix[1:] == mode:
+            pass
+        elif suffix in compression.COMPRESSION_SUFFIXES:
+            filename = '{}.{}'.format(os.path.splitext(filename)[0], mode)
+        else:
+            filename = '{}.{}'.format(filename, mode)
 
     with compression.COMPRESSORS[mode](filename) as f:
         yield f