aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-06-21 15:34:28 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-06-21 15:34:28 +0000
commit6844c38b9b9e5f538168742cf022759ee4ed9f68 (patch)
tree5171f0f2947a8df33da2cbe9b4389e47ef0f2a37
parenta4faee5260290510d16e2dfc9ca18288dabb2b79 (diff)
downloadpaludis-6844c38b9b9e5f538168742cf022759ee4ed9f68.tar.gz
paludis-6844c38b9b9e5f538168742cf022759ee4ed9f68.tar.xz
(python) Add DepTag.
-rw-r--r--python/Makefile.am2
-rw-r--r--python/dep_spec.cc16
-rw-r--r--python/dep_tag.cc197
-rwxr-xr-xpython/dep_tag_TEST.py113
-rw-r--r--python/paludis_python_so.cc2
5 files changed, 330 insertions, 0 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 315d2f2..1b56a28 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -30,6 +30,7 @@ IF_PYTHON_TESTS = \
dep_spec_TEST.py \
eapi_TEST.py \
portage_dep_parser_TEST.py \
+ dep_tag_TEST.py \
log_TEST.py \
name_TEST.py \
query_TEST.py \
@@ -43,6 +44,7 @@ IF_PYTHON_QA_TESTS =
IF_PYTHON_SOURCES = \
contents.cc \
dep_spec.hh dep_spec.cc \
+ dep_tag.cc \
eapi.cc \
environment.cc \
exception.hh exception.cc \
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index 01aefd5..73ba1ce 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -922,6 +922,21 @@ void register_tree_to_python()
tree_to_python<tr1::shared_ptr<typename T_::ConstItem> > >();
}
+struct sp_package_dep_spec_to_python
+{
+ static PyObject *
+ convert(const tr1::shared_ptr<const PackageDepSpec> & d)
+ {
+ PythonPackageDepSpec pyd(*d);
+ return bp::incref(bp::object(pyd).ptr());
+ }
+};
+
+void register_sp_package_dep_spec_to_python()
+{
+ bp::to_python_converter<tr1::shared_ptr<const PackageDepSpec>, sp_package_dep_spec_to_python>();
+}
+
template <typename H_>
struct RegisterSpecTreeFromPython
@@ -1150,6 +1165,7 @@ void PALUDIS_VISIBLE expose_dep_spec()
RegisterPackageDepSpecSPFromPython();
bp::implicitly_convertible<PackageDepSpec, PythonPackageDepSpec>();
+ register_sp_package_dep_spec_to_python();
bp::class_<PythonPackageDepSpec, tr1::shared_ptr<const PythonPackageDepSpec>, bp::bases<PythonStringDepSpec> >
pkgds("PackageDepSpec",
diff --git a/python/dep_tag.cc b/python/dep_tag.cc
new file mode 100644
index 0000000..bce851f
--- /dev/null
+++ b/python/dep_tag.cc
@@ -0,0 +1,197 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
+ *
+ * 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 <paludis_python.hh>
+
+#include <paludis/dep_tag.hh>
+#include <paludis/dep_spec.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct DepTagCategoryMakerWrapper
+{
+ // More convenient way of creating DepTagCategories
+ static tr1::shared_ptr<const DepTagCategory>
+ make_from_id(const DepTagCategoryMaker & self, const std::string & id)
+ {
+ return self[id]();
+ }
+};
+
+void PALUDIS_VISIBLE expose_dep_tag()
+{
+ /**
+ * Exceptions.
+ */
+ ExceptionRegister::get_instance()->add_exception<NoSuchDepTagCategory>
+ ("NoSuchDepTagCategory", "BaseException",
+ "Thrown if DepTagCategoryMaker cannot find the named DepTagCategory.");
+
+ /**
+ * DepTagCategory
+ */
+ register_shared_ptrs_to_python<DepTagCategory>();
+ bp::class_<DepTagCategory, boost::noncopyable>
+ (
+ "DepTagCategory",
+ "A DepTagCategory is identified by its name and has associated display "
+ "information for a DepTag's category.",
+ bp::no_init
+ )
+ .add_property("visible", &DepTagCategory::visible,
+ "[ro] bool\n"
+ "Should we be displayed in a tag category summary?"
+ )
+
+ .add_property("id", &DepTagCategory::id,
+ "[ro] string\n"
+ "Fetch our short ID (for example, 'GLSA')."
+ )
+
+ .add_property("title", &DepTagCategory::title,
+ "[ro] string\n"
+ "Fetch our title (for example, 'Security advisories'), or an "
+ "empty string if we're untitled."
+ )
+
+ .add_property("pre_text", &DepTagCategory::pre_text,
+ "[ro] string\n"
+ "Fetch our pre list text, or an empty string."
+ )
+
+ .add_property("post_text", &DepTagCategory::post_text,
+ "[ro] string\n"
+ "Fetch our post list text, or an empty string."
+ )
+ ;
+
+ /**
+ * DepTagCategoryMaker
+ */
+ bp::class_<DepTagCategoryMaker, boost::noncopyable>
+ (
+ "DepTagCategoryMaker",
+ "Virtual constructor for accessing DepTagCategory instances.",
+ bp::no_init
+ )
+ .add_static_property("instance", bp::make_function(&DepTagCategoryMaker::get_instance,
+ bp::return_value_policy<bp::reference_existing_object>()),
+ "Singleton instance."
+ )
+
+ .def("make_from_id", &DepTagCategoryMakerWrapper::make_from_id,
+ "make_from_id(id_string) -> DepTagCategory\n"
+ "Make DepTagCategory from id."
+ )
+ ;
+
+ /**
+ * DepTag
+ */
+ bp::class_<DepTag, boost::noncopyable>
+ (
+ "DepTag",
+ "A DepTag can be associated with a PackageDepSpec, and is transferred "
+ "onto any associated DepListEntry instances.",
+ bp::no_init
+ )
+ .add_property("short_text", &DepTag::short_text,
+ "[ro] string\n"
+ "Our short text (for example, 'GLSA-1234') that is "
+ "displayed with the dep list entry."
+ )
+
+ .add_property("category", &DepTag::category,
+ "[ro] string\n"
+ "Our DepTagCategory's tag."
+ )
+
+ .def("__cmp__", &py_cmp<DepTag>)
+ ;
+
+ /**
+ * GLSADepTag
+ */
+ bp::class_<GLSADepTag, bp::bases<DepTag>, boost::noncopyable>
+ (
+ "GLSADepTag",
+ "DepTag subclass for GLSAs.",
+ bp::init<const std::string &, const std::string &>("__init__(id_str, glsa_title_str)")
+ )
+ .add_property("glsa_title", &GLSADepTag::glsa_title,
+ "Our GLSA title (for example, 'Yet another PHP remote access hole')"
+ )
+ ;
+
+ /**
+ * GeneralSetDepTag
+ */
+ bp::class_<GeneralSetDepTag, bp::bases<DepTag>, boost::noncopyable>
+ (
+ "GeneralSetDepTag",
+ "DepTag subclass for general sets.",
+ bp::init<const SetName &, const std::string &>("__init__(SetName, source_str)")
+ )
+ .add_property("source", &GeneralSetDepTag::source,
+ "From which repository or environment did we originate?"
+ )
+ ;
+
+ /**
+ * DependencyDepTag
+ */
+ bp::class_<DependencyDepTag, bp::bases<DepTag>, boost::noncopyable>
+ (
+ "DependencyDepTag",
+ "DepTag subclass for dependencies.",
+ bp::init<const PackageDatabaseEntry &, const PackageDepSpec &,
+ tr1::shared_ptr<DependencySpecTree::ConstItem> >(
+ "__init__(PackageDatabaseEntry, PackageDepSpec, CompositeDepSpec)"
+ )
+ )
+ .add_property("package", &DependencyDepTag::package,
+ "[ro] PackageDatabaseEntry\n"
+ "The PackageDatabaseEntry that contains our dependency."
+ )
+
+ .add_property("dependency", bp::make_function(&DependencyDepTag::dependency,
+ bp::return_value_policy<bp::return_by_value>()),
+ "[ro] PackageDepSpec\n"
+ "The PackageDepSpec that pulled us in."
+ )
+
+ .add_property("conditions", &DependencyDepTag::conditions,
+ "[ro] CompositeDepSpec\n"
+ "The AllDepSpecs and UseDepSpecs that our dependency is conditional upon."
+ )
+ ;
+
+ /**
+ * TargetDepTag
+ */
+ bp::class_<TargetDepTag, bp::bases<DepTag>, boost::noncopyable>
+ (
+ "TargetDepTag",
+ "DepTag subclass for explicit targets.",
+ bp::init<>("__init__()")
+ )
+ ;
+}
diff --git a/python/dep_tag_TEST.py b/python/dep_tag_TEST.py
new file mode 100755
index 0000000..c87c730
--- /dev/null
+++ b/python/dep_tag_TEST.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
+#
+# 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_01_DepTag(unittest.TestCase):
+ def test_01_no_create(self):
+ self.assertRaises(Exception, DepTag)
+
+class TestCase_02_GLSADepTag(unittest.TestCase):
+ def setUp(self):
+ global dt
+ dt = GLSADepTag("id", "title")
+
+ def test_01_instance(self):
+ self.assert_(isinstance(dt, DepTag))
+
+ def test_02_properties(self):
+ self.assertEquals(dt.category, "glsa")
+ self.assertEquals(dt.short_text, "GLSA-id")
+ self.assertEquals(dt.glsa_title, "title")
+
+class TestCase_03_GeneralSetDepTag(unittest.TestCase):
+ def setUp(self):
+ global dt
+ dt = GeneralSetDepTag("set_name", "source")
+
+ def test_01_instance(self):
+ self.assert_(isinstance(dt, DepTag))
+
+ def test_02_properties(self):
+ self.assertEquals(dt.category, "general")
+ self.assertEquals(dt.short_text, "set_name")
+ self.assertEquals(dt.source, "source")
+
+class TestCase_04_DependencyDepTag(unittest.TestCase):
+ def setUp(self):
+ global dt, pde, pds, cds
+ pde = PackageDatabaseEntry("cat/foo", "1.0", "repo")
+ pds = PackageDepSpec("=cat/boo-1", PackageDepSpecParseMode.PERMISSIVE)
+ cds = PortageDepParser.parse_depend("", EAPIData.instance.eapi_from_string("0"))
+ dt = DependencyDepTag(pde, pds, cds);
+
+ def test_01_instance(self):
+ self.assert_(isinstance(dt, DepTag))
+
+ def test_02_properties(self):
+ self.assertEquals(dt.category, "dependency")
+ self.assertEquals(dt.short_text, str(pde))
+ self.assertEquals(dt.package, pde)
+ self.assertEquals(str(dt.dependency), str(pds))
+ self.assert_(isinstance(dt.conditions, AllDepSpec))
+
+class TestCase_05_TargetDepTag(unittest.TestCase):
+ def setUp(self):
+ global dt
+ dt = TargetDepTag()
+
+ def test_01_instance(self):
+ self.assert_(isinstance(dt, DepTag))
+
+ def test_02_properties(self):
+ self.assertEquals(dt.category, "target")
+ self.assertEquals(dt.short_text, "target")
+
+class TestCase_06_DepTagCategoryMaker(unittest.TestCase):
+ def test_01_no_create(self):
+ self.assertRaises(Exception, DepTagCategoryMaker)
+
+ def test_02_instance(self):
+ self.assert_(isinstance(DepTagCategoryMaker.instance, DepTagCategoryMaker))
+
+ def test_03_make_from_id(self):
+ cdt = DepTagCategoryMaker.instance.make_from_id("glsa")
+ self.assert_(isinstance(cdt, DepTagCategory))
+
+ self.assertRaises(NoSuchDepTagCategory, DepTagCategoryMaker.instance.make_from_id, "foo")
+
+class TestCase_07_DepTagCategory(unittest.TestCase):
+ def setUp(self):
+ global cdt
+ cdt = DepTagCategoryMaker.instance.make_from_id("glsa")
+
+ def test_01_no_create(self):
+ self.assertRaises(Exception, DepTagCategory)
+
+ def test_02_properties(self):
+ self.assertEquals(cdt.visible, True)
+ self.assertEquals(cdt.id, "glsa")
+ self.assertEquals(cdt.title, "Security advisories")
+ self.assertEquals(cdt.pre_text, "Your system is potentially affected by these security issues:")
+ self.assertEquals(cdt.post_text, "Please read the advisories carefully and take appropriate action.")
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index 62663a9..f5cdd30 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -23,6 +23,7 @@
void expose_contents();
void expose_dep_spec();
+void expose_dep_tag();
void expose_eapi();
void expose_environment();
void expose_exception();
@@ -55,6 +56,7 @@ BOOST_PYTHON_MODULE(paludis)
expose_mask_reasons();
expose_version_metadata();
expose_dep_spec();
+ expose_dep_tag();
expose_portage_dep_parser();
expose_name();
expose_log();