aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-02-27 22:08:29 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-02-28 15:31:18 +0000
commitbf9e33c1c76c2c2387ada7ae7294efa21a1c2f2f (patch)
treefe00ac0ca9434b268499b6380220140fc5e1a816 /python
parent761f72d25876dac3e239fad163123d35cacda4a0 (diff)
downloadpaludis-bf9e33c1c76c2c2387ada7ae7294efa21a1c2f2f.tar.gz
paludis-bf9e33c1c76c2c2387ada7ae7294efa21a1c2f2f.tar.xz
Allow repos to return partial results if faster
Diffstat (limited to 'python')
-rw-r--r--python/choices_TEST.py8
-rwxr-xr-xpython/metadata_key_TEST.py6
-rwxr-xr-xpython/package_id_TEST.py8
-rw-r--r--python/repository.cc23
-rwxr-xr-xpython/repository_TEST.py48
5 files changed, 51 insertions, 42 deletions
diff --git a/python/choices_TEST.py b/python/choices_TEST.py
index f785c310c..b824d3240 100644
--- a/python/choices_TEST.py
+++ b/python/choices_TEST.py
@@ -2,7 +2,7 @@
# vim: set fileencoding=utf-8 sw=4 sts=4 et :
#
-# Copyright (c) 2008 Ciaran McCreesh
+# Copyright (c) 2008, 2011 Ciaran McCreesh
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
@@ -32,7 +32,7 @@ Log.instance.log_level = LogLevel.WARNING
class TestCase_01_Choices(unittest.TestCase):
def setUp(self):
self.e = NoConfigEnvironment(repo_path, "/var/empty")
- self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
self.choices = self.pid.find_metadata("PALUDIS_CHOICES").value()
def test_01_choices(self):
@@ -58,7 +58,7 @@ class TestCase_01_Choices(unittest.TestCase):
class TestCase_02_Choice(unittest.TestCase):
def setUp(self):
self.e = NoConfigEnvironment(repo_path, "/var/empty")
- self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
self.choices = self.pid.find_metadata("PALUDIS_CHOICES").value()
self.use = None
self.linguas = None
@@ -107,7 +107,7 @@ class TestCase_02_Choice(unittest.TestCase):
class TestCase_03_ChoiceValue(unittest.TestCase):
def setUp(self):
self.e = NoConfigEnvironment(repo_path, "/var/empty")
- self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
self.choices = self.pid.find_metadata("PALUDIS_CHOICES").value()
self.use_testflag = self.choices.find_by_name_with_prefix("testflag")
self.linguas_en = self.choices.find_by_name_with_prefix("linguas_en")
diff --git a/python/metadata_key_TEST.py b/python/metadata_key_TEST.py
index a13ed6b54..9d6a74a2e 100755
--- a/python/metadata_key_TEST.py
+++ b/python/metadata_key_TEST.py
@@ -34,8 +34,8 @@ class TestCase_01_MetadataKeys(unittest.TestCase):
def setUp(self):
self.e = NoConfigEnvironment(repo_path, "/var/empty")
self.ie = NoConfigEnvironment(irepo_path)
- self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
- self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
+ self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one", [])).next()
def test_01_contents(self):
self.assertEquals(self.pid.find_metadata("CONTENTS"), None)
@@ -73,7 +73,7 @@ class TestCase_02_MetadataKeys_suclassing(unittest.TestCase):
def value(self):
e = NoConfigEnvironment(repo_path, "/var/empty")
- pid = iter(e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ pid = iter(e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
return pid
def raw_name(self):
diff --git a/python/package_id_TEST.py b/python/package_id_TEST.py
index 24d43d8dc..123387ee5 100755
--- a/python/package_id_TEST.py
+++ b/python/package_id_TEST.py
@@ -32,11 +32,11 @@ class TestCase_01_PackageID(unittest.TestCase):
def setUp(self):
self.e = NoConfigEnvironment(repo_path, "/var/empty")
self.ie = NoConfigEnvironment(irepo_path)
- self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar", [])).next()
if os.environ.get("PALUDIS_ENABLE_VIRTUALS_REPOSITORY") == "yes":
- self.vpid = iter(self.e.package_database.fetch_repository("virtuals").package_ids("virtual/bar")).next()
- self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()
- self.mpid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("cat/masked")).next()
+ self.vpid = iter(self.e.package_database.fetch_repository("virtuals").package_ids("virtual/bar", [])).next()
+ self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one", [])).next()
+ self.mpid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("cat/masked", [])).next()
def test_01_get(self):
pass
diff --git a/python/repository.cc b/python/repository.cc
index bbcce3862..6cc475675 100644
--- a/python/repository.cc
+++ b/python/repository.cc
@@ -18,6 +18,8 @@
*/
#include <python/paludis_python.hh>
+#include <python/exception.hh>
+#include <python/options.hh>
#include <python/iterable.hh>
#include <paludis/repository.hh>
@@ -132,32 +134,32 @@ void expose_repository()
)
.def("has_category_named", &Repository::has_category_named,
- "has_category_named(CategoryNamePart) -> bool\n"
+ "has_category_named(CategoryNamePart, RepositoryContentMayExcludes) -> bool\n"
"Do we have a category with the given name?"
)
.def("has_package_named", &Repository::has_package_named,
- "has_package_named(QualifiedPackageName) -> bool\n"
+ "has_package_named(QualifiedPackageName, RepositoryContentMayExcludes) -> bool\n"
"Do we have a package in the given category with the given name?"
)
- .add_property("category_names", &Repository::category_names,
- "[ro] CategoryNamePartIterable\n"
+ .def("category_names", &Repository::category_names,
+ "category_names(RepositoryContentMayExcludes) -> CategoryNamePartIterable\n"
"Our category names."
)
.def("category_names_containing_package", &Repository::category_names_containing_package,
- "category_names_containing_package(PackageNamePart) -> CategoryNamePartIterable\n"
+ "category_names_containing_package(PackageNamePart, RepositoryContentMayExcludes) -> CategoryNamePartIterable\n"
"Fetch categories that contain a named package."
)
.def("package_names", &Repository::package_names,
- "package_names(CategoryNamePart) -> QualifiedPackageNameIterable\n"
+ "package_names(CategoryNamePart, RepositoryContentMayExcludes) -> QualifiedPackageNameIterable\n"
"Fetch our package names."
)
.def("package_ids", &Repository::package_ids, bp::with_custodian_and_ward_postcall<0, 1>(),
- "package_ids(QualifiedPackageName) -> PackageIDIterable\n"
+ "package_ids(QualifiedPackageName, RepositoryContentMayExcludes) -> PackageIDIterable\n"
"Fetch our versions."
)
@@ -279,4 +281,11 @@ void expose_repository()
.def("add_version", &FakeRepositoryWrapper::add_version)
;
+
+ enum_auto("RepositoryContentMayExclude", last_rcme,
+ "Tells repository it may exclude certain content from queries if doing so will be faster.");
+
+ class_options<RepositoryContentMayExcludes>("RepositoryContentMayExcludes", "RepositoryContentMayExclude",
+ "Options for various Repository methods.");
}
+
diff --git a/python/repository_TEST.py b/python/repository_TEST.py
index 16eaa4834..711efbed4 100755
--- a/python/repository_TEST.py
+++ b/python/repository_TEST.py
@@ -53,30 +53,30 @@ class TestCase_01_Repository(unittest.TestCase):
self.assertEquals(str(irepo.name), "installed")
def test_05_has_category_named(self):
- self.assert_(repo.has_category_named("foo"))
- self.assert_(not repo.has_category_named("bar"))
+ self.assert_(repo.has_category_named("foo", []))
+ self.assert_(not repo.has_category_named("bar", []))
def test_06_has_package_named(self):
- self.assert_(repo.has_package_named("foo/bar"))
- self.assert_(not repo.has_package_named("foo/foo"))
- self.assert_(not repo.has_package_named("bar/foo"))
+ self.assert_(repo.has_package_named("foo/bar", []))
+ self.assert_(not repo.has_package_named("foo/foo", []))
+ self.assert_(not repo.has_package_named("bar/foo", []))
def test_07_package_ids(self):
- y = list(x.version for x in repo.package_ids("foo/bar"));
+ y = list(x.version for x in repo.package_ids("foo/bar", []));
y.sort()
z = [VersionSpec("1.0"), VersionSpec("2.0")]
self.assertEquals(y, z)
- self.assertEquals(len(list(repo.package_ids("bar/baz"))), 0)
+ self.assertEquals(len(list(repo.package_ids("bar/baz", []))), 0)
def test_08_category_names(self):
- self.assertEquals([str(x) for x in repo.category_names], ["foo", "foo1", "foo2", "foo3", "foo4"])
+ self.assertEquals([str(x) for x in repo.category_names([])], ["foo", "foo1", "foo2", "foo3", "foo4"])
def test_09_category_names_containing_package(self):
- self.assertEquals([str(x) for x in repo.category_names_containing_package("bar")],
+ self.assertEquals([str(x) for x in repo.category_names_containing_package("bar", [])],
["foo", "foo1", "foo2", "foo3", "foo4"])
def test_10_package_names(self):
- for (i, qpn) in enumerate(repo.package_names("bar")):
+ for (i, qpn) in enumerate(repo.package_names("bar", [])):
self.assertEquals(i, 0)
self.assertEquals(str(qpn), "foo/bar")
@@ -161,14 +161,14 @@ class TestCase_03_FakeRepository(unittest.TestCase):
self.assertRaises(Exception, FakeRepository, "foo", "foo")
def test_03_add_category(self):
- self.assertEquals(list(f.category_names), [])
+ self.assertEquals(list(f.category_names([])), [])
f.add_category("cat-foo")
- self.assertEquals([str(x) for x in f.category_names], ["cat-foo"])
+ self.assertEquals([str(x) for x in f.category_names([])], ["cat-foo"])
f.add_category("cat-foo")
- self.assertEquals([str(x) for x in f.category_names], ["cat-foo"])
+ self.assertEquals([str(x) for x in f.category_names([])], ["cat-foo"])
f.add_category("cat-bar")
- self.assertEquals([str(x) for x in f.category_names], ["cat-bar", "cat-foo"])
+ self.assertEquals([str(x) for x in f.category_names([])], ["cat-bar", "cat-foo"])
def test_04_add_category_bad(self):
self.assertRaises(Exception, f.add_category, 1)
@@ -180,18 +180,18 @@ class TestCase_03_FakeRepository(unittest.TestCase):
bar_1 = QualifiedPackageName("cat-bar/pkg1")
f.add_category("cat-foo")
- self.assertEquals(list(f.package_names("cat-foo")), [])
+ self.assertEquals(list(f.package_names("cat-foo", [])), [])
f.add_package(foo_1)
- self.assertEquals(list(f.package_names("cat-foo")), [foo_1])
+ self.assertEquals(list(f.package_names("cat-foo", [])), [foo_1])
f.add_package(foo_1)
- self.assertEquals(list(f.package_names("cat-foo")), [foo_1])
+ self.assertEquals(list(f.package_names("cat-foo", [])), [foo_1])
f.add_package(foo_2)
- self.assertEquals(list(f.package_names("cat-foo")), [foo_1, foo_2])
+ self.assertEquals(list(f.package_names("cat-foo", [])), [foo_1, foo_2])
f.add_package(bar_1)
- self.assertEquals(list(f.package_names("cat-bar")), [bar_1])
+ self.assertEquals(list(f.package_names("cat-bar", [])), [bar_1])
def test_06_add_package_bad(self):
self.assertRaises(Exception, f.add_category, 1)
@@ -199,20 +199,20 @@ class TestCase_03_FakeRepository(unittest.TestCase):
def test_07_add_version(self):
f.add_package("cat-foo/pkg")
- self.assertEquals(list(f.package_ids("cat-foo/pkg")), [])
+ self.assertEquals(list(f.package_ids("cat-foo/pkg", [])), [])
pkg = f.add_version("cat-foo/pkg", VersionSpec("1"))
- self.assertEquals(list(f.package_ids("cat-foo/pkg")), [pkg])
+ self.assertEquals(list(f.package_ids("cat-foo/pkg", [])), [pkg])
self.assertEquals(pkg.version, VersionSpec("1"))
pkg2 = f.add_version("cat-foo/pkg", VersionSpec("2"))
- self.assertEquals(list(f.package_ids("cat-foo/pkg")), [pkg, pkg2])
+ self.assertEquals(list(f.package_ids("cat-foo/pkg", [])), [pkg, pkg2])
self.assertEquals(pkg2.version, VersionSpec("2"))
pkg3 = f.add_version("cat-bar/pkg", VersionSpec("0"))
- self.assertEquals(list(f.package_ids("cat-bar/pkg")), [pkg3])
+ self.assertEquals(list(f.package_ids("cat-bar/pkg", [])), [pkg3])
- self.assertEquals([str(x) for x in f.category_names], ["cat-bar", "cat-foo"])
+ self.assertEquals([str(x) for x in f.category_names([])], ["cat-bar", "cat-foo"])
def test_08_add_version_bad(self):
self.assertRaises(Exception, f.add_version, 1)