1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-26 01:46:13 +01:00

Merge pull request #1220 from dmach/fix-package-todo

Fix creating a Package object by providing multiple files on the command line
This commit is contained in:
Daniel Mach 2023-01-23 23:26:49 +01:00 committed by GitHub
commit c0c87dad33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 4 deletions

View File

@ -1277,13 +1277,24 @@ class Package:
path_is_file = os.path.isfile(path) path_is_file = os.path.isfile(path)
if path_is_file: if path_is_file:
path = os.path.dirname(path) or "." path = os.path.dirname(path) or "."
package = cls(path, progress_obj) package = cls(path, progress_obj)
try:
# re-use an existing package
seen_package_index = packages.index(package)
package = packages[seen_package_index]
if os.path.abspath(path) != package.absdir:
raise oscerr.PackageExists(package.prjname, package.name, "Duplicate package")
except ValueError:
# use a new package instance
packages.append(package)
if path_is_file: if path_is_file:
# XXX: modifying 'todo' is an unexpected side-effect # XXX: modifying 'todo' is an unexpected side-effect
package.todo = [os.path.basename(orig_path)] todo_entry = os.path.basename(orig_path)
if package in packages: if todo_entry not in package.todo:
raise oscerr.PackageExists(package.prjname, package.name, "Duplicate package") package.todo.append(todo_entry)
packages.append(package)
return packages return packages
@classmethod @classmethod

View File

@ -0,0 +1 @@
pkgA

View File

@ -81,10 +81,31 @@ class TestPackageFromPaths(OscTestCase):
self.assertEqual(pac.apiurl, "http://localhost") self.assertEqual(pac.apiurl, "http://localhost")
def test_duplicates(self): def test_duplicates(self):
# passing a path twice is ok
paths = ["projectA/pkgA", "projectA/pkgA"] paths = ["projectA/pkgA", "projectA/pkgA"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths] paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
pacs = osc.core.Package.from_paths(paths)
pac = pacs[0]
self.assertEqual(pac.name, "pkgA")
self.assertEqual(pac.prjname, "projectA")
self.assertEqual(pac.apiurl, "http://localhost")
# the same package in 2 paths is an error
paths = ["projectA/pkgA", "projectA/pkgA-symlink"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
self.assertRaises(osc.oscerr.PackageExists, osc.core.Package.from_paths, paths) self.assertRaises(osc.oscerr.PackageExists, osc.core.Package.from_paths, paths)
def test_one_package_two_files(self):
paths = ["projectA/pkgA/pkgA.spec", "projectA/pkgA/pkgA.changes"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
pacs = osc.core.Package.from_paths(paths)
self.assertEqual(len(pacs), 1)
pac = pacs[0]
self.assertEqual(pac.name, "pkgA")
self.assertEqual(pac.prjname, "projectA")
self.assertEqual(pac.apiurl, "http://localhost")
def test_two_packages(self): def test_two_packages(self):
paths = ["projectA/pkgA", "projectA/pkgB"] paths = ["projectA/pkgA", "projectA/pkgB"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths] paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]