mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-11 07:06:16 +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:
commit
c0c87dad33
19
osc/core.py
19
osc/core.py
@ -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
|
||||||
|
1
tests/fixtures/packages/osctest/projectA/pkgA-symlink
vendored
Symbolic link
1
tests/fixtures/packages/osctest/projectA/pkgA-symlink
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
pkgA
|
0
tests/fixtures/packages/osctest/projectA/pkgA/pkgA.changes
vendored
Normal file
0
tests/fixtures/packages/osctest/projectA/pkgA/pkgA.changes
vendored
Normal file
0
tests/fixtures/packages/osctest/projectA/pkgA/pkgA.spec
vendored
Normal file
0
tests/fixtures/packages/osctest/projectA/pkgA/pkgA.spec
vendored
Normal 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]
|
||||||
|
Loading…
Reference in New Issue
Block a user