From: Markus Lehtonen Date: Mon, 20 May 2013 07:45:25 +0000 (+0300) Subject: rpm: support importing bzip2 compressed patches X-Git-Tag: tizen/0.6.22-20150206~85 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6be238273731abb1e7b9aa8ecfcb665f68520b76;p=tools%2Fgit-buildpackage.git rpm: support importing bzip2 compressed patches Signed-off-by: Markus Lehtonen --- diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index edb327f..cf7b29a 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -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)) diff --git a/tests/component/rpm/test_import_srpm.py b/tests/component/rpm/test_import_srpm.py index 6659d36..5515707 100644 --- a/tests/component/rpm/test_import_srpm.py +++ b/tests/component/rpm/test_import_srpm.py @@ -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'),