aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-07-06 02:36:12 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-07-06 02:36:12 +0000
commitf5231e0a84d6f633c1a17dcfa4bb5252080e49d2 (patch)
tree88dfaea257c8ea88515dac285a0fb54399992f71
parente5f11c45d88ca843235be6a10cc97f580f674513 (diff)
downloadpaludis-f5231e0a84d6f633c1a17dcfa4bb5252080e49d2.tar.gz
paludis-f5231e0a84d6f633c1a17dcfa4bb5252080e49d2.tar.xz
(python) Bring lots of stuff up to date.
-rw-r--r--python/Makefile.am19
-rw-r--r--python/dep_spec.cc33
-rw-r--r--python/dep_tag.cc14
-rwxr-xr-xpython/dep_tag_TEST.py12
-rw-r--r--python/environment.cc7
-rwxr-xr-xpython/environment_TEST.py112
-rwxr-xr-xpython/log_TEST.py2
-rw-r--r--python/metadata_key.cc252
-rwxr-xr-xpython/metadata_key_TEST.py72
-rwxr-xr-xpython/metadata_key_TEST_cleanup.sh8
-rwxr-xr-xpython/metadata_key_TEST_setup.sh49
-rw-r--r--python/name.cc84
-rwxr-xr-xpython/name_TEST.py10
-rw-r--r--python/package_database.cc45
-rwxr-xr-xpython/package_database_TEST.py7
-rw-r--r--python/package_id.cc107
-rwxr-xr-xpython/package_id_TEST.py75
-rwxr-xr-xpython/package_id_TEST_cleanup.sh8
-rwxr-xr-xpython/package_id_TEST_setup.sh (renamed from python/version_metadata_TEST_setup.sh)20
-rw-r--r--[-rwxr-xr-x]python/paludis_python.hh33
-rw-r--r--python/paludis_python_so.cc6
-rw-r--r--python/repository.cc218
-rwxr-xr-xpython/repository_TEST.py401
-rwxr-xr-xpython/repository_TEST_setup.sh21
-rw-r--r--python/version_metadata.cc292
-rwxr-xr-xpython/version_metadata_TEST.py117
-rwxr-xr-xpython/version_metadata_TEST_cleanup.sh8
-rw-r--r--python/version_requirements.cc6
-rw-r--r--python/version_spec.cc10
29 files changed, 1090 insertions, 958 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 6882e24..44f67d4 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -37,7 +37,8 @@ IF_PYTHON_TESTS = \
environment_TEST.py \
package_database_TEST.py \
repository_TEST.py \
- version_metadata_TEST.py
+ package_id_TEST.py \
+ metadata_key_TEST.py
IF_PYTHON_QA_TESTS =
@@ -50,13 +51,14 @@ IF_PYTHON_SOURCES = \
exception.hh exception.cc \
fs_entry.cc \
mask_reasons.cc \
+ metadata_key.cc \
name.cc \
log.cc \
package_database.cc \
+ package_id.cc \
portage_dep_parser.cc \
query.cc \
repository.cc \
- version_metadata.cc \
version_operator.cc \
version_requirements.cc \
version_spec.cc
@@ -68,9 +70,10 @@ EXTRA_DIST = $(IF_PYTHON_TESTS) $(IF_PYTHON_SOURCES) \
paludis_python.hh \
paludis_python_so.cc \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
+ metadata_key_TEST_setup.sh metadata_key_TEST_cleanup.sh \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
- repository_TEST_setup.sh repository_TEST_cleanup.sh \
- version_metadata_TEST_setup.sh version_metadata_TEST_cleanup.sh
+ package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
+ repository_TEST_setup.sh repository_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
PALUDIS_NO_GLOBAL_HOOKS="yes" \
@@ -92,7 +95,7 @@ TESTS_ENVIRONMENT = env \
\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/tasks/.libs\`: \
\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/.libs\`: \
\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/e/.libs\`: \
- \`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/qa/.libs\`: \
+ \`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/fake/.libs\`: \
\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/python/.libs\`" \
| tr -d ' '` \
PYTHONPATH="./.libs" \
@@ -120,11 +123,12 @@ libpaludispython_la_LIBADD = \
$(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/libpaludisenvironments.la \
- $(top_builddir)/paludis/qa/libpaludisqa.la
+ $(top_builddir)/paludis/environments/libpaludisenvironments.la
+# $(top_builddir)/paludis/qa/libpaludisqa.la
TESTS = $(IF_PYTHON_QA_TESTS) $(IF_PYTHON_TESTS)
@@ -138,6 +142,7 @@ libpaludispython_la_LIBADD = \
$(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 \
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index c4e2f3d..4ebfe2b 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -240,7 +240,7 @@ PythonPackageDepSpec::PythonPackageDepSpec(const PackageDepSpec & p) :
deep_copy(p.package_ptr()),
deep_copy(p.category_name_part_ptr()),
deep_copy(p.package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
p.version_requirements_mode(),
deep_copy(p.slot_ptr()),
deep_copy(p.repository_ptr()),
@@ -251,7 +251,7 @@ PythonPackageDepSpec::PythonPackageDepSpec(const PackageDepSpec & p) :
if (p.version_requirements_ptr())
{
std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
- _imp->version_requirements->inserter());
+ _imp->version_requirements->back_inserter());
}
}
@@ -261,7 +261,7 @@ PythonPackageDepSpec::PythonPackageDepSpec(const PythonPackageDepSpec & p) :
deep_copy(p.package_ptr()),
deep_copy(p.category_name_part_ptr()),
deep_copy(p.package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
p.version_requirements_mode(),
deep_copy(p.slot_ptr()),
deep_copy(p.repository_ptr()),
@@ -270,7 +270,7 @@ PythonPackageDepSpec::PythonPackageDepSpec(const PythonPackageDepSpec & p) :
p.py_str()))
{
std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
- _imp->version_requirements->inserter());
+ _imp->version_requirements->back_inserter());
}
PythonPackageDepSpec::~PythonPackageDepSpec()
@@ -296,7 +296,7 @@ PythonPackageDepSpec::without_use_requirements() const
deep_copy(package_ptr()),
deep_copy(category_name_part_ptr()),
deep_copy(package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
version_requirements_mode(),
deep_copy(slot_ptr()),
deep_copy(repository_ptr()),
@@ -307,7 +307,7 @@ PythonPackageDepSpec::without_use_requirements() const
if (version_requirements_ptr())
{
std::copy(version_requirements_ptr()->begin(), version_requirements_ptr()->end(),
- p.version_requirements_ptr()->inserter());
+ p.version_requirements_ptr()->back_inserter());
}
return tr1::shared_ptr<PythonPackageDepSpec>(new PythonPackageDepSpec(*p.without_use_requirements()));
@@ -522,7 +522,7 @@ package_dep_spec_from_python(const PythonPackageDepSpec & p)
deep_copy(p.package_ptr()),
deep_copy(p.category_name_part_ptr()),
deep_copy(p.package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
p.version_requirements_mode(),
deep_copy(p.slot_ptr()),
deep_copy(p.repository_ptr()),
@@ -532,7 +532,7 @@ package_dep_spec_from_python(const PythonPackageDepSpec & p)
if (p.version_requirements_ptr())
{
std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
- result->version_requirements_ptr()->inserter());
+ result->version_requirements_ptr()->back_inserter());
}
return result;
}
@@ -583,6 +583,14 @@ struct AllowedTypes<DependencySpecTree>
AllowedTypes(const BlockDepSpec &) {};
};
+template<>
+struct AllowedTypes<SetSpecTree>
+{
+ AllowedTypes(const AllDepSpec &) {};
+ AllowedTypes(const PackageDepSpec &) {};
+};
+
+
template <typename>
struct NiceClassNames;
@@ -998,7 +1006,7 @@ struct RegisterPackageDepSpecFromPython
deep_copy(p.package_ptr()),
deep_copy(p.category_name_part_ptr()),
deep_copy(p.package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
p.version_requirements_mode(),
deep_copy(p.slot_ptr()),
deep_copy(p.repository_ptr()),
@@ -1009,7 +1017,7 @@ struct RegisterPackageDepSpecFromPython
if (p.version_requirements_ptr())
{
std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
- reinterpret_cast<PackageDepSpec *>(storage)->version_requirements_ptr()->inserter());
+ reinterpret_cast<PackageDepSpec *>(storage)->version_requirements_ptr()->back_inserter());
}
data->convertible = storage;
}
@@ -1044,7 +1052,7 @@ struct RegisterPackageDepSpecSPFromPython
deep_copy(p.package_ptr()),
deep_copy(p.category_name_part_ptr()),
deep_copy(p.package_name_part_ptr()),
- tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements),
p.version_requirements_mode(),
deep_copy(p.slot_ptr()),
deep_copy(p.repository_ptr()),
@@ -1054,7 +1062,7 @@ struct RegisterPackageDepSpecSPFromPython
if (p.version_requirements_ptr())
{
std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
- (*reinterpret_cast<tr1::shared_ptr<PackageDepSpec> *>(storage))->version_requirements_ptr()->inserter());
+ (*reinterpret_cast<tr1::shared_ptr<PackageDepSpec> *>(storage))->version_requirements_ptr()->back_inserter());
}
data->convertible = storage;
}
@@ -1084,6 +1092,7 @@ void PALUDIS_VISIBLE expose_dep_spec()
register_tree_to_python<RestrictSpecTree>();
register_tree_to_python<URISpecTree>();
register_tree_to_python<LicenseSpecTree>();
+ register_tree_to_python<SetSpecTree>();
RegisterSpecTreeFromPython<DependencySpecTree>();
RegisterSpecTreeFromPython<ProvideSpecTree>();
diff --git a/python/dep_tag.cc b/python/dep_tag.cc
index bce851f..8dcd171 100644
--- a/python/dep_tag.cc
+++ b/python/dep_tag.cc
@@ -39,7 +39,7 @@ struct DepTagCategoryMakerWrapper
void PALUDIS_VISIBLE expose_dep_tag()
{
/**
- * Exceptions.
+ * Exceptions
*/
ExceptionRegister::get_instance()->add_exception<NoSuchDepTagCategory>
("NoSuchDepTagCategory", "BaseException",
@@ -162,14 +162,14 @@ void PALUDIS_VISIBLE expose_dep_tag()
(
"DependencyDepTag",
"DepTag subclass for dependencies.",
- bp::init<const PackageDatabaseEntry &, const PackageDepSpec &,
- tr1::shared_ptr<DependencySpecTree::ConstItem> >(
- "__init__(PackageDatabaseEntry, PackageDepSpec, CompositeDepSpec)"
+ bp::init<const tr1::shared_ptr<const PackageID> &, const PackageDepSpec &,
+ const tr1::shared_ptr<const DependencySpecTree::ConstItem> >(
+ "__init__(PackageID, PackageDepSpec, CompositeDepSpec)"
)
)
- .add_property("package", &DependencyDepTag::package,
- "[ro] PackageDatabaseEntry\n"
- "The PackageDatabaseEntry that contains our dependency."
+ .add_property("package_id", &DependencyDepTag::package_id,
+ "[ro] PackageID\n"
+ "The PackageID that contains our dependency."
)
.add_property("dependency", bp::make_function(&DependencyDepTag::dependency,
diff --git a/python/dep_tag_TEST.py b/python/dep_tag_TEST.py
index c87c730..19c7186 100755
--- a/python/dep_tag_TEST.py
+++ b/python/dep_tag_TEST.py
@@ -53,19 +53,21 @@ class TestCase_03_GeneralSetDepTag(unittest.TestCase):
class TestCase_04_DependencyDepTag(unittest.TestCase):
def setUp(self):
- global dt, pde, pds, cds
- pde = PackageDatabaseEntry("cat/foo", "1.0", "repo")
+ global dt, pid, pds, cds
+ env = EnvironmentMaker.instance.make_from_spec("")
+ repo = FakeRepository(env, "repo")
+ pid = repo.add_version("cat/foo", "1.0")
pds = PackageDepSpec("=cat/boo-1", PackageDepSpecParseMode.PERMISSIVE)
cds = PortageDepParser.parse_depend("", EAPIData.instance.eapi_from_string("0"))
- dt = DependencyDepTag(pde, pds, cds);
+ dt = DependencyDepTag(pid, 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(dt.short_text, "cat/foo-1.0:0::repo")
+ self.assertEquals(dt.package_id, pid)
self.assertEquals(str(dt.dependency), str(pds))
self.assert_(isinstance(dt.conditions, AllDepSpec))
diff --git a/python/environment.cc b/python/environment.cc
index 904d092..cff065f 100644
--- a/python/environment.cc
+++ b/python/environment.cc
@@ -25,6 +25,7 @@
#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
+#include <paludis/package_id.hh>
using namespace paludis;
using namespace paludis::python;
@@ -127,13 +128,13 @@ void PALUDIS_VISIBLE expose_environment()
)
.def("query_use", &Environment::query_use,
- "query_use(UseFlagName, PackageDatabaseEntry) -> bool\n"
+ "query_use(UseFlagName, PackageID) -> bool\n"
"Is a particular use flag enabled for a particular package?"
)
.def("mask_reasons", &Environment::mask_reasons,
- (bp::arg("PackageDatabaseEntry"), bp::arg("MaskReasonOptions")=MaskReasonsOptions()),
- "mask_reasons(PackageDatabaseEntry, MaskReasonsOptions=MaskReasonsOptions())"
+ (bp::arg("PackageID"), bp::arg("MaskReasonOptions")=MaskReasonsOptions()),
+ "mask_reasons(PackageID, MaskReasonsOptions=MaskReasonsOptions())"
" -> set of MaskReason\n"
"Return the reasons for a package being masked."
)
diff --git a/python/environment_TEST.py b/python/environment_TEST.py
index c639276..1870240 100755
--- a/python/environment_TEST.py
+++ b/python/environment_TEST.py
@@ -31,9 +31,10 @@ import unittest
Log.instance.log_level = LogLevel.WARNING
class TestCase_01_Environments(unittest.TestCase):
- def get_envs(self):
- self.e = EnvironmentMaker.instance.make_from_spec("")
- self.nce = NoConfigEnvironment(repo)
+ def setUp(self):
+ global e, nce
+ e = EnvironmentMaker.instance.make_from_spec("")
+ nce = NoConfigEnvironment(repo)
def test_01_create(self):
NoConfigEnvironment(repo)
@@ -50,74 +51,56 @@ class TestCase_01_Environments(unittest.TestCase):
self.assert_(isinstance(NoConfigEnvironment(repo), Environment))
def test_04_query_use(self):
- self.get_envs()
+ pid = iter(e.package_database.query(Query.Matches(
+ PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ QueryOrder.REQUIRE_EXACTLY_ONE)).next()
- pde = PackageDatabaseEntry("x/x", "1.0", "testrepo")
+ self.assert_(e.query_use("enabled", pid))
+ self.assert_(not e.query_use("not_enabled", pid))
+ self.assert_(e.query_use("sometimes_enabled", pid))
- self.assert_(self.e.query_use("enabled", pde))
- self.assert_(not self.e.query_use("not_enabled", pde))
- self.assert_(not self.e.query_use("sometimes_enabled", pde))
-
- pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
-
- self.assert_(self.e.query_use("enabled", pde))
- self.assert_(not self.e.query_use("not_enabled", pde))
- self.assert_(self.e.query_use("sometimes_enabled", pde))
-
- self.assert_(not self.nce.query_use("foo", pde))
+ self.assert_(not nce.query_use("foo", pid))
def test_05_mask_reasons(self):
- self.get_envs()
- pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
+ pid = iter(nce.package_database.query(Query.Matches(
+ PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ QueryOrder.REQUIRE_EXACTLY_ONE)).next()
- self.nce.mask_reasons(pde)
+ nce.mask_reasons(pid)
def test_06_package_database(self):
- self.get_envs()
+ self.assert_(isinstance(e.package_database, PackageDatabase))
+ self.assert_(isinstance(nce.package_database, PackageDatabase))
- self.assert_(isinstance(self.e.package_database, PackageDatabase))
- self.assert_(isinstance(self.nce.package_database, PackageDatabase))
+ def test_07_sets(self):
+ self.assert_(isinstance(e.set("everything"), AllDepSpec))
+ self.assert_(isinstance(nce.set("everything"), AllDepSpec))
-# def test_07_sets(self):
-# self.get_envs()
-#
-# self.assert_(isinstance(self.e.set("everything"), AllDepSpec))
-# self.assert_(isinstance(self.nce.set("everything"), AllDepSpec))
-#
-# self.assert_(isinstance(self.e.set_names(), SetNameCollection))
-# self.assert_(isinstance(self.nce.set_names(), SetNameCollection))
+ self.assert_(isinstance(e.set_names(), SetNameIterable))
+ self.assert_(isinstance(nce.set_names(), SetNameIterable))
def test_08_repositories(self):
- self.get_envs()
- self.nce2 = NoConfigEnvironment(repo, master_repository_dir=slaverepo)
+ nce2 = NoConfigEnvironment(repo, master_repository_dir=slaverepo)
- self.assert_(isinstance(self.nce.main_repository, Repository))
- self.assertEquals(self.nce.master_repository, None)
- self.assert_(isinstance(self.nce2.main_repository, Repository))
- self.assert_(isinstance(self.nce2.master_repository, Repository))
+ self.assert_(isinstance(nce.main_repository, Repository))
+ self.assertEquals(nce.master_repository, None)
+ self.assert_(isinstance(nce2.main_repository, Repository))
+ self.assert_(isinstance(nce2.master_repository, Repository))
def test_09_root(self):
- self.get_envs()
-
- self.assert_(isinstance(self.e.root(), str))
- self.assert_(isinstance(self.nce.root(), str))
+ self.assert_(isinstance(e.root(), str))
+ self.assert_(isinstance(nce.root(), str))
def test_10_default_destinations(self):
- self.get_envs()
-
- self.assert_(isinstance(self.e.default_destinations(), DestinationsCollection))
- self.assert_(isinstance(self.nce.default_destinations(), DestinationsCollection))
+ self.assert_(isinstance(e.default_destinations(), DestinationsIterable))
+ self.assert_(isinstance(nce.default_destinations(), DestinationsIterable))
def test_11_set_accept_unstable(self):
- self.get_envs()
-
- self.nce.accept_unstable = True
- self.assertRaises(AttributeError, lambda: self.nce.accept_unstable)
+ nce.accept_unstable = True
+ self.assertRaises(AttributeError, lambda: nce.accept_unstable)
def test_12_config_dir(self):
- self.get_envs()
-
- self.assert_(isinstance(self.e.config_dir, str))
+ self.assert_(isinstance(e.config_dir, str))
class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_01_create(self):
@@ -125,35 +108,38 @@ class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_02_adapt_use(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
- pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
+ pid = iter(env.package_database.query(Query.Matches(
+ PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ QueryOrder.REQUIRE_EXACTLY_ONE)).next()
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))
+ self.assert_(env.query_use("enabled", pid))
+ self.assert_(not env.query_use("not_enabled", pid))
+ self.assert_(env.query_use("sometimes_enabled", pid))
env.adapt_use(pds, "enabled", UseFlagState.DISABLED)
- self.assert_(not env.query_use("enabled", pde))
+ self.assert_(not env.query_use("enabled", pid))
env.adapt_use(pds, "not_enabled", UseFlagState.ENABLED)
- self.assert_(env.query_use("not_enabled", pde))
+ self.assert_(env.query_use("not_enabled", pid))
env.adapt_use(pds, "sometimes_enabled", UseFlagState.ENABLED)
- self.assert_(env.query_use("sometimes_enabled", pde))
+ self.assert_(env.query_use("sometimes_enabled", pid))
def test_03_clear_adaptions(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
- pde = PackageDatabaseEntry("foo/bar", "1.0", "testrepo")
+ pid = iter(env.package_database.query(Query.Matches(
+ PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ QueryOrder.REQUIRE_EXACTLY_ONE)).next()
pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
- self.assert_(env.query_use("enabled", pde))
+ self.assert_(env.query_use("enabled", pid))
env.adapt_use(pds, "enabled", UseFlagState.DISABLED)
- self.assert_(not env.query_use("enabled", pde))
+ self.assert_(not env.query_use("enabled", pid))
env.clear_adaptions()
- self.assert_(env.query_use("enabled", pde))
-
+ self.assert_(env.query_use("enabled", pid))
if __name__ == "__main__":
diff --git a/python/log_TEST.py b/python/log_TEST.py
index 67c2ab5..2311b01 100755
--- a/python/log_TEST.py
+++ b/python/log_TEST.py
@@ -31,7 +31,7 @@ class TestCase_Log(unittest.TestCase):
def test_03_log_level(self):
ll = Log.instance.log_level
- self.assertEquals(ll, LogLevel.DEBUG)
+ self.assertEquals(ll, LogLevel.QA)
self.assert_(ll >= LogLevel.DEBUG)
self.assert_(ll <= LogLevel.SILENT)
diff --git a/python/metadata_key.cc b/python/metadata_key.cc
new file mode 100644
index 0000000..bd9e5fb
--- /dev/null
+++ b/python/metadata_key.cc
@@ -0,0 +1,252 @@
+/* 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/metadata_key.hh>
+#include <paludis/name.hh>
+#include <paludis/util/visitor-impl.hh>
+
+#include <datetime.h>
+
+#include <iostream>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct MetadataTimeKeyWrapper
+{
+ static PyObject *
+ value(const MetadataTimeKey & self)
+ {
+ PyDateTime_IMPORT;
+ return PyDateTime_FromTimestamp(bp::make_tuple(self.value()).ptr());
+ }
+
+};
+
+template <typename K_>
+struct class_set_key :
+ bp::class_<K_, bp::bases<MetadataKey>, boost::noncopyable>
+{
+ class_set_key(const std::string & set) :
+ bp::class_<K_, bp::bases<MetadataKey>, boost::noncopyable>(("Metadata" + set + "Key").c_str(), bp::no_init)
+ {
+ add_property("value", &K_::value,
+ ("[ro] " + set + "\n").c_str());
+ }
+};
+
+template <typename K_>
+struct class_spec_tree_key :
+ bp::class_<K_, bp::bases<MetadataKey>, boost::noncopyable>
+{
+ class_spec_tree_key(const std::string & spec_tree) :
+ bp::class_<K_, bp::bases<MetadataKey>, boost::noncopyable>(("Metadata" + spec_tree + "Key").c_str(), bp::no_init)
+ {
+ add_property("value", &K_::value,
+ ("[ro] " + spec_tree + "\n").c_str());
+ }
+};
+
+struct MetadataKeyToPython :
+ ConstVisitor<MetadataKeyVisitorTypes>
+{
+ bp::object value;
+
+ void visit(const MetadataPackageIDKey & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataStringKey & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataTimeKey & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataContentsKey & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSetKey<KeywordNameSet> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSetKey<UseFlagNameSet> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSetKey<IUseFlagSet> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSetKey<InheritedSet> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSpecTreeKey<RestrictSpecTree> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+
+ void visit(const MetadataSpecTreeKey<URISpecTree> & k)
+ {
+ value = bp::object(bp::ptr(&k));
+ }
+};
+
+struct metadata_key_to_python
+{
+ static PyObject *
+ convert(const MetadataKey & k)
+ {
+ MetadataKeyToPython v;
+ k.accept(v);
+ return bp::incref(v.value.ptr());
+ }
+};
+
+void register_metadata_key_to_python()
+{
+ bp::to_python_converter<MetadataKey, metadata_key_to_python>();
+}
+
+
+void PALUDIS_VISIBLE expose_metadata_key()
+{
+ /**
+ * Enums
+ */
+ enum_auto("MetadataKeyType", last_mkt,
+ "The significance of a MetadataKey to a user.");
+
+ /**
+ * MetadataKey
+ */
+ register_shared_ptrs_to_python<MetadataKey>();
+ bp::class_<MetadataKey, boost::noncopyable>
+ (
+ "MetadataKey",
+ bp::no_init
+ )
+ .add_property("raw_name", &MetadataKey::raw_name,
+ "[ro] string\n"
+ )
+
+ .add_property("human_name", &MetadataKey::human_name,
+ "[ro] MetadataKeyType\n"
+ )
+ ;
+ register_metadata_key_to_python();
+
+ /**
+ * MetadataPackageIDKey
+ */
+ bp::class_<MetadataPackageIDKey, bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataPackageIDKey",
+ bp::no_init
+ )
+ .add_property("value", &MetadataPackageIDKey::value,
+ "[ro] PackageID\n"
+ )
+ ;
+
+ /**
+ * MetadataStringKey
+ */
+ bp::class_<MetadataStringKey, bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataStringKey",
+ bp::no_init
+ )
+ .add_property("value", &MetadataStringKey::value,
+ "[ro] string\n"
+ )
+ ;
+
+ /**
+ * MetadataTimeKey
+ */
+ bp::class_<MetadataTimeKey, bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataTimeKey",
+ bp::no_init
+ )
+ .add_property("value", &MetadataTimeKeyWrapper::value,
+ "[ro] datetime\n"
+ )
+ ;
+
+ /**
+ * MetadataContentsKey
+ */
+ bp::class_<MetadataContentsKey, bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataContentsKey",
+ bp::no_init
+ )
+ .add_property("value", &MetadataContentsKey::value,
+ "[ro] Contents\n"
+ )
+ ;
+
+ /**
+ * MetadataSetKeys
+ */
+ class_set_key<MetadataSetKey<KeywordNameSet> >("KeywordNameIterable");
+ class_set_key<MetadataSetKey<UseFlagNameSet> >("UseFlagNameIterable");
+ class_set_key<MetadataSetKey<IUseFlagSet> >("IUseFlagIterable");
+ class_set_key<MetadataSetKey<InheritedSet> >("InheritedIterable");
+
+ /**
+ * MetadataSpecTreeKeys
+ */
+ class_spec_tree_key<MetadataSpecTreeKey<LicenseSpecTree> >("LicenseSpecTree");
+ class_spec_tree_key<MetadataSpecTreeKey<ProvideSpecTree> >("ProvideSpecTree");
+ class_spec_tree_key<MetadataSpecTreeKey<DependencySpecTree> >("DependencySpecTree");
+ class_spec_tree_key<MetadataSpecTreeKey<RestrictSpecTree> >("RestrictSpecTree");
+ class_spec_tree_key<MetadataSpecTreeKey<URISpecTree> >("URISpecTree");
+}
diff --git a/python/metadata_key_TEST.py b/python/metadata_key_TEST.py
new file mode 100755
index 0000000..09ceefd
--- /dev/null
+++ b/python/metadata_key_TEST.py
@@ -0,0 +1,72 @@
+#!/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
+#
+
+import os
+
+repo_path = os.path.join(os.getcwd(), "metadata_key_TEST_dir/testrepo")
+irepo_path = os.path.join(os.getcwd(), "metadata_key_TEST_dir/installed")
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_MetadataKeys(unittest.TestCase):
+ def setUp(self):
+ global e, ie, pid, ipid
+ e = NoConfigEnvironment(repo_path, "/var/empty")
+ ie = NoConfigEnvironment(irepo_path)
+ pid = iter(e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ ipid = iter(ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()
+
+ def test_01_contents(self):
+ self.assertEquals(pid.find("CONTENTS"), None)
+ self.assert_(isinstance(ipid.find("CONTENTS"), MetadataContentsKey))
+
+ def test_02_installed_time(self):
+ self.assertEquals(pid.find("INSTALLED_TIME"), None)
+ self.assert_(isinstance(ipid.find("INSTALLED_TIME"), MetadataTimeKey))
+
+ def test_03_repository(self):
+ self.assertEquals(pid.find("REPOSITORY"), None)
+ self.assert_(isinstance(ipid.find("REPOSITORY"), MetadataStringKey))
+
+ def test_04_keywords(self):
+ self.assert_(isinstance(pid.find("KEYWORDS"), MetadataKeywordNameIterableKey))
+ self.assertEquals(ipid.find("KEYWORDS"), None)
+
+ def test_05_use(self):
+ self.assertEquals(pid.find("USE"), None)
+ self.assert_(isinstance(ipid.find("USE"), MetadataUseFlagNameIterableKey))
+
+ def test_06_iuse(self):
+ self.assert_(isinstance(pid.find("IUSE"), MetadataIUseFlagIterableKey))
+ self.assert_(isinstance(ipid.find("IUSE"), MetadataIUseFlagIterableKey))
+
+ def test_07_inherited(self):
+ self.assert_(isinstance(pid.find("INHERITED"), MetadataInheritedIterableKey))
+ self.assert_(isinstance(ipid.find("INHERITED"), MetadataInheritedIterableKey))
+
+ def test_08_depend(self):
+ self.assert_(isinstance(pid.find("DEPEND"), MetadataDependencySpecTreeKey))
+ self.assertEquals(ipid.find("DEPEND"), None)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/metadata_key_TEST_cleanup.sh b/python/metadata_key_TEST_cleanup.sh
new file mode 100755
index 0000000..a176b6b
--- /dev/null
+++ b/python/metadata_key_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d metadata_key_TEST_dir ] ; then
+ rm -fr metadata_key_TEST_dir
+else
+ true
+fi
diff --git a/python/metadata_key_TEST_setup.sh b/python/metadata_key_TEST_setup.sh
new file mode 100755
index 0000000..e5fafad
--- /dev/null
+++ b/python/metadata_key_TEST_setup.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir metadata_key_TEST_dir || exit 1
+cd metadata_key_TEST_dir || exit 1
+
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+cd testrepo || exit 1
+echo "testrepo" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+foo
+END
+cat <<END > profiles/profiles.desc
+test testprofile stable
+END
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+
+cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE="testflag"
+LICENSE="GPL-2"
+KEYWORDS="test"
+RESTRICT="monkey"
+DEPEND="foo/bar"
+RDEPEND=""
+END
+
+cd ..
+
+mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
+
+
+echo "cat-one" > installed/cat-one/pkg-one-1/CATEGORY
+touch installed/cat-one/pkg-one-1/CONTENTS
+echo "0" > installed/cat-one/pkg-one-1/EAPI
+echo "a description" > installed/cat-one/pkg-one-1/DESCRIPTION
+echo "test_inherited" > installed/cat-one/pkg-one-1/INHERITED
+echo "test_iuse test" > installed/cat-one/pkg-one-1/IUSE
+echo "test" > installed/cat-one/pkg-one-1/KEYWORDS
+echo "origin_test" > installed/cat-one/pkg-one-1/REPOSITORY
+echo "test_slot" > installed/cat-one/pkg-one-1/SLOT
+echo "test test_use" > installed/cat-one/pkg-one-1/USE
diff --git a/python/name.cc b/python/name.cc
index 1f6c0a2..d341a3d 100644
--- a/python/name.cc
+++ b/python/name.cc
@@ -18,8 +18,11 @@
*/
#include <paludis_python.hh>
-#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
#include <paludis/name.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
using namespace paludis::python;
@@ -78,13 +81,12 @@ void PALUDIS_VISIBLE expose_name()
);
/**
- * PackageNamePartCollection
+ * PackageNamePartIterable
*/
- class_collection<PackageNamePartCollection>
+ class_iterable<PackageNamePartSet>
(
- "PackageNamePartCollection",
- "Iterable of PackageNamePart.\n"
- "A collection of PackageNamePart instances."
+ "PackageNamePartIterable",
+ "Iterable of PackageNamePart"
);
/**
@@ -101,13 +103,12 @@ void PALUDIS_VISIBLE expose_name()
;
/**
- * CategoryNamePartCollection
+ * CategoryNamePartIterable
*/
- class_collection<CategoryNamePartCollection>
+ class_iterable<CategoryNamePartSet>
(
- "CategoryNamePartCollection",
- "Iterable of CategoryNamePart.\n"
- "A collection of CategoryNamePart instances."
+ "CategoryNamePartIterable",
+ "Iterable of CategoryNamePart"
);
/**
@@ -120,13 +121,12 @@ void PALUDIS_VISIBLE expose_name()
);
/**
- * UseFlagNameCollection
+ * UseFlagNameIterable
*/
- class_collection<UseFlagNameCollection>
+ class_iterable<UseFlagNameSet>
(
- "UseFlagNameCollection",
- "Iterable of UseFlagName.\n"
- "A collection of UseFlagName instances."
+ "UseFlagNameIterable",
+ "Iterable of UseFlagName"
);
/**
@@ -150,13 +150,12 @@ void PALUDIS_VISIBLE expose_name()
);
/**
- * RepositoryNameCollection
+ * RepositoryNameIterable
*/
- class_collection<RepositoryNameCollection>
+ class_iterable<RepositoryNameSequence>
(
- "RepositoryNameCollection",
- "Iterable of RepositoryName\n"
- "A collection of RepositoryName instances."
+ "RepositoryNameIterable",
+ "Iterable of RepositoryName"
);
/**
@@ -171,11 +170,10 @@ void PALUDIS_VISIBLE expose_name()
/**
* KeywordNameCollect
*/
- class_collection<KeywordNameCollection>
+ class_iterable<KeywordNameSet>
(
- "KeywordNameCollection",
- "Iterable of KeywordName\n"
- "A collection of KeywordName instances."
+ "KeywordNameIterable",
+ "Iterable of KeywordName"
);
/**
@@ -188,23 +186,21 @@ void PALUDIS_VISIBLE expose_name()
);
/**
- * SetNameCollection
+ * SetNameIterable
*/
- class_collection<SetNameCollection>
+ class_iterable<SetNameSet>
(
- "SetNameCollection",
- "Iterable of SetName\n"
- "A collection of set names."
+ "SetNameIterable",
+ "Iterable of SetName"
);
/**
- * InheritedCollection
+ * InheritedIterable
*/
- class_collection<InheritedCollection>
+ class_iterable<InheritedSet>
(
- "InheritedCollection",
- "Iterable of string\n"
- "A collection of inherited packages."
+ "InheritedIterable",
+ "Iterable of string"
);
/**
@@ -230,13 +226,12 @@ void PALUDIS_VISIBLE expose_name()
;
/**
- * QualifiedPackageNameCollection
+ * QualifiedPackageNameIterable
*/
- class_collection<QualifiedPackageNameCollection>
+ class_iterable<QualifiedPackageNameSet>
(
- "QualifiedPackageNameCollection",
- "Iterable of QualifiedPackageName\n"
- "A collection of QualifiedPackageName instances."
+ "QualifiedPackageNameIterable",
+ "Iterable of QualifiedPackageName"
);
/**
@@ -265,12 +260,11 @@ void PALUDIS_VISIBLE expose_name()
;
/**
- * IUseFlagNameCollection
+ * IUseFlagNameIterable
*/
- class_collection<IUseFlagCollection>
+ class_iterable<IUseFlagSet>
(
- "IUseFlagCollection",
- "Iterable of IUseFlag\n"
- "A collection of use flags."
+ "IUseFlagIterable",
+ "Iterable of IUseFlag"
);
}
diff --git a/python/name_TEST.py b/python/name_TEST.py
index e1d9240..285ea22 100755
--- a/python/name_TEST.py
+++ b/python/name_TEST.py
@@ -45,11 +45,11 @@ class TestCase_Names(unittest.TestCase):
self.assertRaises(RepositoryNameError, RepositoryName, ":bad")
self.assertRaises(KeywordNameError, KeywordName, ":bad")
self.assertRaises(SetNameError, SetName, ":bad")
- self.assertRaises(Exception, PackageNamePartCollection)
- self.assertRaises(Exception, CategoryNamePartCollection)
- self.assertRaises(Exception, QualifiedPackageNameCollection)
- self.assertRaises(Exception, UseFlagNameCollection)
- self.assertRaises(Exception, RepositoryNameCollection)
+ self.assertRaises(Exception, PackageNamePartIterable)
+ self.assertRaises(Exception, CategoryNamePartIterable)
+ self.assertRaises(Exception, QualifiedPackageNameIterable)
+ self.assertRaises(Exception, UseFlagNameIterable)
+ self.assertRaises(Exception, RepositoryNameIterable)
def test_3_str(self):
self.test_1_create()
diff --git a/python/package_database.cc b/python/package_database.cc
index 25cea5c..e463c9a 100644
--- a/python/package_database.cc
+++ b/python/package_database.cc
@@ -22,9 +22,8 @@
#include <paludis/dep_spec.hh>
#include <paludis/query.hh>
#include <paludis/environment.hh>
-#include <paludis/package_database_entry.hh>
+#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
-#include <paludis/util/collection.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
@@ -66,18 +65,17 @@ void PALUDIS_VISIBLE expose_package_database()
* PackageDatabase
*/
register_shared_ptrs_to_python<PackageDatabase>();
- tr1::shared_ptr<PackageDatabaseEntryCollection>
- (PackageDatabase::* query)(const Query &, const QueryOrder) const = &PackageDatabase::query;
- tr1::shared_ptr<const Repository>
- (PackageDatabase::* fetch_repository)(const RepositoryName &) const = &PackageDatabase::fetch_repository;
+ tr1::shared_ptr<Repository>
+ (PackageDatabase::* fetch_repository_ptr)(const RepositoryName &) = &PackageDatabase::fetch_repository;
bp::class_<PackageDatabase, boost::noncopyable>
(
"PackageDatabase",
"A PackageDatabase can be queried for Package instances.\n",
bp::no_init
)
- .def("query", query,
- "query(Query, QueryOrder) -> PackageDatabaseEntryCollection\n"
+ .def("query", &PackageDatabase::query, bp::with_custodian_and_ward_postcall<0, 1>(),
+
+ "query(Query, QueryOrder) -> PackageIDIterable\n"
"Query the repository."
)
@@ -86,7 +84,7 @@ void PALUDIS_VISIBLE expose_package_database()
"Name of our 'favourite' repository"
)
- .def("fetch_repository", fetch_repository,
+ .def("fetch_repository", fetch_repository_ptr, bp::with_custodian_and_ward_postcall<0, 1>(),
"fetch_repository(RepositoryName) -> Repository\n"
"Fetch a named repository."
)
@@ -107,33 +105,4 @@ void PALUDIS_VISIBLE expose_package_database()
"Our repositories"
)
;
-
- /**
- * PackageDatabaseEntry
- */
- bp::register_ptr_to_python<tr1::shared_ptr<PackageDatabaseEntry> >();
- bp::class_<PackageDatabaseEntry>
- (
- "PackageDatabaseEntry",
- "Holds an entry in a PackageDatabase, and used to identify"
- " a specific version of a package in a particular repository.",
- bp::init<const QualifiedPackageName &, const VersionSpec &, const RepositoryName &>(
- "__init__(QualifiedPackageName, VersionSpec, RepositoryName)"
- )
- )
- .def(bp::self_ns::str(bp::self))
-
- .def("__eq__", &PackageDatabaseEntry::operator==)
-
- .def("__ne__", &py_ne<PackageDatabaseEntry>)
- ;
-
- /**
- * PackageDatabaseEntryCollection
- */
- class_collection<PackageDatabaseEntryCollection>
- (
- "PackageDatabaseEntryCollection",
- "An iterable collection of PackageDatabaseEntry instances."
- );
}
diff --git a/python/package_database_TEST.py b/python/package_database_TEST.py
index a5c50ce..5b88458 100755
--- a/python/package_database_TEST.py
+++ b/python/package_database_TEST.py
@@ -51,10 +51,9 @@ class TestCase_PackageDatabase(unittest.TestCase):
def test_5_query(self):
self.get_db()
pkgs = list(self.db.query(Query.Package("foo/bar"), QueryOrder.ORDER_BY_VERSION))
- self.assertEqual(pkgs, [
- PackageDatabaseEntry("foo/bar", "1.0", "testrepo"),
- PackageDatabaseEntry("foo/bar", "2.0", "testrepo"),
- ])
+ self.assertEqual([x.canonical_form(PackageIDCanonicalForm.FULL) for x in pkgs], [
+ "foo/bar-1.0::testrepo",
+ "foo/bar-2.0::testrepo"])
pkgs = list(self.db.query(Query.Matches(PackageDepSpec(">=foo/bar-10", PackageDepSpecParseMode.PERMISSIVE)),
QueryOrder.ORDER_BY_VERSION))
diff --git a/python/package_id.cc b/python/package_id.cc
new file mode 100644
index 0000000..01e96cf
--- /dev/null
+++ b/python/package_id.cc
@@ -0,0 +1,107 @@
+/* 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/package_id.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/name.hh>
+#include <paludis/version_spec.hh>
+#include <paludis/util/sequence.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct PackageIDWrapper
+{
+ static PyObject *
+ find(const PackageID & self, const std::string & key)
+ {
+ PackageID::Iterator i(self.find(key));
+ if (i != self.end())
+ return bp::incref(bp::object(*i).ptr());
+ else
+ return Py_None;
+ }
+};
+
+void PALUDIS_VISIBLE expose_package_id()
+{
+ /**
+ * Enums
+ */
+ enum_auto("PackageIDCanonicalForm", last_idcf,
+ "How to generate paludis::PackageID::canonical_form().");
+
+ /**
+ * PackageID
+ */
+ register_shared_ptrs_to_python<PackageID>();
+ bp::class_<PackageID, boost::noncopyable>
+ (
+ "PackageID",
+ bp::no_init
+ )
+ .def("canonical_form", &PackageID::canonical_form,
+ "canonical_form(PackageIDCanonicalForm) -> string\n"
+ )
+
+ .add_property("name", &PackageID::name,
+ "[ro] QualifiedPackageName\n"
+ )
+
+ .add_property("version", &PackageID::version,
+ "[ro] VersionSpec\n"
+ )
+
+ .add_property("slot", &PackageID::slot,
+ "[ro] SlotName\n"
+ )
+
+ .add_property("repository", &PackageID::repository,
+ "[ro] Repository\n"
+ )
+
+ .add_property("eapi", &PackageID::eapi,
+ "[ro] EAPI\n"
+ )
+
+ .def("__iter__", bp::range(&PackageID::begin, &PackageID::end))
+
+ .def("find", &PackageIDWrapper::find,
+ "find(string) -> MetadataKey\n"
+ )
+
+ .def("__eq__", &py_eq<PackageID>)
+
+ .def("__ne__", &py_ne<PackageID>)
+ ;
+
+ /**
+ * PackageIDIterable
+ */
+ class_iterable<PackageIDSequence>
+ (
+ "PackageIDIterable",
+ "Iterable of PackageID"
+ );
+}
diff --git a/python/package_id_TEST.py b/python/package_id_TEST.py
new file mode 100755
index 0000000..adcf44d
--- /dev/null
+++ b/python/package_id_TEST.py
@@ -0,0 +1,75 @@
+#!/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
+#
+
+import os
+
+repo_path = os.path.join(os.getcwd(), "package_id_TEST_dir/testrepo")
+irepo_path = os.path.join(os.getcwd(), "package_id_TEST_dir/installed")
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_PackageID(unittest.TestCase):
+ def setUp(self):
+ global e, ie, pid, ipid
+ e = NoConfigEnvironment(repo_path, "/var/empty")
+ ie = NoConfigEnvironment(irepo_path)
+ pid = iter(e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ ipid = iter(ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()
+
+ def test_01_get(self):
+ pass
+
+ def test_02_name(self):
+ self.assertEquals(pid.name, QualifiedPackageName("foo/bar"))
+ self.assertEquals(ipid.name, QualifiedPackageName("cat-one/pkg-one"))
+
+ def test_03_version(self):
+ self.assertEquals(pid.version, VersionSpec("1.0"))
+ self.assertEquals(ipid.version, VersionSpec("1"))
+
+ def test_04_slot(self):
+ self.assertEquals(str(ipid.slot), "test_slot")
+ self.assertEquals(str(pid.slot), "0")
+
+ def test_05_repository(self):
+ self.assertEquals(str(pid.repository.name), "testrepo")
+ self.assertEquals(str(ipid.repository.name), "installed")
+
+ def test_06_eapi(self):
+ self.assertEquals(pid.eapi.name, "0")
+ self.assertEquals(ipid.eapi.name, "0")
+
+ def test_07_canonical_form(self):
+ self.assertEquals(pid.canonical_form(PackageIDCanonicalForm.FULL), "foo/bar-1.0::testrepo")
+ self.assertEquals(pid.canonical_form(PackageIDCanonicalForm.VERSION), "1.0")
+ self.assertEquals(pid.canonical_form(PackageIDCanonicalForm.NO_VERSION), "foo/bar::testrepo")
+
+ self.assertEquals(ipid.canonical_form(PackageIDCanonicalForm.FULL), "cat-one/pkg-one-1::installed")
+ self.assertEquals(ipid.canonical_form(PackageIDCanonicalForm.VERSION), "1")
+ self.assertEquals(ipid.canonical_form(PackageIDCanonicalForm.NO_VERSION), "cat-one/pkg-one::installed")
+
+ def test_08_find(self):
+ self.assert_(isinstance(pid.find("DEPEND"), MetadataDependencySpecTreeKey))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/package_id_TEST_cleanup.sh b/python/package_id_TEST_cleanup.sh
new file mode 100755
index 0000000..2b07ea8
--- /dev/null
+++ b/python/package_id_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d package_id_TEST_dir ] ; then
+ rm -fr package_id_TEST_dir
+else
+ true
+fi
diff --git a/python/version_metadata_TEST_setup.sh b/python/package_id_TEST_setup.sh
index 96dd1e8..05efdec 100755
--- a/python/version_metadata_TEST_setup.sh
+++ b/python/package_id_TEST_setup.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# vim: set ft=sh sw=4 sts=4 et :
-mkdir version_metadata_TEST_dir || exit 1
-cd version_metadata_TEST_dir || exit 1
+mkdir package_id_TEST_dir || exit 1
+cd package_id_TEST_dir || exit 1
mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
cd testrepo || exit 1
@@ -24,7 +24,7 @@ DESCRIPTION="Test package"
HOMEPAGE="http://paludis.pioto.org/"
SRC_URI="http://example.com/${P}.tar.bz2"
SLOT="0"
-IUSE=""
+IUSE="testflag"
LICENSE="GPL-2"
KEYWORDS="test"
RESTRICT="monkey"
@@ -36,10 +36,14 @@ cd ..
mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
-touch installed/cat-one/pkg-one-1/CONTENTS
-touch installed/cat-one/pkg-two-1/CONTENTS
+echo "cat-one" > installed/cat-one/pkg-one-1/CATEGORY
+touch installed/cat-one/pkg-one-1/CONTENTS
+echo "0" > installed/cat-one/pkg-one-1/EAPI
+echo "a description" > installed/cat-one/pkg-one-1/DESCRIPTION
+echo "test_inherited" > installed/cat-one/pkg-one-1/INHERITED
+echo "test_iuse test" > installed/cat-one/pkg-one-1/IUSE
+echo "test" > installed/cat-one/pkg-one-1/KEYWORDS
echo "origin_test" > installed/cat-one/pkg-one-1/REPOSITORY
-echo "0" > installed/cat-one/pkg-one-1/SLOT
-echo "0" > installed/cat-one/pkg-two-1/SLOT
-
+echo "test_slot" > installed/cat-one/pkg-one-1/SLOT
+echo "test test_use" > installed/cat-one/pkg-one-1/USE
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 2ca0f16..8c73a2f 100755..100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -67,13 +67,23 @@ namespace paludis
{
namespace python
{
+ // Which shared_ptrs to expose
+ enum RegisterSharedPointers
+ {
+ rsp_both,
+ rsp_non_const,
+ rsp_const
+ };
+
// register shared_ptrs
template <typename T_>
void
- register_shared_ptrs_to_python()
+ register_shared_ptrs_to_python(RegisterSharedPointers rsp=rsp_both)
{
- boost::python::register_ptr_to_python<tr1::shared_ptr<T_> >();
- boost::python::register_ptr_to_python<tr1::shared_ptr<const T_> >();
+ if (rsp == rsp_both || rsp == rsp_non_const)
+ boost::python::register_ptr_to_python<tr1::shared_ptr<T_> >();
+ if (rsp == rsp_both || rsp == rsp_const)
+ boost::python::register_ptr_to_python<tr1::shared_ptr<const T_> >();
boost::python::implicitly_convertible<tr1::shared_ptr<T_>, tr1::shared_ptr<const T_> >();
}
@@ -99,7 +109,7 @@ namespace paludis
// Compare
template <typename T_>
- int py_cmp(T_ & a, T_ & b)
+ int py_cmp(const T_ & a, const T_ & b)
{
if (a == b)
return 0;
@@ -109,9 +119,16 @@ namespace paludis
return 1;
}
+ // Equal
+ template <typename T_>
+ bool py_eq(const T_ & a, const T_ & b)
+ {
+ return (a == b);
+ }
+
// Not equal
template <typename T_>
- bool py_ne(T_ & a, T_ & b)
+ bool py_ne(const T_ & a, const T_ & b)
{
return ! (a == b);
}
@@ -133,13 +150,13 @@ namespace paludis
}
};
- // expose *Collection classes
+ // expose iterable classes
template <typename C_>
- class class_collection :
+ class class_iterable :
public boost::python::class_<C_, boost::noncopyable>
{
public:
- class_collection(const std::string & name, const std::string & class_doc) :
+ class_iterable(const std::string & name, const std::string & class_doc) :
boost::python::class_<C_, boost::noncopyable>(name.c_str(), class_doc.c_str(),
boost::python::no_init)
{
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index f5cdd30..7f3b8ad 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -30,12 +30,13 @@ void expose_exception();
void expose_fs_entry();
void expose_log();
void expose_mask_reasons();
+void expose_metadata_key();
void expose_name();
void expose_package_database();
+void expose_package_id();
void expose_portage_dep_parser();
void expose_query();
void expose_repository();
-void expose_version_metadata();
void expose_version_operator();
void expose_version_requirements();
void expose_version_spec();
@@ -54,7 +55,6 @@ BOOST_PYTHON_MODULE(paludis)
expose_eapi();
expose_contents();
expose_mask_reasons();
- expose_version_metadata();
expose_dep_spec();
expose_dep_tag();
expose_portage_dep_parser();
@@ -62,6 +62,8 @@ BOOST_PYTHON_MODULE(paludis)
expose_log();
expose_query();
expose_environment();
+ expose_metadata_key();
+ expose_package_id();
expose_package_database();
expose_repository();
}
diff --git a/python/repository.cc b/python/repository.cc
index 4e689d7..5ccafcb 100644
--- a/python/repository.cc
+++ b/python/repository.cc
@@ -19,10 +19,14 @@
#include <paludis_python.hh>
-#include <datetime.h>
-
#include <paludis/repository.hh>
-#include <paludis/repositories/gentoo/portage_repository.hh>
+#include <paludis/repository_info.hh>
+#include <paludis/repositories/e/e_repository.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/package_id.hh>
+#include <paludis/environment.hh>
+#include <paludis/util/set.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
@@ -125,12 +129,6 @@ struct RepositoryWrapper :
return self.destination_interface;
}
- static RepositoryContentsInterface *
- get_contents_interface(const Repository & self)
- {
- return self.contents_interface;
- }
-
static RepositoryConfigInterface *
get_config_interface(const Repository & self)
{
@@ -143,28 +141,30 @@ struct RepositoryWrapper :
return self.licenses_interface;
}
- static RepositoryPortageInterface *
- get_portage_interface(const Repository & self)
+ static RepositoryEInterface *
+ get_e_interface(const Repository & self)
{
- return self.portage_interface;
+ return self.e_interface;
}
};
-struct RepositoryInstalledInterfaceWrapper :
- RepositoryInstalledInterface
+struct FakeRepositoryWrapper :
+ FakeRepository,
+ bp::wrapper<FakeRepository>
{
- static PyObject *
- installed_time(const RepositoryInstalledInterface & self,
- const QualifiedPackageName & qpn, const VersionSpec & vs)
+ FakeRepositoryWrapper(const Environment * const env, const RepositoryName & name) :
+ FakeRepository(env, name)
{
- PyDateTime_IMPORT;
- return PyDateTime_FromTimestamp(bp::make_tuple(self.installed_time(qpn, vs)).ptr());
}
+ static tr1::shared_ptr<PackageID>
+ add_version(FakeRepository & self, const QualifiedPackageName & qpn, const VersionSpec & vs)
+ {
+ return self.add_version(qpn, vs);
+ }
};
-struct RepositoryLicensesInterfaceWrapper :
- RepositoryLicensesInterface
+struct RepositoryLicensesInterfaceWrapper
{
static PyObject *
license_exists(const RepositoryLicensesInterface & self, const std::string & license)
@@ -177,26 +177,41 @@ struct RepositoryLicensesInterfaceWrapper :
}
};
-struct RepositoryPortageInterfaceWrapper :
- RepositoryPortageInterface
+struct RepositoryEInterfaceWrapper
{
static bp::object
- my_find_profile(const RepositoryPortageInterface & self, const FSEntry & location)
+ my_find_profile(const RepositoryEInterface & self, const FSEntry & location)
{
- ProfilesIterator p(self.find_profile(location));
+ RepositoryEInterface::ProfilesIterator p(self.find_profile(location));
if (p == self.end_profiles())
return bp::object();
return bp::object(bp::ptr(&*p));
}
static void
- my_set_profile(RepositoryPortageInterface & self, const ProfilesDescLine & pdl)
+ my_set_profile(RepositoryEInterface & self, const RepositoryEInterface::ProfilesDescLine & pdl)
{
self.set_profile(self.find_profile(pdl.path));
}
-
};
+// FIXME
+//template <typename I_>
+//struct repository_interface_to_python
+//{
+// static PyObject *
+// convert(const I_ & i)
+// {
+// return 0;
+// return bp::incref(bp::object(bp::ptr(&i)).ptr());
+// }
+//};
+//
+//template <typename I_>
+//void register_repository_interface_to_python()
+//{
+// bp::to_python_converter<I_, repository_interface_to_python<I_> >();
+//}
void PALUDIS_VISIBLE expose_repository()
{
@@ -223,13 +238,12 @@ void PALUDIS_VISIBLE expose_repository()
"Thrown if an environment variable query fails.");
/**
- * DestinationCollection
+ * DestinationIterable
*/
- class_collection<DestinationsCollection>
+ class_iterable<DestinationsSet>
(
- "DestinationsCollection",
- "Iterable of Repository.\n"
- "A set of Destinations."
+ "DestinationsIterable",
+ "Iterable of Repository."
);
/**
@@ -273,15 +287,15 @@ void PALUDIS_VISIBLE expose_repository()
/**
* Repository
*/
- register_shared_ptrs_to_python<Repository>();
- bp::class_<RepositoryWrapper, boost::noncopyable>
+ register_shared_ptrs_to_python<Repository>(rsp_const);
+ bp::class_<RepositoryWrapper, tr1::shared_ptr<Repository>, boost::noncopyable>
(
"Repository",
"A Repository provides a representation of a physical repository to a PackageDatabase.",
bp::no_init
)
.def("info", &Repository::info, &RepositoryWrapper::default_info,
- "info() -> RepositoryInfo"
+ "info() -> RepositoryInfo\n"
"Fetch information about the repository."
)
@@ -302,39 +316,30 @@ void PALUDIS_VISIBLE expose_repository()
)
.def("has_package_named", &Repository::has_package_named,
+ "has_package_named(QualifiedPackageName) -> bool\n"
"Do we have a package in the given category with the given name?"
)
.add_property("category_names", &Repository::category_names,
- "[ro] CategoryNamePartCollection\n"
+ "[ro] CategoryNamePartIterable\n"
"Our category names."
)
.def("category_names_containing_package", &Repository::category_names_containing_package,
- "category_names_containing_package(PackageNamePart) -> CategoryNamePartCollection\n"
+ "category_names_containing_package(PackageNamePart) -> CategoryNamePartIterable\n"
"Fetch categories that contain a named package."
)
.def("package_names", &Repository::package_names,
- "package_names(CategoryNamePart) -> QualifiedPackageNameCollection\n"
+ "package_names(CategoryNamePart) -> QualifiedPackageNameIterable\n"
"Fetch our package names."
)
- .def("version_specs", &Repository::version_specs,
- "version_specs(QualifiedPackageName) -> VersionSpecCollection\n"
+ .def("package_ids", &Repository::package_ids, bp::with_custodian_and_ward_postcall<0, 1>(),
+ "package_ids(QualifiedPackageName) -> PackageIDIterable\n"
"Fetch our versions."
)
- .def("has_version", &Repository::has_version,
- "has_version(QualifiedPackageName, VersionSpec) -> bool\n"
- "Do we have a version spec?"
- )
-
- .def("version_metadata", &Repository::version_metadata,
- "version_metadata(QualifiedPackageName, VersionSpec) -> VersionMetadata\n"
- "Fetch metadata."
- )
-
.add_property("mask_interface", bp::make_function(&RepositoryWrapper::get_mask_interface,
bp::return_internal_reference<>()),
"[ro] RepositoryMaskInterface"
@@ -401,11 +406,6 @@ void PALUDIS_VISIBLE expose_repository()
"[ro] RepositoryDestinationInterface"
)
- .add_property("contents_interface", bp::make_function(&RepositoryWrapper::get_contents_interface,
- bp::return_internal_reference<>()),
- "[ro] RepositoryContentsInterface"
- )
-
.add_property("config_interface", bp::make_function(&RepositoryWrapper::get_config_interface,
bp::return_internal_reference<>()),
"[ro] RepositoryConfigInterface"
@@ -416,34 +416,33 @@ void PALUDIS_VISIBLE expose_repository()
"[ro] RepositoryLicensesInterface"
)
- .add_property("portage_interface", bp::make_function(&RepositoryWrapper::get_portage_interface,
+ .add_property("e_interface", bp::make_function(&RepositoryWrapper::get_e_interface,
bp::return_internal_reference<>()),
- "[ro] RepositoryPortageInterface"
+ "[ro] RepositoryEInterface"
)
;
/**
- * RepositoryPortageInterfaceProfilesDescLine
+ * RepositoryEInterfaceProfilesDescLine
*/
- bp::class_<RepositoryPortageInterfaceProfilesDescLine>
+ bp::class_<RepositoryEInterfaceProfilesDescLine>
(
- "RepositoryPortageInterfaceProfilesDescLine",
- "A profiles.desc line in a Repository implementing RepositoryPortageInterface.",
+ "RepositoryEInterfaceProfilesDescLine",
+ "A profiles.desc line in a Repository implementing RepositoryEInterface.",
bp::no_init
)
- .add_property("path", bp::make_getter(&RepositoryPortageInterfaceProfilesDescLine::path,
+ .add_property("path", bp::make_getter(&RepositoryEInterfaceProfilesDescLine::path,
bp::return_value_policy<bp::return_by_value>())
)
- .def_readonly("arch", &RepositoryPortageInterfaceProfilesDescLine::arch)
+ .def_readonly("arch", &RepositoryEInterfaceProfilesDescLine::arch)
- .def_readonly("status", &RepositoryPortageInterfaceProfilesDescLine::status)
+ .def_readonly("status", &RepositoryEInterfaceProfilesDescLine::status)
;
/**
* RepositoryMaskInterface
*/
- bp::register_ptr_to_python<RepositoryMaskInterface *>();
bp::class_<RepositoryMaskInterface, boost::noncopyable>
(
"RepositoryMaskInterface",
@@ -451,12 +450,12 @@ void PALUDIS_VISIBLE expose_repository()
bp::no_init
)
.def("query_repository_masks", &RepositoryMaskInterface::query_repository_masks,
- "query_repository_masks(QualifiedPackageName, VersionSpec) -> bool\n"
+ "query_repository_masks(PackageID) -> bool\n"
"Query repository masks."
)
.def("query_profile_masks", &RepositoryMaskInterface::query_profile_masks,
- "query_profile_masks(QualifiedPackageName, VersionSpec) -> bool\n"
+ "query_profile_masks(PackageID) -> bool\n"
"Query profile masks."
)
;
@@ -464,7 +463,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryUseInterface
*/
- bp::register_ptr_to_python<RepositoryUseInterface *>();
bp::class_<RepositoryUseInterface, boost::noncopyable>
(
"RepositoryUseInterface",
@@ -473,25 +471,25 @@ void PALUDIS_VISIBLE expose_repository()
)
.def("query_use", &RepositoryUseInterface::query_use,
("ufn", bp::arg("pde")),
- "query_use(UseFlagName, PackageDatabaseEntry) -> UseFlagState\n"
+ "query_use(UseFlagName, PackageID) -> UseFlagState\n"
"Query the state of the specified use flag."
)
.def("query_use_mask", &RepositoryUseInterface::query_use_mask,
("ufn", bp::arg("pde")),
- "query_use_mask(UseFlagName, PackageDatabaseEntry) -> bool\n"
+ "query_use_mask(UseFlagName, PackageID) -> bool\n"
"Query whether the specified use flag is masked."
)
.def("query_use_force", &RepositoryUseInterface::query_use_force,
("ufn", bp::arg("pde")),
- "query_use_force(UseFlagName, PackageDatabaseEntry) -> bool\n"
+ "query_use_force(UseFlagName, PackageID) -> bool\n"
"Query whether the specified use flag is forceed."
)
.def("describe_use_flag", &RepositoryUseInterface::describe_use_flag,
("ufn", bp::arg("pde")),
- "describe_use_flag(UseFlagName, PackageDatabaseEntry) -> string\n"
+ "describe_use_flag(UseFlagName, PackageID) -> string\n"
"Describe a use flag."
)
;
@@ -499,17 +497,12 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryInstalledInterface
*/
- bp::register_ptr_to_python<RepositoryInstalledInterface *>();
bp::class_<RepositoryInstalledInterface, boost::noncopyable>
(
"RepositoryInstalledInterface",
"Interface for handling actions for installed repositories.",
bp::no_init
)
- .def("installed_time", &RepositoryInstalledInterfaceWrapper::installed_time,
- "installed_time(QualifiedPackageName, VersionSpec) -> datetime\n"
- "When was a package installed."
- )
.def("root", bp::pure_virtual(&RepositoryInstalledInterface::root),
"What is our filesystem root?"
)
@@ -518,7 +511,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryInstallableInterface
*/
- bp::register_ptr_to_python<RepositoryInstallableInterface *>();
bp::class_<RepositoryInstallableInterface, boost::noncopyable>
(
"RepositoryInstallableInterface",
@@ -529,7 +521,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryUninstallableInterface
*/
- bp::register_ptr_to_python<RepositoryUninstallableInterface *>();
bp::class_<RepositoryUninstallableInterface, boost::noncopyable>
(
"RepositoryUninstallableInterface",
@@ -540,7 +531,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositorySetsInterface
*/
- bp::register_ptr_to_python<RepositorySetsInterface *>();
bp::class_<RepositorySetsInterface, boost::noncopyable>
(
"RepositorySetsInterface",
@@ -551,7 +541,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositorySyncableInterface
*/
- bp::register_ptr_to_python<RepositorySyncableInterface *>();
bp::class_<RepositorySyncableInterface, boost::noncopyable>
(
"RepositorySyncableInterface",
@@ -562,7 +551,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryWorldInterface
*/
- bp::register_ptr_to_python<RepositoryWorldInterface *>();
bp::class_<RepositoryWorldInterface, boost::noncopyable>
(
"RepositoryWorldInterface",
@@ -573,7 +561,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryEnvironmentVariableInterface
*/
- bp::register_ptr_to_python<RepositoryEnvironmentVariableInterface *>();
bp::class_<RepositoryEnvironmentVariableInterface, boost::noncopyable>
(
"RepositoryEnvironmentVariableInterface",
@@ -584,7 +571,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryMirrorsInterface
*/
- bp::register_ptr_to_python<RepositoryMirrorsInterface *>();
bp::class_<RepositoryMirrorsInterface, boost::noncopyable>
(
"RepositoryMirrorsInterface",
@@ -595,7 +581,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryVirtualsInterface
*/
- bp::register_ptr_to_python<RepositoryVirtualsInterface *>();
bp::class_<RepositoryVirtualsInterface, boost::noncopyable>
(
"RepositoryVirtualsInterface",
@@ -606,7 +591,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryProvidesInterface
*/
- bp::register_ptr_to_python<RepositoryProvidesInterface *>();
bp::class_<RepositoryProvidesInterface, boost::noncopyable>
(
"RepositoryProvidesInterface",
@@ -617,7 +601,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryDestinationInterface
*/
- bp::register_ptr_to_python<RepositoryDestinationInterface *>();
bp::class_<RepositoryDestinationInterface, boost::noncopyable>
(
"RepositoryDestinationInterface",
@@ -626,25 +609,8 @@ void PALUDIS_VISIBLE expose_repository()
);
/**
- * RepositoryContentsInterface
- */
- bp::register_ptr_to_python<RepositoryContentsInterface *>();
- bp::class_<RepositoryContentsInterface, boost::noncopyable>
- (
- "RepositoryContentsInterface",
- "Interface for handling actions for repositories supporting contents queries.",
- bp::no_init
- )
- .def("contents", &RepositoryContentsInterface::contents,
- "contents(QualifiedPackageName, VersionSpec) -> Contents\n"
- "Fetch contents."
- )
- ;
-
- /**
* RepositoryConfigInterface
*/
- bp::register_ptr_to_python<RepositoryConfigInterface *>();
bp::class_<RepositoryConfigInterface, boost::noncopyable>
(
"RepositoryConfigInterface",
@@ -655,7 +621,6 @@ void PALUDIS_VISIBLE expose_repository()
/**
* RepositoryLicensesInterface
*/
- bp::register_ptr_to_python<RepositoryLicensesInterface *>();
bp::class_<RepositoryLicensesInterface, boost::noncopyable>
(
"RepositoryLicensesInterface",
@@ -669,28 +634,47 @@ void PALUDIS_VISIBLE expose_repository()
;
/**
- * RepositoryPortageInterface
+ * RepositoryEInterface
*/
- bp::register_ptr_to_python<RepositoryPortageInterface *>();
- bp::class_<RepositoryPortageInterface, boost::noncopyable>
+ bp::class_<RepositoryEInterface, boost::noncopyable>
(
- "RepositoryPortageInterface",
- "Interface for handling PortageRepository specific functionality.",
+ "RepositoryEInterface",
+ "Interface for handling ERepository specific functionality.",
bp::no_init
)
- .add_property("profiles", bp::range(&RepositoryPortageInterface::begin_profiles,
- &RepositoryPortageInterface::end_profiles),
+ .add_property("profiles", bp::range(&RepositoryEInterface::begin_profiles,
+ &RepositoryEInterface::end_profiles),
"[ro] Iterable of Profiles"
)
- .def("profile_variable", &RepositoryPortageInterface::profile_variable)
+ .def("profile_variable", &RepositoryEInterface::profile_variable)
- .def("find_profile", &RepositoryPortageInterfaceWrapper::my_find_profile,
- "find_profile(path_string) -> RepositoryPortageInterfaceProfilesDescLine"
+ .def("find_profile", &RepositoryEInterfaceWrapper::my_find_profile,
+ "find_profile(path_string) -> RepositoryEInterfaceProfilesDescLine"
)
- .add_property("profile", bp::object(), &RepositoryPortageInterfaceWrapper::my_set_profile,
- "[wo] RepositoryPortageInterfaceProfilesDescLine"
+ .add_property("profile", bp::object(), &RepositoryEInterfaceWrapper::my_set_profile,
+ "[wo] RepositoryEInterfaceProfilesDescLine"
)
;
+
+ /**
+ * FakeRepository
+ */
+ tr1::shared_ptr<FakePackageID>
+ (FakeRepository:: *add_version_ptr)(const QualifiedPackageName &, const VersionSpec &) =
+ &FakeRepository::add_version;
+
+ bp::class_<FakeRepositoryWrapper, tr1::shared_ptr<FakeRepository>, bp::bases<Repository>, boost::noncopyable>
+ (
+ "FakeRepository",
+ "Fake repository for use in test cases.",
+ bp::init<const Environment * const, const RepositoryName &>("__init__(Environment, RepositoryName)")
+ )
+ .def("add_category", &FakeRepository::add_category)
+
+ .def("add_package", &FakeRepository::add_package)
+
+ .def("add_version", &FakeRepositoryWrapper::add_version)
+ ;
}
diff --git a/python/repository_TEST.py b/python/repository_TEST.py
index 5fb7a33..820e51c 100755
--- a/python/repository_TEST.py
+++ b/python/repository_TEST.py
@@ -20,7 +20,7 @@
import os
-repo = os.path.join(os.getcwd(), "repository_TEST_dir/testrepo")
+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 *
@@ -28,89 +28,62 @@ import unittest
Log.instance.log_level = LogLevel.WARNING
-class TestCase_Repository(unittest.TestCase):
- def get_foo(self):
- self.e = EnvironmentMaker.instance.make_from_spec("")
- self.nce = NoConfigEnvironment(repo)
- self.db = self.e.package_database
- self.repo = self.db.fetch_repository("testrepo")
- self.irepo = self.db.fetch_repository("installed")
+class TestCase_01_Repository(unittest.TestCase):
+ def setUp(self):
+ global e, nce, db, repo, irepo
+ e = EnvironmentMaker.instance.make_from_spec("")
+ nce = NoConfigEnvironment(repo_path)
+ db = e.package_database
+ repo = db.fetch_repository("testrepo")
+ irepo = db.fetch_repository("installed")
- def test_01_get(self):
- self.get_foo()
+ def test_01_fetch(self):
+ self.assert_(isinstance(repo, Repository))
+ self.assert_(isinstance(irepo, Repository))
def test_02_create_error(self):
self.assertRaises(Exception, Repository)
def test_03_name(self):
- self.get_foo()
-
- self.assertEquals(str(self.repo.name), "testrepo")
- self.assertEquals(str(self.irepo.name), "installed")
+ self.assertEquals(str(repo.name), "testrepo")
+ self.assertEquals(str(irepo.name), "installed")
def test_04_format(self):
- self.get_foo()
-
- self.assertEquals(str(self.repo.format), "ebuild")
- self.assertEquals(str(self.irepo.format), "vdb")
-
- def test_05_has_version(self):
- self.get_foo()
-
- self.assert_(self.repo.has_version("foo/bar", "1.0"))
- self.assert_(self.repo.has_version("foo/bar", "2.0"))
- self.assert_(not self.repo.has_version("foo/barbar", "1.0"))
- self.assert_(not self.repo.has_version("foo/bar", "3.0"))
-
- def test_06_has_category_named(self):
- self.get_foo()
-
- self.assert_(self.repo.has_category_named("foo"))
- self.assert_(not self.repo.has_category_named("bar"))
-
- def test_07_has_package_named(self):
- self.get_foo()
+ self.assertEquals(str(repo.format), "ebuild")
+ self.assertEquals(str(irepo.format), "vdb")
- self.assert_(self.repo.has_package_named("foo/bar"))
- self.assert_(not self.repo.has_package_named("foo/foo"))
- self.assert_(not self.repo.has_package_named("bar/foo"))
+ def test_05_has_category_named(self):
+ self.assert_(repo.has_category_named("foo"))
+ self.assert_(not repo.has_category_named("bar"))
- def test_08_version_specs(self):
- self.get_foo()
+ def test_06_has_package_named(self):
+ self.assert_(repo.has_package_named("foo/bar"))
+ self.assert_(not repo.has_package_named("foo/foo"))
+ self.assert_(not repo.has_package_named("bar/foo"))
- self.assertEquals(list(self.repo.version_specs("foo/bar")),
+ def test_07_package_ids(self):
+ self.assertEquals([x.version for x in repo.package_ids("foo/bar")],
[VersionSpec("1.0"), VersionSpec("2.0")]
)
- self.assertEquals(len(list(self.repo.version_specs("bar/baz"))), 0)
+ self.assertEquals(len(list(repo.package_ids("bar/baz"))), 0)
- def test_09_category_names(self):
- self.get_foo()
+ def test_08_category_names(self):
+ self.assertEquals([str(x) for x in repo.category_names], ["foo", "foo1", "foo2", "foo3", "foo4"])
- for (i, cat) in enumerate(self.repo.category_names):
- self.assertEquals(i, 0)
- self.assertEquals(str(cat), "foo")
-
- def test_10_category_names_containing_package(self):
- self.get_foo()
+ def test_09_category_names_containing_package(self):
+ self.assertEquals([str(x) for x in repo.category_names_containing_package("bar")],
+ ["foo", "foo1", "foo2", "foo3", "foo4"])
- for (i, cat) in enumerate(self.repo.category_names_containing_package("bar")):
- self.assertEquals(i, 0)
- self.assertEquals(str(cat), "foo")
-
- def test_11_package_names(self):
- self.get_foo()
-
- for (i, qpn) in enumerate(self.repo.package_names("bar")):
+ def test_10_package_names(self):
+ for (i, qpn) in enumerate(repo.package_names("bar")):
self.assertEquals(i, 0)
self.assertEquals(str(qpn), "foo/bar")
- def test_12_repository_info(self):
- self.get_foo()
-
- self.assert_(isinstance(self.repo.info(True), RepositoryInfo))
- self.assert_(isinstance(self.repo.info(False), RepositoryInfo))
+ def test_11_repository_info(self):
+ self.assert_(isinstance(repo.info(True), RepositoryInfo))
+ self.assert_(isinstance(repo.info(False), RepositoryInfo))
- for (i, section) in enumerate(self.repo.info(False).sections):
+ for (i, section) in enumerate(repo.info(False).sections):
self.assert_(isinstance(section, RepositoryInfoSection))
if i == 0:
self.assertEquals(section.heading, "Configuration information")
@@ -118,7 +91,7 @@ class TestCase_Repository(unittest.TestCase):
if k == "format":
self.assertEquals(v, "ebuild")
- for (i, section) in enumerate(self.irepo.info(False).sections):
+ for (i, section) in enumerate(irepo.info(False).sections):
self.assert_(isinstance(section, RepositoryInfoSection))
if i == 0:
self.assertEquals(section.heading, "Configuration information")
@@ -126,190 +99,210 @@ class TestCase_Repository(unittest.TestCase):
if k == "format":
self.assertEquals(v, "vdb")
- def test_13_version_metadata(self):
- self.get_foo()
-
- vm = self.repo.version_metadata("foo/bar", "1.0")
- self.assert_(isinstance(vm, VersionMetadata))
-
-
- def test_14_installable_interface(self):
- self.get_foo()
-
- ii = self.repo.installable_interface
+class TestCase_02_RepositoryInterfaces(unittest.TestCase):
+ def setUp(self):
+ global e, nce, db, repo, irepo
+ e = EnvironmentMaker.instance.make_from_spec("")
+ nce = NoConfigEnvironment(repo_path)
+ db = e.package_database
+ repo = db.fetch_repository("testrepo")
+ irepo = db.fetch_repository("installed")
+
+ def test_01_installable_interface(self):
+ ii = repo.installable_interface
self.assert_(isinstance(ii, RepositoryInstallableInterface))
- def test_15_installed_interface(self):
- import datetime
- self.get_foo()
-
- ii = self.irepo.installed_interface
-
+ def test_02_installed_interface(self):
+ ii = irepo.installed_interface
self.assert_(isinstance(ii, RepositoryInstalledInterface))
- time = ii.installed_time("cat-one/pkg-one", "1")
- self.assert_(type(time) == datetime.datetime)
-
- def test_16_mask_interface(self):
- self.get_foo()
-
- mi = self.repo.mask_interface
+ def test_03_mask_interface(self):
+ mi = repo.mask_interface
self.assert_(isinstance(mi, RepositoryMaskInterface))
- self.assert_(mi.query_profile_masks("foo1/bar", "1.0"))
- self.assert_(not mi.query_profile_masks("foo2/bar", "1.0"))
- self.assert_(mi.query_profile_masks("foo3/bar", "1.0"))
- self.assert_(not mi.query_profile_masks("foo4/bar", "1.0"))
+ foo = []
+ for i in [1,2,3,4]:
+ foo.append(iter(repo.package_ids("foo"+str(i)+"/bar")).next())
- def test_17_sets_interface(self):
- self.get_foo()
+ self.assert_(mi.query_profile_masks(foo[0]))
+ self.assert_(not mi.query_profile_masks(foo[1]))
+ self.assert_(mi.query_profile_masks(foo[2]))
+ self.assert_(not mi.query_profile_masks(foo[3]))
- si = self.repo.sets_interface
+ def test_04_sets_interface(self):
+ si = repo.sets_interface
self.assert_(isinstance(si, RepositorySetsInterface))
- def test_18_syncable_interface(self):
- self.get_foo()
-
- si = self.repo.syncable_interface
+ def test_05_syncable_interface(self):
+ si = repo.syncable_interface
self.assert_(isinstance(si, RepositorySyncableInterface))
- def test_19_uninstallable_interface(self):
- self.get_foo()
-
- ui = self.irepo.uninstallable_interface
+ def test_06_uninstallable_interface(self):
+ ui = irepo.uninstallable_interface
self.assert_(isinstance(ui, RepositoryUninstallableInterface))
- def test_20_use_interface(self):
- self.get_foo()
-
- ui = self.repo.use_interface
+ def test_07_use_interface(self):
+ ui = repo.use_interface
self.assert_(isinstance(ui, RepositoryUseInterface))
- p = PackageDatabaseEntry("foo/bar", "2.0", self.repo.name)
-
- self.assertEquals(ui.query_use("test1",p), UseFlagState.ENABLED)
- self.assertEquals(ui.query_use("test2",p), UseFlagState.DISABLED)
- self.assertEquals(ui.query_use("test3",p), UseFlagState.ENABLED)
- self.assertEquals(ui.query_use("test4",p), UseFlagState.UNSPECIFIED)
- self.assertEquals(ui.query_use("test5",p), UseFlagState.DISABLED)
- self.assertEquals(ui.query_use("test6",p), UseFlagState.ENABLED)
- self.assertEquals(ui.query_use("test7",p), UseFlagState.ENABLED)
-
- self.assert_(not ui.query_use_mask("test1", p))
- self.assert_(not ui.query_use_mask("test2", p))
- self.assert_(not ui.query_use_mask("test3", p))
- self.assert_(not ui.query_use_mask("test4", p))
- self.assert_(ui.query_use_mask("test5", p))
- self.assert_(not ui.query_use_mask("test6", p))
- self.assert_(not ui.query_use_mask("test7", p))
-
- self.assert_(not ui.query_use_force("test1", p))
- self.assert_(not ui.query_use_force("test2", p))
- self.assert_(not ui.query_use_force("test3", p))
- self.assert_(not ui.query_use_force("test4", p))
- self.assert_(not ui.query_use_force("test5", p))
- self.assert_(ui.query_use_force("test6", p))
- self.assert_(ui.query_use_force("test7", p))
-
- self.assert_(ui.describe_use_flag("test1", p), "A test use flag")
-
- def test_21_world_interface(self):
- self.get_foo()
-
- wi = self.irepo.world_interface
+ pid = list(repo.package_ids("foo/bar"))[1]
+
+ self.assertEquals(ui.query_use("test1", pid), UseFlagState.ENABLED)
+ self.assertEquals(ui.query_use("test2", pid), UseFlagState.DISABLED)
+ self.assertEquals(ui.query_use("test3", pid), UseFlagState.ENABLED)
+ self.assertEquals(ui.query_use("test4", pid), UseFlagState.UNSPECIFIED)
+ self.assertEquals(ui.query_use("test5", pid), UseFlagState.DISABLED)
+ self.assertEquals(ui.query_use("test6", pid), UseFlagState.ENABLED)
+ self.assertEquals(ui.query_use("test7", pid), UseFlagState.ENABLED)
+
+ self.assert_(not ui.query_use_mask("test1", pid))
+ self.assert_(not ui.query_use_mask("test2", pid))
+ self.assert_(not ui.query_use_mask("test3", pid))
+ self.assert_(not ui.query_use_mask("test4", pid))
+ self.assert_(ui.query_use_mask("test5", pid))
+ self.assert_(not ui.query_use_mask("test6", pid))
+ self.assert_(not ui.query_use_mask("test7", pid))
+
+ self.assert_(not ui.query_use_force("test1", pid))
+ self.assert_(not ui.query_use_force("test2", pid))
+ self.assert_(not ui.query_use_force("test3", pid))
+ self.assert_(not ui.query_use_force("test4", pid))
+ self.assert_(not ui.query_use_force("test5", pid))
+ self.assert_(ui.query_use_force("test6", pid))
+ self.assert_(ui.query_use_force("test7", pid))
+
+ self.assert_(ui.describe_use_flag("test1", pid), "A test use flag")
+
+ def test_08_world_interface(self):
+ wi = irepo.world_interface
self.assert_(isinstance(wi, RepositoryWorldInterface))
- def test_22_environment_variable_interface(self):
- self.get_foo()
-
- evi = self.repo.environment_variable_interface
+ def test_09_environment_variable_interface(self):
+ evi = repo.environment_variable_interface
self.assert_(isinstance(evi, RepositoryEnvironmentVariableInterface))
- def test_23_mirrors_interface(self):
- self.get_foo()
-
- mi = self.repo.mirrors_interface
+ def test_10_mirrors_interface(self):
+ mi = repo.mirrors_interface
self.assert_(isinstance(mi, RepositoryMirrorsInterface))
- def test_24_provides_interface(self):
- self.get_foo()
-
- pi = self.irepo.provides_interface
+ def test_11_provides_interface(self):
+ pi = irepo.provides_interface
self.assert_(isinstance(pi, RepositoryProvidesInterface))
- def test_25_virtuals_interface(self):
- self.get_foo()
-
- vi = self.repo.virtuals_interface
+ def test_12_virtuals_interface(self):
+ vi = repo.virtuals_interface
self.assert_(isinstance(vi, RepositoryVirtualsInterface))
- def test_26_destination_interface(self):
- self.get_foo()
-
- di = self.irepo.destination_interface
+ def test_13_destination_interface(self):
+ di = irepo.destination_interface
self.assert_(isinstance(di, RepositoryDestinationInterface))
- def test_27_contents_interface(self):
- self.get_foo()
-
- self.assert_(isinstance(self.irepo.contents_interface, RepositoryContentsInterface))
-
- contents = self.irepo.contents_interface.contents("cat-one/pkg-one", "1")
-
- for (i, entry) in enumerate(contents):
- if i == 0:
- self.assert_(isinstance(entry, ContentsDirEntry))
- self.assertEqual(str(entry), "//test")
- self.assertEqual(entry.name, "//test")
- elif i == 1:
- self.assert_(isinstance(entry, ContentsFileEntry))
- self.assertEqual(str(entry), "/test/test_file")
- self.assertEqual(entry.name, "/test/test_file")
- elif i == 2:
- self.assert_(isinstance(entry, ContentsSymEntry))
- self.assertEqual(str(entry), "/test/test_link -> /test/test_file")
- self.assertEqual(entry.name, "/test/test_link")
- self.assertEqual(entry.target, "/test/test_file")
- else:
- self.assertEqual("TOO MANY ENTRIES", "OK")
-
- def test_28_config_interface(self):
- self.get_foo()
-
- ci = self.irepo.config_interface
+ def test_14_config_interface(self):
+ ci = irepo.config_interface
self.assert_(isinstance(ci, RepositoryConfigInterface))
- def test_29_licenses_interface(self):
- self.get_foo()
-
- li = self.repo.licenses_interface
+ def test_15_licenses_interface(self):
+ li = repo.licenses_interface
self.assert_(isinstance(li, RepositoryLicensesInterface))
- self.assertEquals(os.path.realpath(li.license_exists("foo")), os.path.join(repo, "licenses/foo"))
+ self.assertEquals(os.path.realpath(li.license_exists("foo")), os.path.join(repo_path, "licenses/foo"))
self.assertEquals(li.license_exists("bad"), None)
- def test_30_portage_interface(self):
- self.get_foo()
-
- pi = self.nce.main_repository.portage_interface
+ def test_16_e_interface(self):
+ ei = nce.main_repository
+ ei = nce.main_repository.e_interface
- self.assert_(isinstance(pi, RepositoryPortageInterface))
+ self.assert_(isinstance(ei, RepositoryEInterface))
path = os.path.join(os.getcwd(), "repository_TEST_dir/testrepo/profiles/testprofile")
- profile = pi.find_profile(path)
+ profile = ei.find_profile(path)
- self.assert_(isinstance(profile, RepositoryPortageInterfaceProfilesDescLine))
+ self.assert_(isinstance(profile, RepositoryEInterfaceProfilesDescLine))
self.assertEquals(profile.path, path)
self.assertEquals(profile.arch, "x86")
self.assertEquals(profile.status, "stable")
- self.assertEquals(pi.find_profile("broken"), None)
+ self.assertEquals(ei.find_profile("broken"), None)
+
+ profile = iter(ei.profiles).next()
+ ei.profile = profile
+
+ self.assertEquals(ei.profile_variable("ARCH"), "test")
+
+class TestCase_03_FakeRepository(unittest.TestCase):
+ def setUp(self):
+ global e, f
+ e = EnvironmentMaker.instance.make_from_spec("")
+ f = FakeRepository(e, "fake")
+
+ def test_01_init(self):
+ pass
+ self.assertEquals(str(f.name), "fake")
+
+ def test_02_init_bad(self):
+ self.assertRaises(Exception, FakeRepository, e)
+ self.assertRaises(Exception, FakeRepository, "foo", "foo")
+
+ def test_03_add_category(self):
+ self.assertEquals(list(f.category_names), [])
+
+ f.add_category("cat-foo")
+ self.assertEquals([str(x) for x in f.category_names], ["cat-foo"])
+ f.add_category("cat-foo")
+ self.assertEquals([str(x) for x in f.category_names], ["cat-foo"])
+ f.add_category("cat-bar")
+ self.assertEquals([str(x) for x in f.category_names], ["cat-bar", "cat-foo"])
- profile = iter(pi.profiles).next()
- pi.profile = profile
+ def test_04_add_category_bad(self):
+ self.assertRaises(Exception, f.add_category, 1)
+ self.assertRaises(Exception, f.add_category, "a", "b")
+
+ def test_05_add_package(self):
+ foo_1 = QualifiedPackageName("cat-foo/pkg1")
+ foo_2 = QualifiedPackageName("cat-foo/pkg2")
+ bar_1 = QualifiedPackageName("cat-bar/pkg1")
+
+ f.add_category("cat-foo")
+ self.assertEquals(list(f.package_names("cat-foo")), [])
+
+ f.add_package(foo_1)
+ self.assertEquals(list(f.package_names("cat-foo")), [foo_1])
+ f.add_package(foo_1)
+ self.assertEquals(list(f.package_names("cat-foo")), [foo_1])
+
+ f.add_package(foo_2)
+ self.assertEquals(list(f.package_names("cat-foo")), [foo_1, foo_2])
+
+ f.add_package(bar_1)
+ self.assertEquals(list(f.package_names("cat-bar")), [bar_1])
+
+ def test_06_add_package_bad(self):
+ self.assertRaises(Exception, f.add_category, 1)
+ self.assertRaises(Exception, f.add_category, "a", "b")
+
+ def test_07_add_version(self):
+ f.add_package("cat-foo/pkg")
+ self.assertEquals(list(f.package_ids("cat-foo/pkg")), [])
+
+ pkg = f.add_version("cat-foo/pkg", "1")
+ self.assertEquals(list(f.package_ids("cat-foo/pkg")), [pkg])
+ self.assertEquals(pkg.version, VersionSpec("1"))
+
+ pkg2 = f.add_version("cat-foo/pkg", "2")
+ self.assertEquals(list(f.package_ids("cat-foo/pkg")), [pkg, pkg2])
+ self.assertEquals(pkg2.version, VersionSpec("2"))
+
+ pkg3 = f.add_version("cat-bar/pkg", "0")
+ self.assertEquals(list(f.package_ids("cat-bar/pkg")), [pkg3])
+
+ self.assertEquals([str(x) for x in f.category_names], ["cat-bar", "cat-foo"])
+
+ def test_08_add_version_bad(self):
+ self.assertRaises(Exception, f.add_version, 1)
+ self.assertRaises(Exception, f.add_version, "a", "b", "c")
- self.assertEquals(pi.profile_variable("ARCH"), "test")
if __name__ == "__main__":
unittest.main()
+
diff --git a/python/repository_TEST_setup.sh b/python/repository_TEST_setup.sh
index 0950a74..72aa76d 100755
--- a/python/repository_TEST_setup.sh
+++ b/python/repository_TEST_setup.sh
@@ -41,6 +41,10 @@ cd testrepo || exit 1
echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
+foo1
+foo2
+foo3
+foo4
END
cat <<END > profiles/profiles.desc || exit 1
@@ -94,6 +98,23 @@ END
touch licenses/foo
+for i in 1 2 3 4; do
+ mkdir -p foo${i}/bar/
+
+cat <<"END" > foo${i}/bar/bar-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI=""
+SLOT="0"
+IUSE="test1"
+LICENSE="GPL-2"
+KEYWORDS="test"
+END
+
+done
+
+
+
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
DESCRIPTION="Test package"
HOMEPAGE="http://paludis.pioto.org/"
diff --git a/python/version_metadata.cc b/python/version_metadata.cc
deleted file mode 100644
index 5adb8cd..0000000
--- a/python/version_metadata.cc
+++ /dev/null
@@ -1,292 +0,0 @@
-/* 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/version_metadata.hh>
-
-using namespace paludis;
-using namespace paludis::python;
-namespace bp = boost::python;
-
-struct VersionMetadataWrapper
-{
- static VersionMetadataEbuildInterface *
- get_ebuild_interface(const VersionMetadata & self)
- {
- return self.ebuild_interface;
- }
-
- static VersionMetadataEbinInterface *
- get_ebin_interface(const VersionMetadata & self)
- {
- return self.ebin_interface;
- }
-
- static VersionMetadataCRANInterface *
- get_cran_interface(const VersionMetadata & self)
- {
- return self.cran_interface;
- }
-
- static VersionMetadataDepsInterface *
- get_deps_interface(const VersionMetadata & self)
- {
- return self.deps_interface;
- }
-
- static VersionMetadataOriginsInterface *
- get_origins_interface(const VersionMetadata & self)
- {
- return self.origins_interface;
- }
-
- static VersionMetadataVirtualInterface *
- get_virtual_interface(const VersionMetadata & self)
- {
- return self.virtual_interface;
- }
-
- static VersionMetadataLicenseInterface *
- get_license_interface(const VersionMetadata & self)
- {
- return self.license_interface;
- }
-};
-
-void PALUDIS_VISIBLE expose_version_metadata()
-{
- /**
- * VersionMetadata
- */
- bp::register_ptr_to_python<tr1::shared_ptr<const VersionMetadata> >();
- bp::class_<VersionMetadata, boost::noncopyable>
- (
- "VersionMetadata",
- "Version metadata.",
- bp::no_init
- )
- .def_readonly("slot", &VersionMetadata::slot,
- "[ro] SlotName"
- )
-
- .def_readonly("homepage", &VersionMetadata::homepage,
- "[ro] DepSpec"
- )
-
- .def_readonly("description", &VersionMetadata::description,
- "[ro] string"
- )
-
- .def_readonly("eapi", &VersionMetadata::eapi,
- "[ro] EAPI"
- )
-
- .add_property("ebuild_interface", bp::make_function(&VersionMetadataWrapper::get_ebuild_interface,
- bp::return_internal_reference<>()),
- "[ro] EbuildInterface"
- )
-
- .add_property("ebin_interface", bp::make_function(&VersionMetadataWrapper::get_ebin_interface,
- bp::return_internal_reference<>()),
- "[ro] EbinInterface"
- )
-
- .add_property("cran_interface", bp::make_function(&VersionMetadataWrapper::get_cran_interface,
- bp::return_internal_reference<>()),
- "[ro] CRANInterface"
- )
-
- .add_property("deps_interface", bp::make_function(&VersionMetadataWrapper::get_deps_interface,
- bp::return_internal_reference<>()),
- "[ro] DepsInterface"
- )
-
- .add_property("origins_interface", bp::make_function(&VersionMetadataWrapper::get_origins_interface,
- bp::return_internal_reference<>()),
- "[ro] OriginsInterface"
- )
-
- .add_property("virtual_interface", bp::make_function(&VersionMetadataWrapper::get_virtual_interface,
- bp::return_internal_reference<>()),
- "[ro] VirtualInterface"
- )
-
- .add_property("license_interface", bp::make_function(&VersionMetadataWrapper::get_license_interface,
- bp::return_internal_reference<>()),
- "[ro] LicenseInterface"
- )
- ;
-
- /**
- * VersionMetadataEbuildInterface
- */
- bp::register_ptr_to_python<VersionMetadataEbuildInterface *>();
- bp::class_<VersionMetadataEbuildInterface, boost::noncopyable>
- (
- "VersionMetadataEbuildInterface",
- "Version metadata for ebuilds.",
- bp::no_init
- )
- .def_readonly("provide", &VersionMetadataEbuildInterface::provide,
- "[ro] DepSpec"
- )
-
- .def_readonly("src_uri", &VersionMetadataEbuildInterface::src_uri,
- "[ro] DepSpec"
- )
-
- .def_readonly("restrictions", &VersionMetadataEbuildInterface::restrictions,
- "[ro] DepSpec"
- )
-
- .def_readonly("keywords", &VersionMetadataEbuildInterface::keywords,
- "[ro] KeywordNameCollection"
- )
-
- .def_readonly("eclass_keywords", &VersionMetadataEbuildInterface::eclass_keywords,
- "[ro] string"
- )
-
- .def_readonly("iuse", &VersionMetadataEbuildInterface::iuse,
- "[ro] IUseFlagCollection"
- )
-
- .def_readonly("inherited", &VersionMetadataEbuildInterface::inherited,
- "[ro] InheritedCollection"
- )
- ;
-
- /**
- * VersionMetadataEbinInterface
- */
- bp::register_ptr_to_python<VersionMetadataEbinInterface *>();
- bp::class_<VersionMetadataEbinInterface, boost::noncopyable>
- (
- "VersionMetadataEbinInterface",
- "Version metadata for Ebins.",
- bp::no_init
- )
- .def_readonly("bin_uri", &VersionMetadataEbinInterface::bin_uri,
- "[ro] DepSpec"
- )
- ;
-
- /**
- * VersionMetadataCRANInterface
- */
- bp::register_ptr_to_python<VersionMetadataCRANInterface *>();
- bp::class_<VersionMetadataCRANInterface, boost::noncopyable>
- (
- "VersionMetadataCRANInterface",
- "Version metadata for CRAN packages.",
- bp::no_init
- )
- .def_readonly("keywords", &VersionMetadataCRANInterface::keywords,
- "[ro] string"
- )
-
- .def_readonly("package", &VersionMetadataCRANInterface::package,
- "[ro] string"
- )
-
- .def_readonly("version", &VersionMetadataCRANInterface::version,
- "[ro] string"
- )
- ;
-
- /**
- * VersionMetadataDepsInterface
- */
- bp::register_ptr_to_python<VersionMetadataDepsInterface *>();
- bp::class_<VersionMetadataDepsInterface, boost::noncopyable>
- (
- "VersionMetadataDepsInterface",
- "Dependency data for VersionMetadata.",
- bp::no_init
- )
- .add_property("build_depend", &VersionMetadataDepsInterface::build_depend,
- "[ro] DepSpec"
- )
-
- .add_property("run_depend", &VersionMetadataDepsInterface::run_depend,
- "[ro] DepSpec"
- )
-
- .add_property("post_depend", &VersionMetadataDepsInterface::post_depend,
- "[ro] DepSpec"
- )
-
- .add_property("suggested_depend", &VersionMetadataDepsInterface::suggested_depend,
- "[ro] DepSpec"
- )
- ;
-
- /**
- * VersionMetadataOriginsInterface
- */
- bp::register_ptr_to_python<VersionMetadataOriginsInterface *>();
- bp::class_<VersionMetadataOriginsInterface, boost::noncopyable>
- (
- "VersionMetadataOriginsInterface",
- "Origins data for VersionMetadata.",
- bp::no_init
- )
- .add_property("source", bp::make_getter(&VersionMetadataOriginsInterface::source,
- bp::return_value_policy<bp::return_by_value>()),
- "[ro] PackageDatabaseEntry"
- )
-
- .add_property("binary", bp::make_getter(&VersionMetadataOriginsInterface::binary,
- bp::return_value_policy<bp::return_by_value>()),
- "[ro] PackageDatabaseEntry"
- )
- ;
-
- /**
- * VersionMetadataCRANInterface
- */
- bp::register_ptr_to_python<VersionMetadataVirtualInterface *>();
- bp::class_<VersionMetadataVirtualInterface, boost::noncopyable>
- (
- "VersionMetadataVirtualInterface",
- "Version metadata for virtual packages.",
- bp::no_init
- )
- .def_readonly("virtual_for", &VersionMetadataVirtualInterface::virtual_for,
- "[ro] PackageDatabaseEntry"
- )
- ;
-
- /**
- * VersionMetadataCRANInterface
- */
- bp::register_ptr_to_python<VersionMetadataLicenseInterface *>();
- bp::class_<VersionMetadataLicenseInterface, boost::noncopyable>
- (
- "VersionMetadataLicenseInterface",
- "License data for VersionMetadata.",
- bp::no_init
- )
- .def_readonly("license", &VersionMetadataLicenseInterface::license,
- "[ro] DepSpec"
- )
- ;
-}
-
diff --git a/python/version_metadata_TEST.py b/python/version_metadata_TEST.py
deleted file mode 100755
index 18c06af..0000000
--- a/python/version_metadata_TEST.py
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/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
-#
-
-import os
-
-repo = os.path.join(os.getcwd(), "version_metadata_TEST_dir/testrepo")
-irepo = os.path.join(os.getcwd(), "version_metadata_TEST_dir/installed")
-
-from paludis import *
-import unittest
-
-Log.instance.log_level = LogLevel.WARNING
-
-#class TestCase_VersionMetadata(unittest.TestCase):
-# e = NoConfigEnvironment(repo)
-# evdb = NoConfigEnvironment(irepo)
-#
-# def vmd(self, version):
-# return self.e.package_database.fetch_repository("testrepo").version_metadata("foo/bar", version)
-#
-# def vmd_vdb(self, package, version):
-# return self.evdb.package_database.fetch_repository("installed").version_metadata(package, version)
-#
-# def test_01_get(self):
-# self.vmd("1.0")
-#
-# def test_02_create_error(self):
-# self.assertRaises(Exception, VersionMetadata)
-#
-# def test_03_data_members(self):
-# vmd = self.vmd("1.0")
-#
-# self.assertEquals(str(vmd.slot), "0")
-# self.assertEquals(str(iter(vmd.homepage).next()), "http://paludis.pioto.org/")
-# self.assertEquals(vmd.description, "Test package")
-# self.assertEquals(vmd.eapi.name, "0")
-#
-# def test_04_ebuild_interface(self):
-# ei = self.vmd("1.0").ebuild_interface
-# ei2 = self.vmd_vdb("cat-one/pkg-one", "1").ebuild_interface
-#
-# self.assert_(isinstance(ei, VersionMetadataEbuildInterface))
-# self.assert_(isinstance(ei2, VersionMetadataEbuildInterface))
-#
-# self.assertEquals(len(list(ei.provide)), 0)
-# self.assertEquals(str(iter(ei.src_uri).next()), "http://example.com/bar-1.0.tar.bz2")
-# self.assertEquals(str(iter(ei.restrictions).next()), "monkey")
-# self.assertEquals(str(iter(ei.keywords).next()), "test")
-# self.assertEquals(len(list(ei.eclass_keywords)), 0)
-# self.assertEquals(len(list(ei.iuse)), 0)
-# self.assertEquals(len(list(ei.inherited)), 0)
-#
-# def test_05_ebin_interface_TODO(self):
-# pass
-#
-# def test_06_cran_interface_TODO(self):
-# pass
-#
-# def test_07_deps_interface(self):
-# di = self.vmd("1.0").deps_interface
-# di2 = self.vmd_vdb("cat-one/pkg-one", "1").deps_interface
-#
-# self.assert_(isinstance(di, VersionMetadataDepsInterface))
-# self.assert_(isinstance(di2, VersionMetadataDepsInterface))
-#
-# self.assert_(isinstance(di.build_depend, AllDepSpec))
-# self.assert_(isinstance(di.run_depend, AllDepSpec))
-# self.assert_(isinstance(di.suggested_depend, AllDepSpec))
-# self.assert_(isinstance(di.post_depend, AllDepSpec))
-#
-# self.assertEquals(str(iter(di.build_depend).next()), "foo/bar")
-# self.assertEquals(len(list(di.run_depend)), 0)
-# self.assertEquals(len(list(di.post_depend)), 0)
-# self.assertEquals(len(list(di.suggested_depend)), 0)
-#
-#
-# def test_08_origins_interface(self):
-# oi = self.vmd_vdb("cat-one/pkg-one", "1").origins_interface
-#
-# self.assert_(isinstance(oi, VersionMetadataOriginsInterface))
-#
-# self.assertEquals(str(oi.source), "cat-one/pkg-one-1::origin_test")
-# self.assertEquals(oi.binary, None)
-#
-# def test_09_virutal_interface_TODO(self):
-# pass
-#
-# def test_10_license_interface(self):
-# li = self.vmd("1.0").license_interface
-# li2 = self.vmd_vdb("cat-one/pkg-one", "1").license_interface
-#
-# self.assert_(isinstance(li, VersionMetadataLicenseInterface))
-# self.assert_(isinstance(li2, VersionMetadataLicenseInterface))
-#
-# self.assertEquals(str(iter(li.license).next()), "GPL-2")
-# self.assertEquals(len(list(li2.license)), 0)
-
-if __name__ == "__main__":
- unittest.main()
-
diff --git a/python/version_metadata_TEST_cleanup.sh b/python/version_metadata_TEST_cleanup.sh
deleted file mode 100755
index c031e3f..0000000
--- a/python/version_metadata_TEST_cleanup.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-# vim: set ft=sh sw=4 sts=4 et :
-
-if [ -d version_metadata_TEST_dir ] ; then
- rm -fr version_metadata_TEST_dir
-else
- true
-fi
diff --git a/python/version_requirements.cc b/python/version_requirements.cc
index a56da09..b0adc9a 100644
--- a/python/version_requirements.cc
+++ b/python/version_requirements.cc
@@ -18,8 +18,10 @@
*/
#include <paludis_python.hh>
-#include <libwrapiter/libwrapiter_forward_iterator.hh>
+
#include <paludis/version_requirements.hh>
+#include <paludis/util/sequence.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
using namespace paludis::python;
@@ -59,7 +61,7 @@ void PALUDIS_VISIBLE expose_version_requirements()
/**
* VersionRequirements
*/
- class_collection<VersionRequirements>
+ class_iterable<VersionRequirements>
(
"VersionRequirements",
"Iterable collection of VersionRequirement instances, usually for a PackageDepSpec."
diff --git a/python/version_spec.cc b/python/version_spec.cc
index 86b23f7..ae1dca7 100644
--- a/python/version_spec.cc
+++ b/python/version_spec.cc
@@ -70,14 +70,4 @@ void PALUDIS_VISIBLE expose_version_spec()
.def(bp::self_ns::str(bp::self))
;
-
- /**
- * VersionSpecCollection
- */
- class_collection<VersionSpecCollection>
- (
- "VersionSpecCollection",
- "Iterable of VersionSpec.\n"
- "Collection of VersionSpec instances."
- );
}