aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-11 20:33:07 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-08-11 20:33:07 +0000
commita4ce4aabe6055fcf4002574c11880402adce1fcb (patch)
tree42003d2dea19db02cc5170b075b00e1067d28459
parentb2a5edd145d8678e5bc5f6ac1270a9b296f09b40 (diff)
downloadpaludis-a4ce4aabe6055fcf4002574c11880402adce1fcb.tar.gz
paludis-a4ce4aabe6055fcf4002574c11880402adce1fcb.tar.xz
(python) Add Masks and fix PackageID.metadata.
-rw-r--r--python/Makefile.am3
-rw-r--r--python/mask.cc222
-rwxr-xr-xpython/mask_TEST.py98
-rwxr-xr-xpython/mask_TEST_cleanup.sh8
-rwxr-xr-xpython/mask_TEST_setup.sh84
-rw-r--r--python/metadata_key.cc156
-rw-r--r--python/metadata_key.hh55
-rw-r--r--python/package_id.cc29
-rwxr-xr-xpython/package_id_TEST.py84
-rwxr-xr-xpython/package_id_TEST_setup.sh19
-rw-r--r--python/paludis_python_so.cc2
11 files changed, 650 insertions, 110 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index c72c4ae..8ca67ba 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -50,7 +50,8 @@ IF_PYTHON_SOURCES = \
environment.cc \
exception.hh exception.cc \
fs_entry.cc \
- metadata_key.cc \
+ mask.cc \
+ metadata_key.hh metadata_key.cc \
name.cc \
log.cc \
package_database.cc \
diff --git a/python/mask.cc b/python/mask.cc
new file mode 100644
index 0000000..c9cd5dd
--- /dev/null
+++ b/python/mask.cc
@@ -0,0 +1,222 @@
+/* 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 <python/metadata_key.hh>
+
+#include <paludis/mask.hh>
+#include <paludis/util/visitor-impl.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+struct MaskToPython :
+ ConstVisitor<MaskVisitorTypes>
+{
+ bp::object value;
+
+ void visit(const UserMask & m)
+ {
+ value = bp::object(bp::ptr(&m));
+ }
+
+ void visit(const UnacceptedMask & m)
+ {
+ value = bp::object(bp::ptr(&m));
+ }
+
+ void visit(const RepositoryMask & m)
+ {
+ value = bp::object(bp::ptr(&m));
+ }
+
+ void visit(const UnsupportedMask & m)
+ {
+ value = bp::object(bp::ptr(&m));
+ }
+
+ void visit(const AssociationMask & m)
+ {
+ value = bp::object(bp::ptr(&m));
+ }
+};
+
+struct mask_to_python
+{
+ static PyObject *
+ convert(const Mask & m)
+ {
+ MaskToPython v;
+ m.accept(v);
+ return bp::incref(v.value.ptr());
+ }
+};
+
+void register_mask_to_python()
+{
+ bp::to_python_converter<Mask, mask_to_python>();
+}
+
+struct UnacceptedMaskWrapper
+{
+ static PyObject *
+ unaccepted_key(const UnacceptedMask & self)
+ {
+ MetadataKeyToPython v;
+ self.unaccepted_key()->accept(v);
+ return bp::incref(v.value.ptr());
+ }
+};
+
+struct RepositoryMaskWrapper
+{
+ static PyObject *
+ mask_key(const RepositoryMask & self)
+ {
+ MetadataKeyToPython v;
+ self.mask_key()->accept(v);
+ return bp::incref(v.value.ptr());
+ }
+};
+
+
+void PALUDIS_VISIBLE expose_mask()
+{
+ /**
+ * RepositoryMaskInfo
+ */
+ class_iterable<Sequence<std::string> >
+ (
+ "StringIterable",
+ "Iterable of string"
+ );
+ register_shared_ptrs_to_python<RepositoryMaskInfo>();
+ bp::class_<RepositoryMaskInfo>
+ (
+ "RepositoryMaskInfo",
+ "Information about a RepositoryMask.",
+ bp::no_init
+ )
+ .add_property("mask_file", bp::make_getter(&RepositoryMaskInfo::mask_file,
+ bp::return_value_policy<bp::return_by_value>()),
+ "[ro] str\n"
+ "NEED_DOC"
+ )
+
+ .add_property("comment", bp::make_getter(&RepositoryMaskInfo::comment,
+ bp::return_value_policy<bp::return_by_value>()),
+ "[ro] Iterable of str\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * Mask
+ */
+ register_mask_to_python();
+ bp::class_<Mask, boost::noncopyable>
+ (
+ "Mask",
+ "NEED_DOC",
+ bp::no_init
+ )
+ .add_property("key", &Mask::key,
+ "[ro] str\n"
+ "NEED_DOC"
+ )
+
+ .add_property("description", &Mask::description,
+ "[ro] str\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * UserMask
+ */
+ bp::class_<UserMask, bp::bases<Mask>, boost::noncopyable>
+ (
+ "UserMask",
+ "NEED_DOC",
+ bp::no_init
+ );
+
+ /**
+ * UnacceptedMask
+ */
+ bp::class_<UnacceptedMask, bp::bases<Mask>, boost::noncopyable>
+ (
+ "UnacceptedMask",
+ "NEED_DOC",
+ bp::no_init
+ )
+ .add_property("unaccepted_key", &UnacceptedMaskWrapper::unaccepted_key,
+ "[ro] MetadataKey\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * RepositoryMask
+ */
+ bp::class_<RepositoryMask, bp::bases<Mask>, boost::noncopyable>
+ (
+ "RepositoryMask",
+ "NEED_DOC",
+ bp::no_init
+ )
+ .add_property("mask_key", &RepositoryMaskWrapper::mask_key,
+ "[ro] MetadataKey\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * UnsupportedMask
+ */
+ bp::class_<UnsupportedMask, bp::bases<Mask>, boost::noncopyable>
+ (
+ "UnsupportedMask",
+ "NEED_DOC",
+ bp::no_init
+ )
+ .add_property("explanation", &UnsupportedMask::explanation,
+ "[ro] str\n"
+ "NEED_DOC"
+ )
+ ;
+
+ /**
+ * AssociationMask
+ */
+ bp::class_<AssociationMask, bp::bases<Mask>, boost::noncopyable>
+ (
+ "AssociationMask",
+ "NEED_DOC",
+ bp::no_init
+ )
+ .add_property("associated_package", &AssociationMask::associated_package,
+ "[ro] PackageID\n"
+ "NEED_DOC"
+ )
+ ;
+}
+
diff --git a/python/mask_TEST.py b/python/mask_TEST.py
new file mode 100755
index 0000000..329216b
--- /dev/null
+++ b/python/mask_TEST.py
@@ -0,0 +1,98 @@
+#!/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
+
+os.environ["PALUDIS_HOME"] = os.path.join(os.getcwd(), "mask_TEST_dir/home")
+
+from paludis import *
+import unittest
+
+Log.instance.log_level = LogLevel.WARNING
+
+class TestCase_01_Masks(unittest.TestCase):
+ def setUp(self):
+ self.e = EnvironmentMaker.instance.make_from_spec("")
+ self.db = self.e.package_database
+
+ def test_01_user_mask(self):
+ q = Query.Matches(PackageDepSpec("=masked/user-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ m = iter(pid.masks).next()
+
+ self.assert_(isinstance(m, Mask))
+ self.assert_(isinstance(m, UserMask))
+
+ self.assertEquals(m.key, "U")
+ self.assertEquals(m.description, "user")
+
+ def test_02_unaccepted_mask(self):
+ q = Query.Matches(PackageDepSpec("=masked/unaccepted-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ m = iter(pid.masks).next()
+
+ self.assert_(isinstance(m, Mask))
+ self.assert_(isinstance(m, UnacceptedMask))
+
+ self.assertEquals(m.key, "K")
+ self.assertEquals(m.description, "keywords")
+ self.assert_(isinstance(m.unaccepted_key, MetadataKeywordNameIterableKey))
+
+ def test_03_repository_mask(self):
+ q = Query.Matches(PackageDepSpec("=masked/repo-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ m = iter(pid.masks).next()
+
+ self.assert_(isinstance(m, Mask))
+ self.assert_(isinstance(m, RepositoryMask))
+
+ self.assertEquals(m.key, "R")
+ self.assertEquals(m.description, "repository")
+
+ package_mask_path = os.path.join(os.getcwd(), "mask_TEST_dir/testrepo/profiles/package.mask")
+ self.assertEquals(m.mask_key.value.mask_file, package_mask_path)
+ self.assert_(isinstance(m.mask_key.value.comment, StringIterable))
+
+ def test_04_unsupported_mask(self):
+ q = Query.Matches(PackageDepSpec("=masked/unsupported-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ m = iter(pid.masks).next()
+
+ self.assert_(isinstance(m, Mask))
+ self.assert_(isinstance(m, UnsupportedMask))
+
+ self.assertEquals(m.key, "E")
+ self.assertEquals(m.description, "eapi")
+ self.assertEquals(m.explanation, "Unsupported EAPI 'unsupported'")
+
+ def test_05_association_mask(self):
+ q = Query.Matches(PackageDepSpec("=virtual/association-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
+ m = iter(pid.masks).next()
+
+ self.assert_(isinstance(m, Mask))
+ self.assert_(isinstance(m, AssociationMask))
+
+ self.assertEquals(m.key, "A")
+ self.assertEquals(m.description, "by association")
+ self.assertEquals(m.associated_package.name, "masked/repo")
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/python/mask_TEST_cleanup.sh b/python/mask_TEST_cleanup.sh
new file mode 100755
index 0000000..067462f
--- /dev/null
+++ b/python/mask_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d mask_TEST_dir ] ; then
+ rm -fr mask_TEST_dir
+else
+ true
+fi
diff --git a/python/mask_TEST_setup.sh b/python/mask_TEST_setup.sh
new file mode 100755
index 0000000..ff53c62
--- /dev/null
+++ b/python/mask_TEST_setup.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir mask_TEST_dir || exit 1
+cd mask_TEST_dir || exit 1
+
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,masked/{user,repo,unaccepted,unsupported}} || exit 1
+
+cd testrepo || exit 1
+echo "testrepo" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+masked
+END
+cat <<END > profiles/profiles.desc
+test testprofile stable
+END
+cat <<END > profiles/package.mask
+masked/repo
+END
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+
+cat <<END > profiles/testprofile/virtuals
+virtual/association masked/repo
+END
+
+cat <<"END" > masked/repo/repo-1.0.ebuild || exit 1
+DESCRIPTION="RepositoryMask"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE=""
+LICENSE=""
+KEYWORDS="test"
+END
+
+cat <<"END" > masked/user/user-1.0.ebuild || exit 1
+DESCRIPTION="UserMask"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE=""
+LICENSE=""
+KEYWORDS="test"
+END
+
+
+cat <<"END" > masked/unaccepted/unaccepted-1.0.ebuild || exit 1
+DESCRIPTION="UnacceptedMask"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE=""
+LICENSE=""
+KEYWORDS="unaccepted"
+END
+
+cat <<"END" > masked/unsupported/unsupported-1.0.ebuild || exit 1
+EAPI="unsupported"
+END
+
+cd ..
+
+mkdir -p home/.paludis/repositories
+
+cat <<END > home/.paludis/repositories/testrepo.conf
+location = `pwd`/testrepo
+format = ebuild
+names_cache = /var/empty
+cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+cat <<END > home/.paludis/package_mask.conf
+masked/user
+END
+
+cat <<END > home/.paludis/keywords.conf
+*/* test
+END
+
diff --git a/python/metadata_key.cc b/python/metadata_key.cc
index c2b9645..3c96955 100644
--- a/python/metadata_key.cc
+++ b/python/metadata_key.cc
@@ -17,16 +17,14 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "metadata_key.hh"
#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;
@@ -66,86 +64,95 @@ struct class_spec_tree_key :
}
};
-struct MetadataKeyToPython :
- ConstVisitor<MetadataKeyVisitorTypes>
+void
+MetadataKeyToPython::visit(const MetadataPackageIDKey & k)
{
- bp::object value;
-
- void visit(const MetadataPackageIDKey & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataStringKey & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataStringKey & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataTimeKey & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataTimeKey & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataContentsKey & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataContentsKey & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataRepositoryMaskInfoKey & k)
- {
- value = bp::object();
- }
+void
+MetadataKeyToPython::visit(const MetadataRepositoryMaskInfoKey & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSetKey<KeywordNameSet> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSetKey<KeywordNameSet> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSetKey<UseFlagNameSet> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSetKey<UseFlagNameSet> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSetKey<IUseFlagSet> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSetKey<IUseFlagSet> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSetKey<InheritedSet> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSetKey<InheritedSet> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSpecTreeKey<RestrictSpecTree> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSpecTreeKey<RestrictSpecTree> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSpecTreeKey<URISpecTree> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
+void
+MetadataKeyToPython::visit(const MetadataSpecTreeKey<URISpecTree> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
- void visit(const MetadataSetKey<PackageIDSequence> & k)
- {
- value = bp::object(bp::ptr(&k));
- }
-};
+void
+MetadataKeyToPython::visit(const MetadataSetKey<PackageIDSequence> & k)
+{
+ value = bp::object(bp::ptr(&k));
+}
struct metadata_key_to_python
{
@@ -254,6 +261,19 @@ void PALUDIS_VISIBLE expose_metadata_key()
;
/**
+ * MetadataRepositoryMaskInfoKey
+ */
+ bp::class_<MetadataRepositoryMaskInfoKey, bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataRepositoryMaskInfoKey",
+ bp::no_init
+ )
+ .add_property("value", &MetadataRepositoryMaskInfoKey::value,
+ "[ro] RepositoryMaskInfo\n"
+ )
+ ;
+
+ /**
* MetadataSetKeys
*/
class_set_key<MetadataSetKey<KeywordNameSet> >("KeywordNameIterable");
diff --git a/python/metadata_key.hh b/python/metadata_key.hh
new file mode 100644
index 0000000..e7d2e2d
--- /dev/null
+++ b/python/metadata_key.hh
@@ -0,0 +1,55 @@
+/* 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
+ */
+
+#ifndef PYTHON_GUARD_PYTHON_METADATA_KEY_HH
+#define PYTHON_GUARD_PYTHON_METADATA_KEY_HH 1
+
+#include <paludis_python.hh>
+
+#include <paludis/metadata_key.hh>
+
+namespace paludis
+{
+ namespace python
+ {
+ struct PALUDIS_VISIBLE MetadataKeyToPython :
+ ConstVisitor<MetadataKeyVisitorTypes>
+ {
+ boost::python::object value;
+
+ void visit(const MetadataPackageIDKey & k);
+ void visit(const MetadataStringKey & k);
+ void visit(const MetadataTimeKey & k);
+ void visit(const MetadataContentsKey & k);
+ void visit(const MetadataRepositoryMaskInfoKey & k);
+ void visit(const MetadataSetKey<KeywordNameSet> & k);
+ void visit(const MetadataSetKey<UseFlagNameSet> & k);
+ void visit(const MetadataSetKey<IUseFlagSet> & k);
+ void visit(const MetadataSetKey<InheritedSet> & k);
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k);
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k);
+ void visit(const MetadataSpecTreeKey<DependencySpecTree> & k);
+ void visit(const MetadataSpecTreeKey<RestrictSpecTree> & k);
+ void visit(const MetadataSpecTreeKey<URISpecTree> & k);
+ void visit(const MetadataSetKey<PackageIDSequence> & k);
+ };
+ }
+}
+
+#endif
diff --git a/python/package_id.cc b/python/package_id.cc
index 4659d49..a936718 100644
--- a/python/package_id.cc
+++ b/python/package_id.cc
@@ -26,6 +26,7 @@
#include <paludis/version_spec.hh>
#include <paludis/action.hh>
#include <paludis/util/sequence.hh>
+#include <paludis/util/iterator.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
using namespace paludis;
@@ -43,6 +44,18 @@ struct PackageIDWrapper
else
return Py_None;
}
+
+ static IndirectIterator<PackageID::MetadataIterator>
+ begin_metadata(const PackageID & self)
+ {
+ return indirect_iterator(self.begin_metadata());
+ }
+
+ static IndirectIterator<PackageID::MetadataIterator>
+ end_metadata(const PackageID & self)
+ {
+ return indirect_iterator(self.end_metadata());
+ }
};
void PALUDIS_VISIBLE expose_package_id()
@@ -92,12 +105,26 @@ void PALUDIS_VISIBLE expose_package_id()
"NEED_DOC"
)
- .def("__iter__", bp::range(&PackageID::begin_metadata, &PackageID::end_metadata))
+ .add_property("metadata", bp::range(&PackageIDWrapper::begin_metadata, &PackageIDWrapper::end_metadata),
+ "[ro] Iterable of MetadataKey\n"
+ "NEED_DOC"
+ )
.def("find_metadata", &PackageIDWrapper::find_metadata,
"find_metadata(string) -> MetadataKey\n"
+ "NEED_DOC"
)
+ .add_property("masked", &PackageID::masked,
+ "[ro] bool\n"
+ "NEED_DOC"
+ )
+
+ .add_property("masks", bp::range(&PackageID::begin_masks, &PackageID::end_masks),
+ "[ro] Iterable of Mask\n"
+ "NEED_DOC"
+ )
+
.def("__eq__", &py_eq<PackageID>)
.def("__ne__", &py_ne<PackageID>)
diff --git a/python/package_id_TEST.py b/python/package_id_TEST.py
index 6bc54b2..711f81e 100755
--- a/python/package_id_TEST.py
+++ b/python/package_id_TEST.py
@@ -30,64 +30,72 @@ 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()
+ self.e = NoConfigEnvironment(repo_path, "/var/empty")
+ self.ie = NoConfigEnvironment(irepo_path)
+ self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
+ self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()
+ self.mpid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("cat/masked")).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"))
+ self.assertEquals(self.pid.name, QualifiedPackageName("foo/bar"))
+ self.assertEquals(self.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"))
+ self.assertEquals(self.pid.version, VersionSpec("1.0"))
+ self.assertEquals(self.ipid.version, VersionSpec("1"))
def test_04_slot(self):
- self.assertEquals(str(ipid.slot), "test_slot")
- self.assertEquals(str(pid.slot), "0")
+ self.assertEquals(str(self.ipid.slot), "test_slot")
+ self.assertEquals(str(self.pid.slot), "0")
def test_05_repository(self):
- self.assertEquals(str(pid.repository.name), "testrepo")
- self.assertEquals(str(ipid.repository.name), "installed")
+ self.assertEquals(str(self.pid.repository.name), "testrepo")
+ self.assertEquals(str(self.ipid.repository.name), "installed")
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(self.pid.canonical_form(PackageIDCanonicalForm.FULL), "foo/bar-1.0::testrepo")
+ self.assertEquals(self.pid.canonical_form(PackageIDCanonicalForm.VERSION), "1.0")
+ self.assertEquals(self.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")
+ self.assertEquals(self.ipid.canonical_form(PackageIDCanonicalForm.FULL), "cat-one/pkg-one-1::installed")
+ self.assertEquals(self.ipid.canonical_form(PackageIDCanonicalForm.VERSION), "1")
+ self.assertEquals(self.ipid.canonical_form(PackageIDCanonicalForm.NO_VERSION), "cat-one/pkg-one::installed")
def test_08_find_metadata(self):
- self.assert_(isinstance(pid.find_metadata("DEPEND"), MetadataDependencySpecTreeKey))
+ self.assert_(isinstance(self.pid.find_metadata("DEPEND"), MetadataDependencySpecTreeKey))
def test_09_perform_action(self):
- pid.perform_action(PretendAction())
- self.assertRaises(UnsupportedActionError, pid.perform_action, ConfigAction())
- self.assertRaises(UnsupportedActionError, ipid.perform_action, PretendAction())
+ self.pid.perform_action(PretendAction())
+ self.assertRaises(UnsupportedActionError, self.pid.perform_action, ConfigAction())
+ self.assertRaises(UnsupportedActionError, self.ipid.perform_action, PretendAction())
def test_10_supports_action(self):
- self.assert_(pid.supports_action(SupportsFetchActionTest()))
- self.assert_(pid.supports_action(SupportsInstallActionTest()))
- self.assert_(pid.supports_action(SupportsFetchActionTest()))
- self.assert_(not pid.supports_action(SupportsUninstallActionTest()))
- self.assert_(not pid.supports_action(SupportsInstalledActionTest()))
- self.assert_(pid.supports_action(SupportsPretendActionTest()))
- self.assert_(not pid.supports_action(SupportsConfigActionTest()))
-
- self.assert_(not ipid.supports_action(SupportsFetchActionTest()))
- self.assert_(not ipid.supports_action(SupportsInstallActionTest()))
- self.assert_(not ipid.supports_action(SupportsFetchActionTest()))
- self.assert_(ipid.supports_action(SupportsUninstallActionTest()))
- self.assert_(ipid.supports_action(SupportsInstalledActionTest()))
- self.assert_(not ipid.supports_action(SupportsPretendActionTest()))
- self.assert_(ipid.supports_action(SupportsConfigActionTest()))
+ self.assert_(self.pid.supports_action(SupportsFetchActionTest()))
+ self.assert_(self.pid.supports_action(SupportsInstallActionTest()))
+ self.assert_(self.pid.supports_action(SupportsFetchActionTest()))
+ self.assert_(not self.pid.supports_action(SupportsUninstallActionTest()))
+ self.assert_(not self.pid.supports_action(SupportsInstalledActionTest()))
+ self.assert_(self.pid.supports_action(SupportsPretendActionTest()))
+ self.assert_(not self.pid.supports_action(SupportsConfigActionTest()))
+
+ self.assert_(not self.ipid.supports_action(SupportsFetchActionTest()))
+ self.assert_(not self.ipid.supports_action(SupportsInstallActionTest()))
+ self.assert_(not self.ipid.supports_action(SupportsFetchActionTest()))
+ self.assert_(self.ipid.supports_action(SupportsUninstallActionTest()))
+ self.assert_(self.ipid.supports_action(SupportsInstalledActionTest()))
+ self.assert_(not self.ipid.supports_action(SupportsPretendActionTest()))
+ self.assert_(self.ipid.supports_action(SupportsConfigActionTest()))
+
+ def test_11_masked(self):
+ self.assert_(not self.pid.masked)
+ self.assert_(self.mpid.masked)
+
+ def test_12_masks(self):
+ mask = iter(self.mpid.masks).next()
+ self.assert_(isinstance(mask, UnacceptedMask))
if __name__ == "__main__":
unittest.main()
diff --git a/python/package_id_TEST_setup.sh b/python/package_id_TEST_setup.sh
index 05efdec..af0967c 100755
--- a/python/package_id_TEST_setup.sh
+++ b/python/package_id_TEST_setup.sh
@@ -4,11 +4,12 @@
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
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar,cat/masked} || exit 1
cd testrepo || exit 1
echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
+cat
END
cat <<END > profiles/profiles.desc
test testprofile stable
@@ -32,9 +33,23 @@ DEPEND="foo/bar"
RDEPEND=""
END
+
+cat <<"END" > cat/masked/masked-1.0.ebuild || exit 1
+DESCRIPTION="Masked package"
+HOMEPAGE="http://paludis.pioto.org/"
+SRC_URI="http://example.com/${P}.tar.bz2"
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="masked"
+RESTRICT=""
+DEPEND=""
+RDEPEND=""
+END
+
cd ..
-mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
+mkdir -p installed/cat-one/pkg-one-1 || exit 1
echo "cat-one" > installed/cat-one/pkg-one-1/CATEGORY
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index f060cb3..be4d429 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -30,6 +30,7 @@ void expose_environment();
void expose_exception();
void expose_fs_entry();
void expose_log();
+void expose_mask();
void expose_metadata_key();
void expose_name();
void expose_package_database();
@@ -61,6 +62,7 @@ BOOST_PYTHON_MODULE(paludis)
expose_query();
expose_environment();
expose_metadata_key();
+ expose_mask();
expose_package_id();
expose_action();
expose_package_database();