aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-07-27 20:58:29 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-07-27 20:58:29 +0000
commit1760d448e4c48b99f957dfa9d24b3f695d40d340 (patch)
treefb435e61a173713fb109011278a6819c1e0858d7
parenta86a9cdd0ca738353b0ebc9be17fc9f9d2e1ed2d (diff)
downloadpaludis-1760d448e4c48b99f957dfa9d24b3f695d40d340.tar.gz
paludis-1760d448e4c48b99f957dfa9d24b3f695d40d340.tar.xz
(python) Add actions.
-rw-r--r--python/Makefile.am2
-rw-r--r--python/action.cc237
-rwxr-xr-xpython/action_TEST.py122
-rw-r--r--python/dep_list.cc2
-rw-r--r--python/package_id.cc11
-rwxr-xr-xpython/package_id_TEST.py22
-rw-r--r--python/paludis_python_so.cc2
-rw-r--r--python/repository.cc34
8 files changed, 400 insertions, 32 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index df69b7b..4d78ef1 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -33,6 +33,7 @@ IF_PYTHON_TESTS = \
environment_TEST.py \
package_database_TEST.py \
repository_TEST.py \
+ action_TEST.py \
package_id_TEST.py \
metadata_key_TEST.py \
dep_list_TEST.py
@@ -40,6 +41,7 @@ IF_PYTHON_TESTS = \
IF_PYTHON_QA_TESTS =
IF_PYTHON_SOURCES = \
+ action.cc \
contents.cc \
dep_list.cc \
dep_spec.hh dep_spec.cc \
diff --git a/python/action.cc b/python/action.cc
new file mode 100644
index 0000000..7fd9287
--- /dev/null
+++ b/python/action.cc
@@ -0,0 +1,237 @@
+/* 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/action.hh>
+#include <paludis/util/tr1_memory.hh>
+#include <paludis/repository.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+template <typename A_>
+class class_supports_action_test :
+ public bp::class_<SupportsActionTest<A_>, bp::bases<SupportsActionTestBase> >
+{
+ public:
+ class_supports_action_test(const std::string & action) :
+ bp::class_<SupportsActionTest<A_>, bp::bases<SupportsActionTestBase> >(
+ ("Supports" + action + "ActionTest").c_str(),
+ "NEED_DOC",
+ bp::init<>("__init__()")
+ )
+ {
+ }
+};
+
+void PALUDIS_VISIBLE expose_action()
+{
+ /**
+ * Exceptions
+ */
+ ExceptionRegister::get_instance()->add_exception<ActionError>
+ ("ActionError", "BaseException",
+ "Parent class for action errors.");
+ ExceptionRegister::get_instance()->add_exception<UnsupportedActionError>
+ ("UnsupportedActionError", "ActionError",
+ "NEED_DOC");
+ ExceptionRegister::get_instance()->add_exception<InstallActionError>
+ ("InstallActionError", "ActionError",
+ "Thrown if an install fails.");
+ ExceptionRegister::get_instance()->add_exception<FetchActionError>
+ ("FetchActionError", "ActionError",
+ "Thrown if a fetch fails.");
+ ExceptionRegister::get_instance()->add_exception<UninstallActionError>
+ ("UninstallActionError", "ActionError",
+ "Thrown if an uninstall fails.");
+ ExceptionRegister::get_instance()->add_exception<ConfigActionError>
+ ("ConfigActionError", "ActionError",
+ "Thrown if a configure fails.");
+
+ /**
+ * Enums
+ */
+ enum_auto("InstallActionDebugOption", last_iado,
+ "Debug build mode for an InstallAction.");
+ enum_auto("InstallActionChecksOption", last_iaco,
+ "NEED_DOC");
+
+ /**
+ * InstallActionOptions
+ */
+ bp::class_<InstallActionOptions>
+ (
+ "InstallActionOptions",
+ "Options for InstallAction.",
+ bp::init<const bool &, const InstallActionDebugOption &, const InstallActionChecksOption &,
+ const tr1::shared_ptr<paludis::Repository> &>(
+ "__init__(no_config_protect_bool, InstallActionDebugOption, "
+ "InstallActionChecksOption, Repository)"
+ )
+ )
+ .def_readwrite("no_config_protect", &InstallActionOptions::no_config_protect,
+ "[rw] bool"
+ )
+
+ .def_readwrite("debug_build", &InstallActionOptions::debug_build,
+ "[rw] InstallActionDebugOption"
+ )
+
+ .def_readwrite("checks", &InstallActionOptions::checks,
+ "[rw] InstallActionChecksOption"
+ )
+
+ .add_property("destination",
+ bp::make_getter(&InstallActionOptions::destination,
+ bp::return_value_policy<bp::return_by_value>()),
+ bp::make_setter(&InstallActionOptions::destination),
+ "[rw] Repository"
+ )
+ ;
+
+ /**
+ * FetchActionOptions
+ */
+ bp::class_<FetchActionOptions>
+ (
+ "FetchActionOptions",
+ "Options for FetchAction.",
+ bp::init<const bool &, const bool &>("__init__(fetch_unneeded_bool, safe_resume_bool)")
+ )
+ .def_readwrite("fetch_unneeded", &FetchActionOptions::fetch_unneeded,
+ "[rw] bool"
+ )
+
+ .def_readwrite("safe_resume", &FetchActionOptions::safe_resume,
+ "[rw] bool"
+ )
+ ;
+
+ /**
+ * UninstallActionOptions
+ */
+ bp::class_<UninstallActionOptions>
+ (
+ "UninstallActionOptions",
+ "Options for UninstallAction.",
+ bp::init<const bool &>("__init__(no_config_protect_bool)")
+ )
+ .def_readwrite("no_config_protect", &UninstallActionOptions::no_config_protect,
+ "[rw] bool"
+ )
+ ;
+
+ /**
+ * Action
+ */
+ bp::class_<Action, boost::noncopyable>
+ (
+ "Action",
+ "NEED_DOC",
+ bp::no_init
+ );
+
+ /**
+ * InstallAction
+ */
+ bp::class_<InstallAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "InstallAction",
+ "NEED_DOC",
+ bp::init<const InstallActionOptions &>("__init__(InstallActionOptions)")
+ );
+
+ /**
+ * FetchAction
+ */
+ bp::class_<FetchAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "FetchAction",
+ "NEED_DOC",
+ bp::init<const FetchActionOptions &>("__init__(FetchActionOptions)")
+ );
+
+ /**
+ * UninstallAction
+ */
+ bp::class_<UninstallAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "UninstallAction",
+ "NEED_DOC",
+ bp::init<const UninstallActionOptions &>("__init__(UninstallActionOptions)")
+ );
+
+ /**
+ * InsatlledAction
+ */
+ bp::class_<InstalledAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "InstalledAction",
+ "NEED_DOC",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * PretendAction
+ */
+ bp::class_<PretendAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "PretendAction",
+ "NEED_DOC",
+ bp::init<>("__init__()")
+ )
+ .add_property("failed", &PretendAction::failed,
+ "[ro] bool\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * ConfigAction
+ */
+ bp::class_<ConfigAction, bp::bases<Action>, boost::noncopyable>
+ (
+ "ConfigAction",
+ "NEED_DOC",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * SupportActionTestBase
+ */
+ bp::class_<SupportsActionTestBase, boost::noncopyable>
+ (
+ "SupportsActionTestBase",
+ "NEED_DOC",
+ bp::no_init
+ );
+
+ /**
+ * SupportActionTests
+ */
+ class_supports_action_test<InstallAction>("Install");
+ class_supports_action_test<FetchAction>("Fetch");
+ class_supports_action_test<UninstallAction>("Uninstall");
+ class_supports_action_test<InstalledAction>("Installed");
+ class_supports_action_test<PretendAction>("Pretend");
+ class_supports_action_test<ConfigAction>("Config");
+
+}
diff --git a/python/action_TEST.py b/python/action_TEST.py
new file mode 100755
index 0000000..1ba33b9
--- /dev/null
+++ b/python/action_TEST.py
@@ -0,0 +1,122 @@
+#!/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
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_InstallActionOptions(unittest.TestCase):
+ def setUp(self):
+ global repo1, repo2
+ env = TestEnvironment()
+ repo1 = FakeRepository(env, "1")
+ repo2 = FakeRepository(env, "2")
+
+ def test_01_create(self):
+ InstallActionOptions(True, InstallActionDebugOption.values[0], InstallActionChecksOption.values[0], repo1)
+
+ def test_02_data_members(self):
+ iao = InstallActionOptions(True, InstallActionDebugOption.values[0],
+ InstallActionChecksOption.values[0], repo1)
+
+ self.assertEquals(iao.no_config_protect, True)
+ self.assertEquals(iao.debug_build, InstallActionDebugOption.values[0])
+ self.assertEquals(iao.checks, InstallActionChecksOption.values[0])
+ self.assertEquals(str(iao.destination.name), "1")
+
+ iao.no_config_protect = False
+ iao.debug_build = InstallActionDebugOption.values[1]
+ iao.checks = InstallActionChecksOption.values[1]
+ iao.destination = repo2
+
+ self.assertEquals(iao.no_config_protect, False)
+ self.assertEquals(iao.debug_build, InstallActionDebugOption.values[1])
+ self.assertEquals(iao.checks, InstallActionChecksOption.values[1])
+ self.assertEquals(str(iao.destination.name), "2")
+
+class TestCase_02_FetchActionOptions(unittest.TestCase):
+ def test_01_create(self):
+ FetchActionOptions(True, True)
+
+ def test_02_data_members(self):
+ fao = FetchActionOptions(True, True)
+
+ self.assertEquals(fao.fetch_unneeded, True)
+ self.assertEquals(fao.safe_resume, True)
+
+ fao.fetch_unneeded = False
+ fao.safe_resume = False
+
+ self.assertEquals(fao.fetch_unneeded, False)
+ self.assertEquals(fao.safe_resume, False)
+
+class TestCase_03_UninstallActionOptions(unittest.TestCase):
+ def test_01_create(self):
+ UninstallActionOptions(True)
+
+ def test_02_data_members(self):
+ uao = UninstallActionOptions(True)
+
+ self.assertEquals(uao.no_config_protect, True)
+ uao.no_config_protect = False
+ self.assertEquals(uao.no_config_protect, False)
+
+
+class TestCase_04_InstallAction(unittest.TestCase):
+ def test_01_create(self):
+ env = TestEnvironment()
+ repo1 = FakeRepository(env, "1")
+ iao = InstallActionOptions(True, InstallActionDebugOption.values[0],
+ InstallActionChecksOption.values[0], repo1)
+ InstallAction(iao)
+
+class TestCase_05_FetchAction(unittest.TestCase):
+ def test_01_create(self):
+ FetchAction(FetchActionOptions(True, True))
+
+class TestCase_06_UninstallAction(unittest.TestCase):
+ def test_01_create(self):
+ UninstallAction(UninstallActionOptions(True))
+
+class TestCase_07_InstalledAction(unittest.TestCase):
+ def test_01_create(self):
+ InstalledAction()
+
+class TestCase_08_PretendAction(unittest.TestCase):
+ def test_01_create(self):
+ PretendAction()
+
+class TestCase_09_ConfigAction(unittest.TestCase):
+ def test_01_create(self):
+ ConfigAction()
+
+class TestCase_10_SupportsActionTests(unittest.TestCase):
+ def test_01_create(self):
+ SupportsInstallActionTest()
+ SupportsFetchActionTest()
+ SupportsUninstallActionTest()
+ SupportsInstalledActionTest()
+ SupportsPretendActionTest()
+ SupportsConfigActionTest()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/dep_list.cc b/python/dep_list.cc
index b0038d8..a840051 100644
--- a/python/dep_list.cc
+++ b/python/dep_list.cc
@@ -223,7 +223,7 @@ void PALUDIS_VISIBLE expose_dep_list()
.add_property("destination", bp::make_getter(&DepListEntry::destination,
bp::return_value_policy<bp::return_by_value>()),
- "[ro] tr1::shared_ptr<Repository>"
+ "[ro] Repository"
)
.def_readonly("state", &DepListEntry::state,
diff --git a/python/package_id.cc b/python/package_id.cc
index d8cd924..f3c4e37 100644
--- a/python/package_id.cc
+++ b/python/package_id.cc
@@ -24,6 +24,7 @@
#include <paludis/metadata_key.hh>
#include <paludis/name.hh>
#include <paludis/version_spec.hh>
+#include <paludis/action.hh>
#include <paludis/util/sequence.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
@@ -81,6 +82,16 @@ void PALUDIS_VISIBLE expose_package_id()
"[ro] Repository\n"
)
+ .def("supports_action", &PackageID::supports_action,
+ "supports_action(SupportsActionTestBase) -> bool\n"
+ "NEED_DOC"
+ )
+
+ .def("perform_action", &PackageID::perform_action,
+ "perform_action(Action)\n"
+ "NEED_DOC"
+ )
+
.def("__iter__", bp::range(&PackageID::begin_metadata, &PackageID::end_metadata))
.def("find_metadata", &PackageIDWrapper::find_metadata,
diff --git a/python/package_id_TEST.py b/python/package_id_TEST.py
index 2df9cc1..6bc54b2 100755
--- a/python/package_id_TEST.py
+++ b/python/package_id_TEST.py
@@ -67,5 +67,27 @@ class TestCase_01_PackageID(unittest.TestCase):
def test_08_find_metadata(self):
self.assert_(isinstance(pid.find_metadata("DEPEND"), MetadataDependencySpecTreeKey))
+ def test_09_perform_action(self):
+ pid.perform_action(PretendAction())
+ self.assertRaises(UnsupportedActionError, pid.perform_action, ConfigAction())
+ self.assertRaises(UnsupportedActionError, ipid.perform_action, PretendAction())
+
+ def test_10_supports_action(self):
+ self.assert_(pid.supports_action(SupportsFetchActionTest()))
+ self.assert_(pid.supports_action(SupportsInstallActionTest()))
+ self.assert_(pid.supports_action(SupportsFetchActionTest()))
+ self.assert_(not pid.supports_action(SupportsUninstallActionTest()))
+ self.assert_(not pid.supports_action(SupportsInstalledActionTest()))
+ self.assert_(pid.supports_action(SupportsPretendActionTest()))
+ self.assert_(not pid.supports_action(SupportsConfigActionTest()))
+
+ self.assert_(not ipid.supports_action(SupportsFetchActionTest()))
+ self.assert_(not ipid.supports_action(SupportsInstallActionTest()))
+ self.assert_(not ipid.supports_action(SupportsFetchActionTest()))
+ self.assert_(ipid.supports_action(SupportsUninstallActionTest()))
+ self.assert_(ipid.supports_action(SupportsInstalledActionTest()))
+ self.assert_(not ipid.supports_action(SupportsPretendActionTest()))
+ self.assert_(ipid.supports_action(SupportsConfigActionTest()))
+
if __name__ == "__main__":
unittest.main()
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index ddb903c..d11df54 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -21,6 +21,7 @@
#include <boost/version.hpp>
+void expose_action();
void expose_contents();
void expose_dep_list();
void expose_dep_spec();
@@ -60,6 +61,7 @@ BOOST_PYTHON_MODULE(paludis)
expose_environment();
expose_metadata_key();
expose_package_id();
+ expose_action();
expose_package_database();
expose_repository();
}
diff --git a/python/repository.cc b/python/repository.cc
index 8cc8198..fea47a4 100644
--- a/python/repository.cc
+++ b/python/repository.cc
@@ -119,15 +119,8 @@ struct RepositoryWrapper :
}
};
-struct FakeRepositoryWrapper :
- FakeRepository,
- bp::wrapper<FakeRepository>
+struct FakeRepositoryWrapper
{
- FakeRepositoryWrapper(const Environment * const env, const RepositoryName & name) :
- FakeRepository(env, name)
- {
- }
-
static tr1::shared_ptr<PackageID>
add_version(FakeRepository & self, const QualifiedPackageName & qpn, const VersionSpec & vs)
{
@@ -187,25 +180,6 @@ struct RepositoryEInterfaceWrapper
void PALUDIS_VISIBLE expose_repository()
{
/**
- * Exceptions
- */
- ExceptionRegister::get_instance()->add_exception<ActionError>
- ("ActionError", "BaseException",
- "Parent class for install, uninstall errors.");
- ExceptionRegister::get_instance()->add_exception<InstallActionError>
- ("InstallActionError", "ActionError",
- "Thrown if an install fails.");
- ExceptionRegister::get_instance()->add_exception<FetchActionError>
- ("FetchActionError", "ActionError",
- "Thrown if a fetch fails.");
- ExceptionRegister::get_instance()->add_exception<UninstallActionError>
- ("UninstallActionError", "ActionError",
- "Thrown if an uninstall fails.");
- ExceptionRegister::get_instance()->add_exception<ConfigActionError>
- ("ConfigActionError", "ActionError",
- "Thrown if a configure fails.");
-
- /**
* DestinationIterable
*/
class_iterable<DestinationsSet>
@@ -554,11 +528,9 @@ void PALUDIS_VISIBLE expose_repository()
/**
* FakeRepository
*/
- tr1::shared_ptr<FakePackageID>
- (FakeRepository:: *add_version_ptr)(const QualifiedPackageName &, const VersionSpec &) =
- &FakeRepository::add_version;
+ bp::implicitly_convertible<tr1::shared_ptr<FakeRepository>, tr1::shared_ptr<Repository> >();
- bp::class_<FakeRepositoryWrapper, tr1::shared_ptr<FakeRepository>, bp::bases<Repository>, boost::noncopyable>
+ bp::class_<FakeRepository, tr1::shared_ptr<FakeRepository>, bp::bases<Repository>, boost::noncopyable>
(
"FakeRepository",
"Fake repository for use in test cases.",