import-srpm: enhance spec guessing
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 9 Jan 2013 12:06:39 +0000 (14:06 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:21:29 +0000 (16:21 +0200)
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 <markus.lehtonen@linux.intel.com>
gbp/scripts/import_srpm.py
tests/component/rpm/test_import_srpm.py

index f295c02ebb549160af87c4b6ffff3f6458c946ce..a5d0a9a61381a3c12c20f82b76208e8a3879f849 100755 (executable)
@@ -268,13 +268,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))
index 0f1ffebadcf4f746dcb10a37e37a671bfe0f4ab8..e2458a74908827f9c20f33ed5a5be249f4e3c8df 100644 (file)
@@ -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")