aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-05 12:25:42 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-05 01:33:54 +0000
commita0a35b8d0dd4ca00c91350e3d3acf1bc6208cad1 (patch)
tree83a8c5994577da21ed70242add8e4cf041ee554c /python
parent23d144895a2c80a2f3ff6cd7aa9d94705394ca04 (diff)
downloadpaludis-a0a35b8d0dd4ca00c91350e3d3acf1bc6208cad1.tar.gz
paludis-a0a35b8d0dd4ca00c91350e3d3acf1bc6208cad1.tar.xz
Make slot a metadata key.
Fixes: ticket:450
Diffstat (limited to 'python')
-rw-r--r--python/metadata_key.cc75
-rw-r--r--python/package_id.cc8
-rwxr-xr-xpython/package_id_TEST.py12
3 files changed, 85 insertions, 10 deletions
diff --git a/python/metadata_key.cc b/python/metadata_key.cc
index 8cdee8435..c3c83bdfb 100644
--- a/python/metadata_key.cc
+++ b/python/metadata_key.cc
@@ -57,6 +57,11 @@ class MetadataKeySptrToPythonVisitor
obj = bp::object(std::tr1::static_pointer_cast<const MetadataValueKey<std::string> >(_m_ptr));
}
+ void visit(const MetadataValueKey<SlotName> & k)
+ {
+ obj = bp::object(std::tr1::static_pointer_cast<const MetadataValueKey<SlotName> >(_m_ptr));
+ }
+
void visit(const MetadataValueKey<long> & k)
{
obj = bp::object(std::tr1::static_pointer_cast<const MetadataValueKey<long> >(_m_ptr));
@@ -271,6 +276,52 @@ struct MetadataStringKeyWrapper :
}
};
+struct MetadataSlotNameKeyWrapper :
+ MetadataValueKey<SlotName> ,
+ bp::wrapper<MetadataValueKey<SlotName> >
+{
+ virtual const SlotName value() const
+ PALUDIS_ATTRIBUTE((warn_unused_result))
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = get_override("value"))
+ return f();
+ else
+ throw PythonMethodNotImplemented("MetadataSlotNameKey", "value");
+ }
+
+ virtual const std::string raw_name() const
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = get_override("raw_name"))
+ return f();
+ else
+ throw PythonMethodNotImplemented("MetadataSlotNameKey", "raw_name");
+ }
+
+ virtual const std::string human_name() const
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = get_override("human_name"))
+ return f();
+ else
+ throw PythonMethodNotImplemented("MetadataSlotNameKey", "human_name");
+ }
+
+ virtual MetadataKeyType type() const
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = get_override("type"))
+ return f();
+ else
+ throw PythonMethodNotImplemented("MetadataSlotNameKey", "type");
+ }
+};
+
struct MetadataSectionKeyWrapper :
MetadataSectionKey,
bp::wrapper<MetadataSectionKey>
@@ -1131,6 +1182,30 @@ void expose_metadata_key()
;
/**
+ * MetadataSlotNameKey
+ */
+ bp::register_ptr_to_python<std::tr1::shared_ptr<const MetadataValueKey<SlotName> > >();
+ bp::implicitly_convertible<std::tr1::shared_ptr<MetadataSlotNameKeyWrapper>,
+ std::tr1::shared_ptr<MetadataKey> >();
+ bp::class_<MetadataSlotNameKeyWrapper, std::tr1::shared_ptr<MetadataSlotNameKeyWrapper>,
+ bp::bases<MetadataKey>, boost::noncopyable>
+ (
+ "MetadataSlotNameKey",
+ "A MetadataStringKey is a MetadataKey that has a SlotName as its\n"
+ "value.\n\n"
+
+ "This class can be subclassed in Python.",
+ bp::init<>(
+ "__init__()"
+ )
+ )
+ .def("value", bp::pure_virtual(&MetadataValueKey<SlotName> ::value),
+ "value() -> SlotName\n"
+ "Fetch our value."
+ )
+ ;
+
+ /**
* MetadataSectionKey
*/
bp::register_ptr_to_python<std::tr1::shared_ptr<const MetadataSectionKey> >();
diff --git a/python/package_id.cc b/python/package_id.cc
index 9f212136f..2bc58862c 100644
--- a/python/package_id.cc
+++ b/python/package_id.cc
@@ -74,10 +74,6 @@ void expose_package_id()
"[ro] VersionSpec\n"
)
- .add_property("slot", &PackageID::slot,
- "[ro] SlotName\n"
- )
-
.add_property("repository", &PackageID::repository,
"[ro] Repository\n"
)
@@ -202,6 +198,10 @@ void expose_package_id()
"best describes the location of a PackageID."
)
+ .def("slot_key", &PackageID::slot_key,
+ "The slot_key, if not None, indicates the package's slot."
+ )
+
.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 16f73c9ed..1e243fa32 100755
--- a/python/package_id_TEST.py
+++ b/python/package_id_TEST.py
@@ -50,8 +50,8 @@ class TestCase_01_PackageID(unittest.TestCase):
self.assertEquals(self.ipid.version, VersionSpec("1"))
def test_04_slot(self):
- self.assertEquals(str(self.ipid.slot), "test_slot")
- self.assertEquals(str(self.pid.slot), "0")
+ self.assertEquals(str(self.ipid.slot_key().value()), "test_slot")
+ self.assertEquals(str(self.pid.slot_key().value()), "0")
def test_05_repository(self):
self.assertEquals(str(self.pid.repository.name), "testrepo")
@@ -59,8 +59,8 @@ class TestCase_01_PackageID(unittest.TestCase):
def test_07_canonical_form(self):
# Load the metadata
- self.pid.slot
- self.ipid.slot
+ self.pid.slot_key().value
+ self.ipid.slot_key().value
self.assertEquals(self.pid.canonical_form(PackageIDCanonicalForm.FULL), "foo/bar-1.0:0::testrepo")
self.assertEquals(self.pid.canonical_form(PackageIDCanonicalForm.VERSION), "1.0")
@@ -74,8 +74,8 @@ class TestCase_01_PackageID(unittest.TestCase):
def test_08_str(self):
# Load the metadata
- self.pid.slot
- self.ipid.slot
+ self.pid.slot_key().value
+ self.ipid.slot_key().value
self.assertEquals(str(self.pid), "foo/bar-1.0:0::testrepo")
self.assertEquals(str(self.ipid), "cat-one/pkg-one-1:test_slot::installed")