diff options
author | 2011-07-16 14:33:19 +0100 | |
---|---|---|
committer | 2011-07-16 14:33:19 +0100 | |
commit | 7ce688d7cf41055a607d933077664c1160ae0a30 (patch) | |
tree | 2fe5383071f82609b25b6868ce43ac2446d375f3 | |
parent | 031c98dfc6043c73bfde593a8252113788b15b3c (diff) | |
download | paludis-7ce688d7cf41055a607d933077664c1160ae0a30.tar.gz paludis-7ce688d7cf41055a607d933077664c1160ae0a30.tar.xz |
Wrap SlotRequirement
-rw-r--r-- | python/Makefile.am | 1 | ||||
-rw-r--r-- | python/dep_spec.cc | 6 | ||||
-rwxr-xr-x | python/dep_spec_TEST.py | 7 | ||||
-rw-r--r-- | python/paludis_python.hh | 1 | ||||
-rw-r--r-- | python/paludis_python_so.cc | 1 | ||||
-rw-r--r-- | python/slot_requirement.cc | 150 |
6 files changed, 159 insertions, 7 deletions
diff --git a/python/Makefile.am b/python/Makefile.am index 61efbd79e..eded71ba6 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -72,6 +72,7 @@ IF_PYTHON_SOURCES = \ package_id.cc \ repository.cc \ selection.cc \ + slot_requirement.cc \ version_operator.cc \ version_requirements.cc \ version_spec.cc diff --git a/python/dep_spec.cc b/python/dep_spec.cc index e42ac17d6..9f544929a 100644 --- a/python/dep_spec.cc +++ b/python/dep_spec.cc @@ -1215,12 +1215,10 @@ void expose_dep_spec() "Version requirements mode." ) -#if 0 - .add_property("slot", &PythonPackageDepSpec::slot_ptr, - "[ro] SlotName\n" + .add_property("slot_requirement", &PythonPackageDepSpec::slot_requirement_ptr, + "[ro] SlotRequirement\n" "Slot name (may be None)." ) -#endif .add_property("in_repository", &PythonPackageDepSpec::in_repository_ptr, "[ro] RepositoryName\n" diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py index ec22662c4..fb05ba232 100755 --- a/python/dep_spec_TEST.py +++ b/python/dep_spec_TEST.py @@ -58,9 +58,10 @@ class TestCase_1_DepSpecs(unittest.TestCase): self.assertEqual(str(self.bds.blocking), ">=foo/bar-1:100::testrepo") self.assertEqual(str(self.nds), "system") -### def test_04_slot(self): -### self.get_depspecs() -### self.assertEqual(str(self.pds.slot), "100") + def test_04_slot(self): + self.get_depspecs() + self.assert_(isinstance(self.pds.slot_requirement, SlotExactRequirement)) + self.assertEqual(str(self.pds.slot_requirement.slot), "100") def test_05_package(self): self.get_depspecs() diff --git a/python/paludis_python.hh b/python/paludis_python.hh index aacf7beac..61bb8a86b 100644 --- a/python/paludis_python.hh +++ b/python/paludis_python.hh @@ -191,6 +191,7 @@ void expose_name() PALUDIS_VISIBLE; void expose_package_id() PALUDIS_VISIBLE; void expose_repository() PALUDIS_VISIBLE; void expose_selection() PALUDIS_VISIBLE; +void expose_slot_requirement() 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 f8b4e3eca..a2b431417 100644 --- a/python/paludis_python_so.cc +++ b/python/paludis_python_so.cc @@ -39,6 +39,7 @@ BOOST_PYTHON_MODULE(paludis) expose_filter(); /* must be before dep_spec */ expose_dep_spec(); expose_dep_label(); + expose_slot_requirement(); expose_name(); expose_log(); expose_environment(); diff --git a/python/slot_requirement.cc b/python/slot_requirement.cc new file mode 100644 index 000000000..09453d968 --- /dev/null +++ b/python/slot_requirement.cc @@ -0,0 +1,150 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 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 + * 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 <python/exception.hh> + +#include <paludis/util/make_named_values.hh> +#include <paludis/util/sequence.hh> +#include <paludis/util/make_null_shared_ptr.hh> +#include <paludis/slot_requirement.hh> +#include <paludis/name.hh> +#include <memory> + +using namespace paludis; +using namespace paludis::python; +namespace bp = boost::python; + +namespace +{ + class SlotRequirementSptrToPythonVisitor + { + private: + const std::shared_ptr<const SlotRequirement> & _m_ptr; + + public: + boost::python::object obj; + + SlotRequirementSptrToPythonVisitor(const std::shared_ptr<const SlotRequirement> & m_ptr) : + _m_ptr(m_ptr) + { + } + + void visit(const SlotExactRequirement & k) + { + obj = bp::object(std::static_pointer_cast<const SlotExactRequirement>(_m_ptr)); + } + + void visit(const SlotAnyLockedRequirement & k) + { + obj = bp::object(std::static_pointer_cast<const SlotAnyLockedRequirement>(_m_ptr)); + } + + void visit(const SlotAnyUnlockedRequirement & k) + { + obj = bp::object(std::static_pointer_cast<const SlotAnyUnlockedRequirement>(_m_ptr)); + } + }; + + struct SlotRequirementSptrToPython + { + SlotRequirementSptrToPython() + { + bp::to_python_converter<std::shared_ptr<const SlotRequirement>, SlotRequirementSptrToPython>(); + } + + static PyObject * + convert(const std::shared_ptr<const SlotRequirement> & m) + { + SlotRequirementSptrToPythonVisitor v(m); + m->accept(v); + return bp::incref(v.obj.ptr()); + } + }; +} + +void expose_slot_requirement() +{ + SlotRequirementSptrToPython(); + + /** + * SlotRequirement + */ + bp::class_<SlotRequirement, boost::noncopyable> + ( + "SlotRequirement", + "A SlotRequirement represents a PackageDepSpec's slot requirement, " + "such as :3 , :* , := or :=3 .", + bp::no_init + ) + + .def("__str__", &SlotRequirement::as_string) + ; + + /** + * SlotExactRequirement + */ + register_shared_ptrs_to_python<SlotExactRequirement>(rsp_const); + bp::implicitly_convertible<std::shared_ptr<SlotExactRequirement>, std::shared_ptr<SlotRequirement> >(); + bp::class_<SlotExactRequirement, std::shared_ptr<SlotExactRequirement>, bp::bases<SlotRequirement>, boost::noncopyable> + ( + "SlotExactRequirement", + "A SlotExactRequirement is a SlotRequirement for exact slot requirements, " + "such as :3 or :=3 .", + bp::no_init + ) + + .add_property("slot", &SlotExactRequirement::slot, + "[ro] SlotName\n" + "The slot in question." + ) + + .add_property("from_any_locked", &SlotExactRequirement::from_any_locked, + "[ro] bool\n" + "If true, indicates we are a :=3 style dependency." + ) + ; + + /** + * SlotAnyLockedRequirement + */ + register_shared_ptrs_to_python<SlotAnyLockedRequirement>(rsp_const); + bp::implicitly_convertible<std::shared_ptr<SlotAnyLockedRequirement>, std::shared_ptr<SlotRequirement> >(); + bp::class_<SlotAnyLockedRequirement, std::shared_ptr<SlotAnyLockedRequirement>, bp::bases<SlotRequirement>, boost::noncopyable> + ( + "SlotAnyLockedRequirement", + "A SlotAnyLockedRequirement is a SlotRequirement for := slot requirements.", + bp::no_init + ) + ; + + /** + * SlotAnyUnlockedRequirement + */ + register_shared_ptrs_to_python<SlotAnyUnlockedRequirement>(rsp_const); + bp::implicitly_convertible<std::shared_ptr<SlotAnyUnlockedRequirement>, std::shared_ptr<SlotRequirement> >(); + bp::class_<SlotAnyUnlockedRequirement, std::shared_ptr<SlotAnyUnlockedRequirement>, bp::bases<SlotRequirement>, boost::noncopyable> + ( + "SlotAnyUnlockedRequirement", + "A SlotAnyUnlockedRequirement is a SlotRequirement for :* slot requirements.", + bp::no_init + ) + ; +} + |