aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-02 16:03:40 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-02 16:03:40 +0000
commit4cee663f11f28a739e7c8b8b435b4712d32b9a12 (patch)
treede722d42600bc7051a2ae1cbee0f52985162fc74
parent1daa45d087b135979f1c7ef68dd9d03ebfeaa601 (diff)
downloadpaludis-4cee663f11f28a739e7c8b8b435b4712d32b9a12.tar.gz
paludis-4cee663f11f28a739e7c8b8b435b4712d32b9a12.tar.xz
(python) Add QA interface.
-rw-r--r--python/Makefile.am31
-rw-r--r--python/exception.cc17
-rw-r--r--python/exception.hh15
-rw-r--r--python/paludis_python_so.cc2
-rw-r--r--python/qa.cc72
-rwxr-xr-xpython/qa_TEST.py62
-rw-r--r--python/repository.cc28
-rwxr-xr-xpython/repository_TEST.py23
-rwxr-xr-xpython/repository_TEST_setup.sh4
9 files changed, 231 insertions, 23 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 4d78ef1..c72c4ae 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -38,7 +38,8 @@ IF_PYTHON_TESTS = \
metadata_key_TEST.py \
dep_list_TEST.py
-IF_PYTHON_QA_TESTS =
+IF_PYTHON_QA_TESTS = \
+ qa_TEST.py
IF_PYTHON_SOURCES = \
action.cc \
@@ -60,7 +61,8 @@ IF_PYTHON_SOURCES = \
version_requirements.cc \
version_spec.cc
-IF_PYTHON_QA_SOURCES =
+IF_PYTHON_QA_SOURCES = \
+ qa.cc
EXTRA_DIST = $(IF_PYTHON_TESTS) $(IF_PYTHON_SOURCES) \
$(IF_PYTHON_QA_TESTS) $(IF_PYTHON_QA_SOURCES) \
@@ -117,26 +119,15 @@ paludis_python_so.o : paludis_python_so.cc
if ENABLE_QA
libpaludispython_la_SOURCES = $(IF_PYTHON_SOURCES) $(IF_PYTHON_QA_SOURCES)
-libpaludispython_la_LIBADD = \
- $(top_builddir)/paludis/libpaludis.la \
- $(top_builddir)/paludis/util/libpaludisutil.la \
- $(top_builddir)/paludis/dep_list/libpaludisdeplist.la \
- $(top_builddir)/paludis/tasks/libpaludistasks.la \
- $(top_builddir)/paludis/repositories/libpaludisrepositories.la \
- $(top_builddir)/paludis/repositories/e/libpaludiserepository.la \
- $(top_builddir)/paludis/repositories/fake/libpaludisfakerepository.la \
- $(top_builddir)/paludis/environments/paludis/libpaludispaludisenvironment.la \
- $(top_builddir)/paludis/environments/no_config/libpaludisnoconfigenvironment.la \
- $(top_builddir)/paludis/environments/adapted/libpaludisadaptedenvironment.la \
- $(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
- $(top_builddir)/paludis/environments/libpaludisenvironments.la
-# $(top_builddir)/paludis/qa/libpaludisqa.la
-
-TESTS = $(IF_PYTHON_QA_TESTS) $(IF_PYTHON_TESTS)
+TESTS = $(IF_PYTHON_TESTS) $(IF_PYTHON_QA_TESTS)
else
libpaludispython_la_SOURCES = $(IF_PYTHON_SOURCES)
+TESTS = $(IF_PYTHON_TESTS)
+
+endif
+
libpaludispython_la_LIBADD = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
@@ -151,10 +142,6 @@ libpaludispython_la_LIBADD = \
$(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
$(top_builddir)/paludis/environments/libpaludisenvironments.la
-TESTS = $(IF_PYTHON_TESTS)
-
-endif
-
check_DATA = .libs/paludis.so
pythonlibdir = @PYTHON_INSTALL_DIR@
pythonlib_DATA = paludis.so
diff --git a/python/exception.cc b/python/exception.cc
index 421ec5c..6e44aa8 100644
--- a/python/exception.cc
+++ b/python/exception.cc
@@ -67,6 +67,17 @@ ExceptionRegister::get_py_exception(const std::string & name)
return NULL;
}
+PythonError::PythonError(const std::string & message) throw () :
+ Exception(message)
+{
+}
+
+PythonMethodNotImplemented::PythonMethodNotImplemented(const std::string & class_name,
+ const std::string & method_name) throw () :
+ PythonError("Python subclasses of '" + class_name + "' have to implement '" + method_name + "' method")
+{
+}
+
void PALUDIS_VISIBLE expose_exception()
{
/**
@@ -85,4 +96,10 @@ void PALUDIS_VISIBLE expose_exception()
"A NameError is an Exception that is thrown when some kind of invalid name is encountered.");
ExceptionRegister::get_instance()->add_exception<ConfigurationError>("ConfigurationError", "BaseException",
"A ConfigurationError is thrown when an invalid configuration occurs.");
+ ExceptionRegister::get_instance()->add_exception<PythonError>("PythonError", "BaseException",
+ "Base exception class for Python specific stuff.");
+ ExceptionRegister::get_instance()->add_exception<PythonMethodNotImplemented>("PythonMethodNotImplemented",
+ "PythonError",
+ "Thrown if a not implemented virtual function was called from C++.");
+
}
diff --git a/python/exception.hh b/python/exception.hh
index 62a9cde..df6c5e7 100644
--- a/python/exception.hh
+++ b/python/exception.hh
@@ -119,6 +119,21 @@ namespace paludis
new RegisteredException<Ex_>(name, doc, get_py_exception(base))));
}
};
+
+ class PALUDIS_VISIBLE PythonError :
+ public Exception
+ {
+ public:
+ PythonError(const std::string & message) throw ();
+ };
+
+ class PALUDIS_VISIBLE PythonMethodNotImplemented :
+ public PythonError
+ {
+ public:
+ PythonMethodNotImplemented(const std::string & class_name,
+ const std::string & function_name) throw ();
+ };
}
}
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index d11df54..f060cb3 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -34,6 +34,7 @@ void expose_metadata_key();
void expose_name();
void expose_package_database();
void expose_package_id();
+void expose_qa();
void expose_query();
void expose_repository();
void expose_version_operator();
@@ -64,4 +65,5 @@ BOOST_PYTHON_MODULE(paludis)
expose_action();
expose_package_database();
expose_repository();
+ expose_qa();
}
diff --git a/python/qa.cc b/python/qa.cc
new file mode 100644
index 0000000..3b8de59
--- /dev/null
+++ b/python/qa.cc
@@ -0,0 +1,72 @@
+/* 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/qa.hh>
+#include <paludis/util/options.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct QAReporterWrapper :
+ QAReporter,
+ bp::wrapper<QAReporter>
+{
+ void message(QAMessageLevel qml, const std::string & s, const std::string & m)
+ {
+ if (get_override("message"))
+ get_override("message")(qml, s, m);
+ else
+ throw PythonMethodNotImplemented("QAReporter", "message");
+ }
+};
+
+void PALUDIS_VISIBLE expose_qa()
+{
+ /**
+ * Enums
+ */
+ enum_auto("QAMessageLevel", last_qaml,
+ "The importance of a QA notice.");
+ enum_auto("QACheckProperty", last_qacp,
+ "Properties of a QA check.");
+
+ /**
+ * Options
+ */
+ class_options<QACheckProperties>("QACheckProperties", "QACheckProperty",
+ "NEED_DOC");
+
+ /**
+ * QAReporter
+ */
+ bp::class_<QAReporterWrapper, boost::noncopyable>
+ (
+ "QAReporter",
+ "NEED_DOC",
+ bp::init<>()
+ )
+ .def("message", bp::pure_virtual(&QAReporter::message),
+ "message(QAMessageLevel, str, str)\n"
+ "NEED_DOC"
+ )
+ ;
+}
diff --git a/python/qa_TEST.py b/python/qa_TEST.py
new file mode 100755
index 0000000..e486518
--- /dev/null
+++ b/python/qa_TEST.py
@@ -0,0 +1,62 @@
+#!/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_QACheckProperties(unittest.TestCase):
+ def test_01_create(self):
+ QACheckProperties()
+
+ def test_02_set(self):
+ qcp = QACheckProperties()
+
+ self.assert_(qcp.none)
+
+ qcp += QACheckProperty.NEEDS_BUILD
+ self.assert_(qcp[QACheckProperty.NEEDS_BUILD])
+ qcp += QACheckProperty.NEEDS_NETWORK
+ self.assert_(qcp[QACheckProperty.NEEDS_NETWORK])
+
+class TestCase_QAReporter(unittest.TestCase):
+ import paludis
+ if hasattr(paludis, "QAReporter"):
+ class PyQAR(QAReporter):
+ def __init__(self):
+ QAReporter.__init__(self)
+
+ def message(self, l, s, m):
+ return 1
+
+ def test_01_create(self):
+ QAReporter()
+
+ def test_02_no_message(self):
+ self.assertRaises(Exception, QAReporter().message, QAMessageLevel.DEBUG, "foo", "foo")
+
+ def test_03_subclass(self):
+ self.assert_(isinstance(self.PyQAR(), QAReporter))
+
+ def test_04_subclass_message(self):
+ self.assertEquals(self.PyQAR().message(QAMessageLevel.DEBUG, "foo", "foo"), 1)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/repository.cc b/python/repository.cc
index fea47a4..ba225e6 100644
--- a/python/repository.cc
+++ b/python/repository.cc
@@ -27,7 +27,9 @@
#include <paludis/action.hh>
#include <paludis/package_id.hh>
#include <paludis/environment.hh>
+#include <paludis/qa.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/options.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
@@ -117,6 +119,12 @@ struct RepositoryWrapper :
{
return self.e_interface;
}
+
+ static RepositoryQAInterface *
+ get_qa_interface(const Repository & self)
+ {
+ return self.qa_interface;
+ }
};
struct FakeRepositoryWrapper
@@ -337,6 +345,11 @@ void PALUDIS_VISIBLE expose_repository()
bp::return_internal_reference<>()),
"[ro] RepositoryEInterface"
)
+
+ .add_property("qa_interface", bp::make_function(&RepositoryWrapper::get_qa_interface,
+ bp::return_internal_reference<>()),
+ "[ro] RepositoryQAInterface"
+ )
;
/**
@@ -526,6 +539,21 @@ void PALUDIS_VISIBLE expose_repository()
;
/**
+ * RepositoryQAInterface
+ */
+ bp::class_<RepositoryQAInterface, boost::noncopyable>
+ (
+ "RepositoryQAInterface",
+ "Interface for handling QA tasks.",
+ bp::no_init
+ )
+ .def("check_qa", &RepositoryQAInterface::check_qa,
+ "check_qa(QAReporter, QACheckProperties, QACheckProperties, QAMessageLevel, path)\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
* FakeRepository
*/
bp::implicitly_convertible<tr1::shared_ptr<FakeRepository>, tr1::shared_ptr<Repository> >();
diff --git a/python/repository_TEST.py b/python/repository_TEST.py
index 7da8422..46fe2ba 100755
--- a/python/repository_TEST.py
+++ b/python/repository_TEST.py
@@ -24,6 +24,10 @@ repo_path = os.path.join(os.getcwd(), "repository_TEST_dir/testrepo")
os.environ["PALUDIS_HOME"] = os.path.join(os.getcwd(), "repository_TEST_dir/home")
from paludis import *
+
+# To check for QA easily
+import paludis
+
import unittest
Log.instance.log_level = LogLevel.WARNING
@@ -180,7 +184,6 @@ class TestCase_02_RepositoryInterfaces(unittest.TestCase):
self.assertEquals(li.license_exists("bad"), None)
def test_12_e_interface(self):
- ei = nce.main_repository
ei = nce.main_repository.e_interface
self.assert_(isinstance(ei, RepositoryEInterface))
@@ -201,6 +204,24 @@ class TestCase_02_RepositoryInterfaces(unittest.TestCase):
self.assertEquals(ei.profile_variable("ARCH"), "test")
+ def test_12_qa_interface(self):
+ if hasattr(paludis, "QAReporter"):
+ class PyQAR(QAReporter):
+ def __init__(self):
+ QAReporter.__init__(self)
+ self.messages = 0
+
+ def message(self, l, s, m):
+ self.messages += 1
+
+ qi = repo.qa_interface
+ self.assert_(isinstance(qi, RepositoryQAInterface))
+
+ qr = PyQAR()
+
+ qi.check_qa(qr, QACheckProperties(), QACheckProperties(), QAMessageLevel.DEBUG, "")
+ self.assertEquals(qr.messages, 1)
+
class TestCase_03_FakeRepository(unittest.TestCase):
def setUp(self):
global e, f
diff --git a/python/repository_TEST_setup.sh b/python/repository_TEST_setup.sh
index f78df77..638fd82 100755
--- a/python/repository_TEST_setup.sh
+++ b/python/repository_TEST_setup.sh
@@ -38,6 +38,8 @@ END
mkdir -p testrepo/{eclass,licenses,distfiles,profiles/testprofile,foo/bar/files} || exit 1
cd testrepo || exit 1
+echo "stray" > stray
+
echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
@@ -113,6 +115,8 @@ END
done
+touch foo/metadata.xml
+
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
DESCRIPTION="Test package"
HOMEPAGE="http://paludis.pioto.org/"