aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-22 20:39:43 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-22 20:39:43 +0000
commit983779c9dd7ccea24932b97a70fd2ed08b9f9d8b (patch)
treea3cb891f5a923bf0e946cdb9f05a8a11a918768a
parent135ad6c0c365fc8f5af9c2402cd0d93a8b6e4c82 (diff)
downloadpaludis-983779c9dd7ccea24932b97a70fd2ed08b9f9d8b.tar.gz
paludis-983779c9dd7ccea24932b97a70fd2ed08b9f9d8b.tar.xz
(python) Add AdaptedEnvironment.
-rw-r--r--python/Makefile.am3
-rw-r--r--python/environment.cc28
-rwxr-xr-xpython/environment_TEST.py39
3 files changed, 63 insertions, 7 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 0697cce..358f215 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -83,6 +83,7 @@ TESTS_ENVIRONMENT = env \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/environments/.libs\`: \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/environments/paludis/.libs\`: \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/environments/no_config/.libs\`: \
+ \`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/environments/adapted/.libs\`: \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/dep_list/.libs\`: \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/tasks/.libs\`: \
\`$(top_srcdir)/paludis/repositories/gentoo/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/.libs\`: \
@@ -117,6 +118,7 @@ libpaludispython_la_LIBADD = \
$(top_builddir)/paludis/repositories/gentoo/libpaludisgentoorepository.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/libpaludisenvironments.la \
$(top_builddir)/paludis/qa/libpaludisqa.la
@@ -134,6 +136,7 @@ libpaludispython_la_LIBADD = \
$(top_builddir)/paludis/repositories/gentoo/libpaludisgentoorepository.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/libpaludisenvironments.la
TESTS = $(IF_PYTHON_TESTS)
diff --git a/python/environment.cc b/python/environment.cc
index 8185b7b..5101b61 100644
--- a/python/environment.cc
+++ b/python/environment.cc
@@ -21,6 +21,7 @@
#include <paludis/environment.hh>
#include <paludis/environments/environment_maker.hh>
+#include <paludis/environments/adapted/adapted_environment.hh>
#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
@@ -113,15 +114,30 @@ void PALUDIS_VISIBLE expose_environment()
"Return all known named sets."
);
+ bp::class_<AdaptedEnvironment, bp::bases<Environment>, boost::noncopyable>
+ ae("AdaptedEnvironment",
+ "An Environment that allows you to change aspects of an existing Environment,"
+ " e.g. the state of a USE flag for a package.",
+ bp::init<tr1::shared_ptr<Environment> >("__init__(Environment)")
+ );
+ ae.def("adapt_use", &AdaptedEnvironment::adapt_use,
+ "adapt_use(PackageDepSpeec, UseFlagName, UseFlagState)\n"
+ "Set the state of a USE flag for the given PackageDepSpec."
+ );
+ ae.def("clear_adaptions", &AdaptedEnvironment::clear_adaptions,
+ "clear_adaptions()\n"
+ "Clear all adaptions from this Environemnt."
+ );
+
bp::class_<PaludisEnvironment, bp::bases<Environment>, boost::noncopyable>
pe("PaludisEnvironment",
"The PaludisEnvironment is an Environment that corresponds to the normal operating evironment.",
bp::init<const std::string &>("__init__(string)")
);
- pe.add_property("config_dir", &PaludisEnvironment::config_dir,
- "[ro] string\n"
- "The config directory."
- );
+ pe.add_property("config_dir", &PaludisEnvironment::config_dir,
+ "[ro] string\n"
+ "The config directory."
+ );
bp::class_<NoConfigEnvironmentWrapper, bp::bases<Environment>, boost::noncopyable>
nce("NoConfigEnvironment",
@@ -133,8 +149,8 @@ void PALUDIS_VISIBLE expose_environment()
"master_repository_dir=\"/var/empty\")"
)
);
- tr1::shared_ptr<Repository> (NoConfigEnvironment::*main_repository)() =
- &NoConfigEnvironment::main_repository;
+ tr1::shared_ptr<Repository> (NoConfigEnvironment::*main_repository)()
+ = &NoConfigEnvironment::main_repository;
nce.add_property("main_repository", main_repository,
"[ro] Repository\n"
"Main repository."
diff --git a/python/environment_TEST.py b/python/environment_TEST.py
index 67470b1..2ab84ae 100755
--- a/python/environment_TEST.py
+++ b/python/environment_TEST.py
@@ -30,7 +30,7 @@ import unittest
Log.instance.log_level = LogLevel.WARNING
-class TestCase_Environments(unittest.TestCase):
+class TestCase_01_Environments(unittest.TestCase):
def get_envs(self):
self.e = EnvironmentMaker.instance.make_from_spec("")
self.nce = NoConfigEnvironment(repo)
@@ -119,5 +119,42 @@ class TestCase_Environments(unittest.TestCase):
self.assert_(isinstance(self.e.config_dir, str))
+class TestCase_02_AdaptedEnvironment(unittest.TestCase):
+ def test_01_create(self):
+ env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
+
+ def test_02_adapt_use(self):
+ env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
+ pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
+ pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+
+ self.assert_(env.query_use("enabled", pde))
+ self.assert_(not env.query_use("not_enabled", pde))
+ self.assert_(env.query_use("sometimes_enabled", pde))
+
+ env.adapt_use(pds, "enabled", UseFlagState.DISABLED)
+ self.assert_(not env.query_use("enabled", pde))
+
+ env.adapt_use(pds, "not_enabled", UseFlagState.ENABLED)
+ self.assert_(env.query_use("not_enabled", pde))
+
+ env.adapt_use(pds, "sometimes_enabled", UseFlagState.ENABLED)
+ self.assert_(env.query_use("sometimes_enabled", pde))
+
+ def test_03_clear_adaptions(self):
+ env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
+ pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
+ pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+
+ self.assert_(env.query_use("enabled", pde))
+
+ env.adapt_use(pds, "enabled", UseFlagState.DISABLED)
+ self.assert_(not env.query_use("enabled", pde))
+
+ env.clear_adaptions()
+ self.assert_(env.query_use("enabled", pde))
+
+
+
if __name__ == "__main__":
unittest.main()