aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-12-31 14:13:04 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-12-31 14:13:04 +0000
commit819f0f92f1b3c02f8bc52b0b02ddd08c198d4dc4 (patch)
tree08f763309159127c10d8ed16b64f91d7f1e693eb /python
parent716dfad8ca27d774b1b07b9a6783b2afe8a960c6 (diff)
downloadpaludis-819f0f92f1b3c02f8bc52b0b02ddd08c198d4dc4.tar.gz
paludis-819f0f92f1b3c02f8bc52b0b02ddd08c198d4dc4.tar.xz
Add some more UseRequirement variants, and change the syntax of the old ones.
Diffstat (limited to 'python')
-rw-r--r--python/use_requirements.cc89
-rwxr-xr-xpython/use_requirements_TEST.py33
2 files changed, 104 insertions, 18 deletions
diff --git a/python/use_requirements.cc b/python/use_requirements.cc
index 05fef3dc0..4599cb57b 100644
--- a/python/use_requirements.cc
+++ b/python/use_requirements.cc
@@ -20,6 +20,8 @@
#include <python/paludis_python.hh>
#include <paludis/use_requirements.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_id.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/visitor-impl.hh>
@@ -86,6 +88,11 @@ void expose_use_requirements()
"flag() -> UseFlagName\n"
"Our use flag."
)
+
+ .def("satisfied_by", &UseRequirement::satisfied_by,
+ "satisfied_by(Environment, PackageID) -> bool\n"
+ "Does the package meet the requirement?"
+ )
;
/**
@@ -109,9 +116,77 @@ void expose_use_requirements()
);
/**
+ * ConditionalUseRequirement
+ */
+ bp::class_<ConditionalUseRequirement, bp::bases<UseRequirement>, boost::noncopyable>
+ (
+ "ConditionalUseRequirement",
+ "A use requirement that depends on the use flags of the package it appears in.",
+ bp::no_init
+ )
+
+ .def("package_id", &ConditionalUseRequirement::package_id,
+ "package_id() -> PackageID\n"
+ "Out package."
+ )
+ ;
+
+ /**
+ * IfMineThenUseRequirement
+ */
+ bp::class_<IfMineThenUseRequirement, bp::bases<ConditionalUseRequirement> >
+ (
+ "IfMineThenUseRequirement",
+ "An if-then requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__init__(UseFlagName, PackageID)"
+ )
+ )
+ ;
+
+ /**
+ * IfNotMineThenUseRequirement
+ */
+ bp::class_<IfNotMineThenUseRequirement, bp::bases<ConditionalUseRequirement> >
+ (
+ "IfNotMineThenUseRequirement",
+ "An if-not-then requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__init__(UseFlagName, PackageID)"
+ )
+ )
+ ;
+
+ /**
+ * IfMineThenNotUseRequirement
+ */
+ bp::class_<IfMineThenNotUseRequirement, bp::bases<ConditionalUseRequirement> >
+ (
+ "IfMineThenNotUseRequirement",
+ "An if-then-not requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__init__(UseFlagName, PackageID)"
+ )
+ )
+ ;
+
+ /**
+ * IfNotMineThenNotUseRequirement
+ */
+ bp::class_<IfNotMineThenNotUseRequirement, bp::bases<ConditionalUseRequirement> >
+ (
+ "IfNotMineThenNotUseRequirement",
+ "An if-not-then-not requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__init__(UseFlagName, PackageID)"
+ )
+ )
+ ;
+
+ /**
* EqualUseRequirement
*/
- bp::class_<EqualUseRequirement, bp::bases<UseRequirement> >
+ bp::class_<EqualUseRequirement, bp::bases<ConditionalUseRequirement> >
(
"EqualUseRequirement",
"An equal requirement for a use flag.",
@@ -119,17 +194,12 @@ void expose_use_requirements()
"__init__(UseFlagName, PackageID)"
)
)
-
- .def("package_id", &EqualUseRequirement::package_id,
- "package_id() -> PackageID\n"
- "Our package."
- )
;
/**
* NotEqualUseRequirement
*/
- bp::class_<NotEqualUseRequirement, bp::bases<UseRequirement> >
+ bp::class_<NotEqualUseRequirement, bp::bases<ConditionalUseRequirement> >
(
"NotEqualUseRequirement",
"A not equal requirement for a use flag.",
@@ -137,11 +207,6 @@ void expose_use_requirements()
"__init__(UseFlagName, PackageID)"
)
)
-
- .def("package_id", &NotEqualUseRequirement::package_id,
- "package_id() -> PackageID\n"
- "Our package."
- )
;
}
diff --git a/python/use_requirements_TEST.py b/python/use_requirements_TEST.py
index 563e1abd6..82c6ad85a 100755
--- a/python/use_requirements_TEST.py
+++ b/python/use_requirements_TEST.py
@@ -27,17 +27,22 @@ class TestCase_1_UseRequirements(unittest.TestCase):
self.r = FakeRepository(self.e, "fake")
self.pid = self.r.add_version("cat/pkg", "1")
- self.ur1 = EnabledUseRequirement("foo")
- self.ur2 = DisabledUseRequirement("foo")
- self.ur3 = EqualUseRequirement("foo", self.pid)
- self.ur4 = NotEqualUseRequirement("foo", self.pid)
+ self.ur1 = EnabledUseRequirement("enabled")
+ self.ur2 = DisabledUseRequirement("enabled")
+ self.ur3 = IfMineThenUseRequirement("foo", self.pid)
+ self.ur4 = IfNotMineThenUseRequirement("foo", self.pid)
+ self.ur5 = IfMineThenNotUseRequirement("foo", self.pid)
+ self.ur6 = IfNotMineThenNotUseRequirement("foo", self.pid)
+ self.ur7 = EqualUseRequirement("foo", self.pid)
+ self.ur8 = NotEqualUseRequirement("foo", self.pid)
def test_01_create(self):
self.assertRaises(Exception, UseRequirement)
+ self.assertRaises(Exception, ConditionalUseRequirement)
def test_02_flag(self):
- self.assertEquals(self.ur1.flag(), UseFlagName("foo"))
- self.assertEquals(self.ur2.flag(), UseFlagName("foo"))
+ self.assertEquals(self.ur1.flag(), UseFlagName("enabled"))
+ self.assertEquals(self.ur2.flag(), UseFlagName("enabled"))
self.assertEquals(self.ur3.flag(), UseFlagName("foo"))
self.assertEquals(self.ur4.flag(), UseFlagName("foo"))
@@ -45,6 +50,22 @@ class TestCase_1_UseRequirements(unittest.TestCase):
self.assertEquals(self.ur3.package_id(), self.pid)
self.assertEquals(self.ur4.package_id(), self.pid)
+ def test_04_satisfied_by(self):
+ self.assert_(self.ur1.satisfied_by(self.e, self.pid))
+ self.assert_(not self.ur2.satisfied_by(self.e, self.pid))
+
+ def test_05_hierarchy(self):
+ self.assert_(isinstance(self.ur1, UseRequirement))
+ self.assert_(not isinstance(self.ur1, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur2, UseRequirement))
+ self.assert_(not isinstance(self.ur2, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur3, UseRequirement))
+ self.assert_(isinstance(self.ur3, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur4, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur5, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur6, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur7, ConditionalUseRequirement))
+ self.assert_(isinstance(self.ur8, ConditionalUseRequirement))
if __name__ == "__main__":
unittest.main()