aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-12-30 18:35:12 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-12-30 18:35:12 +0000
commit2c11d05f01a58712ceb22954bb52a8afdcfb43a0 (patch)
tree34b713a3c3c5a207591648ba7eed9a9f8d2759f1
parent1cca7d05c5b6019c6fab003c99db5313dcf94c21 (diff)
downloadpaludis-2c11d05f01a58712ceb22954bb52a8afdcfb43a0.tar.gz
paludis-2c11d05f01a58712ceb22954bb52a8afdcfb43a0.tar.xz
(python) Fix UseRequirements after r4105. Fixes: ticket:464.
-rw-r--r--python/Makefile.am2
-rw-r--r--python/dep_spec.cc16
-rwxr-xr-xpython/dep_spec_TEST.py9
-rw-r--r--python/paludis_python.hh1
-rw-r--r--python/paludis_python_so.cc1
-rw-r--r--python/use_requirements.cc147
-rwxr-xr-xpython/use_requirements_TEST.py50
7 files changed, 205 insertions, 21 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index afc2239..ff53d4d 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -27,6 +27,7 @@ IF_PYTHON_TESTS = \
version_operator_TEST.py \
version_requirements_TEST.py \
contents_TEST.py \
+ use_requirements_TEST.py \
dep_spec_TEST.py \
dep_tag_TEST.py \
dep_label_TEST.py \
@@ -72,6 +73,7 @@ IF_PYTHON_SOURCES = \
package_id.cc \
query.cc \
repository.cc \
+ use_requirements.cc \
version_operator.cc \
version_requirements.cc \
version_spec.cc
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index 1dbf7b9..b89bbad 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -1176,22 +1176,6 @@ void expose_dep_spec()
;
/**
- * UseRequirements
- */
- bp::to_python_converter<std::pair<const UseFlagName, UseFlagState>,
- pair_to_tuple<const UseFlagName, UseFlagState> >();
- register_shared_ptrs_to_python<UseRequirements>();
- bp::class_<UseRequirements>
- (
- "UseRequirements",
- "A selection of USE flag requirements.",
- bp::no_init
- )
-
- .def("__iter__", bp::range(&UseRequirements::begin, &UseRequirements::end))
- ;
-
- /**
* PackageDepSpec
*/
diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py
index c988d3b..b16f68d 100755
--- a/python/dep_spec_TEST.py
+++ b/python/dep_spec_TEST.py
@@ -79,11 +79,10 @@ class TestCase_1_DepSpecs(unittest.TestCase):
self.get_depspecs()
self.assertEquals(self.pds.version_requirements_mode, VersionRequirementsMode.AND)
-### def test_09_use_requirements(self):
-### spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
-### ur = iter(spec.use_requirements).next()
-### self.assertEquals(str(ur[0]), "foo")
-### self.assertEquals(ur[1], UseFlagState.ENABLED)
+ def test_09_use_requirements(self):
+ spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
+ ur = iter(spec.use_requirements).next()
+ self.assert_(isinstance(ur, EnabledUseRequirement))
def test_10_without_use_requirements(self):
spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 05d83a6..9e20f1a 100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -177,6 +177,7 @@ void expose_package_id() PALUDIS_VISIBLE;
void expose_qa() PALUDIS_VISIBLE;
void expose_query() PALUDIS_VISIBLE;
void expose_repository() PALUDIS_VISIBLE;
+void expose_use_requirements() PALUDIS_VISIBLE;
void expose_version_operator() PALUDIS_VISIBLE;
void expose_version_requirements() PALUDIS_VISIBLE;
void expose_version_spec() PALUDIS_VISIBLE;
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index 016f7df..c24d51c 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -36,6 +36,7 @@ BOOST_PYTHON_MODULE(paludis)
expose_version_requirements();
expose_fs_entry();
expose_contents();
+ expose_use_requirements();
expose_dep_spec();
expose_dep_tag();
expose_dep_label();
diff --git a/python/use_requirements.cc b/python/use_requirements.cc
new file mode 100644
index 0000000..05fef3d
--- /dev/null
+++ b/python/use_requirements.cc
@@ -0,0 +1,147 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <python/paludis_python.hh>
+
+#include <paludis/use_requirements.hh>
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/visitor-impl.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct UseRequirementsWrapper
+{
+ static PyObject *
+ find(const UseRequirements & self, const UseFlagName & u)
+ {
+ UseRequirements::ConstIterator i(self.find(u));
+ if (i != self.end())
+ return bp::incref(bp::object(*i).ptr());
+ else
+ return Py_None;
+ }
+};
+
+void expose_use_requirements()
+{
+ /**
+ * UseRequirements
+ */
+ register_shared_ptrs_to_python<UseRequirements>();
+ bp::class_<UseRequirements>
+ (
+ "UseRequirements",
+ "A selection of USE flag requirements.",
+ bp::no_init
+ )
+
+ .def("empty", &UseRequirements::empty,
+ "empty() -> bool\n"
+ "Are we empty?"
+ )
+
+ .def("find", UseRequirementsWrapper::find,
+ "find(UseFlagName) -> UseRequirement\n"
+ "Find the requirement for a particular USE flag."
+ )
+
+ .def("insert", &UseRequirements::insert,
+ "insert(UseRequirement)\n"
+ "Insert a new requirement."
+ )
+
+ .def("__iter__", bp::range(&UseRequirements::begin, &UseRequirements::end))
+ ;
+
+ /**
+ * UseRequirement
+ */
+ register_shared_ptrs_to_python<UseRequirement>();
+ bp::class_<UseRequirement, boost::noncopyable>
+ (
+ "UseRequirement",
+ "A requirement for a use flag.",
+ bp::no_init
+ )
+
+ .def("flag", &UseRequirement::flag,
+ "flag() -> UseFlagName\n"
+ "Our use flag."
+ )
+ ;
+
+ /**
+ * EnabledUseRequirement
+ */
+ bp::class_<EnabledUseRequirement, bp::bases<UseRequirement>, tr1::shared_ptr<EnabledUseRequirement> >
+ (
+ "EnabledUseRequirement",
+ "An enabled requirement for a use flag.",
+ bp::init<const UseFlagName &>("__init__(UseFlagName)")
+ );
+
+ /**
+ * DisabledUseRequirement
+ */
+ bp::class_<DisabledUseRequirement, bp::bases<UseRequirement> >
+ (
+ "DisabledUseRequirement",
+ "A disabled requirement for a use flag.",
+ bp::init<const UseFlagName &>("__init__(UseFlagName)")
+ );
+
+ /**
+ * EqualUseRequirement
+ */
+ bp::class_<EqualUseRequirement, bp::bases<UseRequirement> >
+ (
+ "EqualUseRequirement",
+ "An equal requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__init__(UseFlagName, PackageID)"
+ )
+ )
+
+ .def("package_id", &EqualUseRequirement::package_id,
+ "package_id() -> PackageID\n"
+ "Our package."
+ )
+ ;
+
+ /**
+ * NotEqualUseRequirement
+ */
+ bp::class_<NotEqualUseRequirement, bp::bases<UseRequirement> >
+ (
+ "NotEqualUseRequirement",
+ "A not equal requirement for a use flag.",
+ bp::init<const UseFlagName &, const tr1::shared_ptr<const PackageID> &>(
+ "__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
new file mode 100755
index 0000000..563e1ab
--- /dev/null
+++ b/python/use_requirements_TEST.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# Copyright (c) 2007 Piotr Jaroszyński
+#
+# 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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+from paludis import *
+import unittest
+
+class TestCase_1_UseRequirements(unittest.TestCase):
+ def setUp(self):
+ self.e = TestEnvironment()
+ 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)
+
+ def test_01_create(self):
+ self.assertRaises(Exception, UseRequirement)
+
+ def test_02_flag(self):
+ self.assertEquals(self.ur1.flag(), UseFlagName("foo"))
+ self.assertEquals(self.ur2.flag(), UseFlagName("foo"))
+ self.assertEquals(self.ur3.flag(), UseFlagName("foo"))
+ self.assertEquals(self.ur4.flag(), UseFlagName("foo"))
+
+ def test_03_package_id(self):
+ self.assertEquals(self.ur3.package_id(), self.pid)
+ self.assertEquals(self.ur4.package_id(), self.pid)
+
+
+if __name__ == "__main__":
+ unittest.main()