import sys
import re
import gzip
+import bz2
import subprocess
import gbp.tmpfile as tempfile
from gbp.config import (GbpOptionParserRpm, GbpOptionGroup)
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))
# 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'),