From 4e02c93cb50774ac0f6f553f7857efb20f456a5c Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 9 Jan 2013 14:06:39 +0200 Subject: [PATCH] import-srpm: enhance spec guessing Use package name (in case of src.rpm) or directory name (in case of dir) as the preferred name of the spec file. Signed-off-by: Markus Lehtonen --- gbp/scripts/import_srpm.py | 7 ++++++- tests/component/rpm/test_import_srpm.py | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index 574d01e..269101d 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -274,13 +274,18 @@ def main(argv): prefix='pkgextract_') gbp.log.info("Extracting src rpm to '%s'" % dirs['pkgextract']) src.unpack(dirs['pkgextract']) + preferred_spec = src.name + '.spec' srpm = dirs['pkgextract'] + elif os.path.isdir(srpm): + preferred_spec = os.path.basename(srpm.rstrip('/')) + '.spec' + else: + preferred_spec = None # Find and parse spec file if os.path.isdir(srpm): gbp.log.debug("Trying to import an unpacked srpm from '%s'" % srpm) dirs['src'] = os.path.abspath(srpm) - spec = parse_spec(guess_spec(srpm, True)) + spec = parse_spec(guess_spec(srpm, True, preferred_spec)) else: gbp.log.debug("Trying to import an srpm from '%s' with spec "\ "file '%s'" % (os.path.dirname(srpm), srpm)) diff --git a/tests/component/rpm/test_import_srpm.py b/tests/component/rpm/test_import_srpm.py index 0f1ffeb..e2458a7 100644 --- a/tests/component/rpm/test_import_srpm.py +++ b/tests/component/rpm/test_import_srpm.py @@ -53,6 +53,17 @@ class TestImportPacked(ComponentTestBase): # of imported patches assert len(repo.get_commits()) == 4 + def test_basic_import2(self): + """Import package with multiple spec files and full url patch""" + srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm') + assert import_srpm(['arg0', srpm]) == 0 + # Check repository state + repo = GitRepository('gbp-test2') + self._check_repo_state(repo, 'master', ['master', 'upstream']) + # Four commits: upstream, packaging files, one patch and the removal + # of imported patches + assert len(repo.get_commits()) == 4 + def test_basic_import_orphan(self): """ Test importing of non-native src.rpm to separate packaging and @@ -221,9 +232,9 @@ class TestImportUnPacked(ComponentTestBase): def test_missing_files(self): """Test importing of directory with missing packaging files""" - + specfile = 'gbp-test2-2.0-0-unpack/gbp-test2.spec' os.unlink('gbp-test2-2.0-0-unpack/my.patch') - assert import_srpm(['arg0', 'gbp-test2-2.0-0-unpack']) == 1 + assert import_srpm(['arg0', specfile]) == 1 self._check_log(-1, "gbp:error: File 'my.patch' listed in spec " "not found") -- 2.7.4