rpm: support importing bzip2 compressed patches
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 20 May 2013 07:45:25 +0000 (10:45 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:46:24 +0000 (14:46 +0200)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/pq_rpm.py
tests/component/rpm/test_import_srpm.py

index edb327f..cf7b29a 100755 (executable)
@@ -25,6 +25,7 @@ import shutil
 import sys
 import re
 import gzip
+import bz2
 import subprocess
 import gbp.tmpfile as tempfile
 from gbp.config import (GbpOptionParserRpm, GbpOptionGroup)
@@ -227,12 +228,14 @@ def safe_patches(queue, tmpdir_base):
         gbp.log.debug("Safeing patches '%s' in '%s'" % (os.path.dirname(queue[0].path), tmpdir))
         for p in queue:
             (base, archive_fmt, comp) = parse_archive_filename(p.path)
-            if comp == 'gzip':
+            uncompressors = {'gzip': gzip.open, 'bzip2': bz2.BZ2File}
+            if comp in uncompressors:
                 gbp.log.debug("Uncompressing '%s'" % os.path.basename(p.path))
-                src = gzip.open(p.path, 'r')
+                src = uncompressors[comp](p.path, 'r')
                 dst_name = os.path.join(tmpdir, os.path.basename(base))
             elif comp:
-                raise GbpError, ("Unsupported compression of a patch, giving up")
+                raise GbpError("Unsupported patch compression '%s', giving up"
+                               % comp)
             else:
                 src = open(p.path, 'r')
                 dst_name = os.path.join(tmpdir, os.path.basename(p.path))
index 6659d36..5515707 100644 (file)
@@ -113,6 +113,20 @@ class TestImportPacked(ComponentTestBase):
         # Only one commit: packaging files
         eq_(len(repo.get_commits()), 1)
 
+    def test_import_compressed_patches(self):
+        """Test importing of non-native src.rpm with compressed patches"""
+        srpm = os.path.join(DATA_DIR, 'gbp-test-1.1-2.src.rpm')
+        eq_(import_srpm(['arg0', srpm]), 0)
+        # Check repository state
+        repo = GitRepository('gbp-test')
+        files =  set(['Makefile', 'README', 'AUTHORS', 'NEWS', 'bar.tar.gz',
+                    'dummy.sh', 'foo.txt', 'gbp-test.spec', 'my.patch',
+                    'mydir/myfile.txt'])
+        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
+        # Four commits: upstream, packaging files, three patches and the removal
+        # of imported patches
+        eq_(len(repo.get_commits()), 6)
+
     def test_multiple_versions(self):
         """Test importing of multiple versions"""
         srpms = [ os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm'),