]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Fixing _decompress to handle bundled and compressed
authorChris Alfonso <calfonso@redhat.com>
Mon, 21 May 2012 18:50:54 +0000 (14:50 -0400)
committerChris Alfonso <calfonso@redhat.com>
Mon, 21 May 2012 18:50:54 +0000 (14:50 -0400)
The api call to os.path.splitext returns the root and the ext;
however, for a .tar.gz the ext would just be the .gz, which meant
there was no handler for a file with a .gz extension.

heat/cfntools/cfn_helper.py

index 841938cb403ea5ed08e1e756c166d80244aafc1e..0ca2503cf0f1aa8725735325d2fa5e4b20bd6870 100644 (file)
@@ -581,15 +581,28 @@ class SourcesHandler(object):
 
     def _decompress(self, archive, dest_dir):
         cmd_str = ''
+        logger.debug("Decompressing")
         (r, ext) = os.path.splitext(archive)
-        if ext == '.tar.gz' or ext == '.tgz':
+        if  ext == '.tgz':
             cmd_str = 'tar -C %s -xzf %s' % (dest_dir, archive)
-        elif ext == '.tar.bz2' or ext == '.tbz2':
+        elif ext == '.tbz2':
             cmd_str = 'tar -C %s -xjf %s' % (dest_dir, archive)
         elif ext == '.zip':
             cmd_str = 'unzip -d %s %s' % (dest_dir, archive)
         elif ext == '.tar':
             cmd_str = 'tar -C %s -xf %s' % (dest_dir, archive)
+        elif ext == '.gz':
+            (r, ext) = os.path.splitext(r)
+            if ext:
+                cmd_str = 'tar -C %s -xzf %s' % (dest_dir, archive)
+            else:
+                cmd_str = 'gunzip -c %s > %s' % (archive, dest_dir)
+        elif ext == 'bz2':
+            (r, ext) = os.path.splitext(r)
+            if ext:
+                cmd_str = 'tar -C %s -xjf %s' % (dest_dir, archive)
+            else:
+                cmd_str = 'bunzip2 -c %s > %s' % (archive, dest_dir)
         else:
             pass
         return CommandRunner(cmd_str)