aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-16 01:16:14 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-16 01:16:14 +0000
commit0db602cec77b3ff600428126357e9a40d4f1cedb (patch)
tree5328b48fe038b25c9959f78cd72b4051b9d0c9dd
parentb4b7368f5e80ec7a0878107326636540cbc3c431 (diff)
downloadpaludis-0db602cec77b3ff600428126357e9a40d4f1cedb.tar.gz
paludis-0db602cec77b3ff600428126357e9a40d4f1cedb.tar.xz
Update bindings
-rw-r--r--python/contents.cc64
-rwxr-xr-xpython/contents_TEST.py41
-rw-r--r--ruby/contents.cc107
-rw-r--r--ruby/contents_TEST.rb56
-rw-r--r--ruby/repository_TEST.rb13
5 files changed, 112 insertions, 169 deletions
diff --git a/python/contents.cc b/python/contents.cc
index f1a66f2..c04b170 100644
--- a/python/contents.cc
+++ b/python/contents.cc
@@ -18,7 +18,8 @@
*/
#include <python/paludis_python.hh>
-#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/fs_entry.hh>
#include <paludis/contents.hh>
using namespace paludis;
@@ -55,12 +56,21 @@ void expose_contents()
"Base class for a contents entry.",
bp::no_init
)
- .add_property("name", &ContentsEntry::name,
- "[ro] string\n"
- "Our name."
+
+ .add_property("metadata", bp::range(&ContentsEntry::begin_metadata, &ContentsEntry::end_metadata),
+ "[ro] Iterable of MetadataKey\n"
+ "NEED_DOC"
)
- .def(bp::self_ns::str(bp::self))
+ .def("find_metadata", &ContentsEntry::find_metadata,
+ "find_metadata(string) -> MetadataKey\n"
+ "NEED_DOC"
+ )
+
+ .def("location_key", &ContentsEntry::location_key,
+ "The location_key, which will not be None, provides the path on the filesystem\n"
+ "of the entry. It is not modified for root."
+ )
;
/**
@@ -70,7 +80,7 @@ void expose_contents()
(
"ContentsFileEntry",
"A file contents entry.",
- bp::init<const std::string &>("__init__(name_string)")
+ bp::init<const FSEntry &>("__init__(location)")
);
/**
@@ -80,37 +90,17 @@ void expose_contents()
(
"ContentsDirEntry",
"A directory contents entry.",
- bp::init<const std::string &>("__init__(name_string)")
- );
-
- /**
- * ContentsMiscEntry
- */
- class_contents<ContentsMiscEntry>
- (
- "ContentsMiscEntry",
- "A misc contents entry.",
- bp::init<const std::string &>("__init__(name_string)")
- );
-
- /**
- * ContentsFifoEntry
- */
- class_contents<ContentsFifoEntry>
- (
- "ContentsFifoEntry",
- "A fifo contents entry.",
- bp::init<const std::string &>("__init__(name_string)")
+ bp::init<const FSEntry &>("__init__(location)")
);
/**
- * ContentsDevEntry
+ * ContentsOtherEntry
*/
- class_contents<ContentsDevEntry>
+ class_contents<ContentsOtherEntry>
(
- "ContentsDevEntry",
- "A dev contents entry.",
- bp::init<const std::string &>("__init__(name_string)")
+ "ContentsOtherEntry",
+ "An 'other' contents entry.",
+ bp::init<const FSEntry &>("__init__(location)")
);
/**
@@ -120,14 +110,12 @@ void expose_contents()
(
"ContentsSymEntry",
"A sym contents entry.",
- bp::init<const std::string &, const std::string &>("__init__(name_string, target_string)")
+ bp::init<const FSEntry &, const std::string &>("__init__(location, target_string)")
)
- .add_property("target", &ContentsSymEntry::target,
- "[ro] string\n"
- "Our target (as per readlink)."
- )
- .def(bp::self_ns::str(bp::self))
+ .def("target_key", &ContentsSymEntry::target_key,
+ "The target_key, which will not be None, holds the symlink's target (as per readlink)."
+ )
;
/**
diff --git a/python/contents_TEST.py b/python/contents_TEST.py
index 047255f..6cadb9b 100755
--- a/python/contents_TEST.py
+++ b/python/contents_TEST.py
@@ -29,63 +29,44 @@ class TestCase_Contents(unittest.TestCase):
e = ContentsFileEntry("/foo")
self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo")
- self.assertEquals(e.name, "/foo")
+ self.assertEquals(e.location_key().value(), "/foo")
def test_03_dir_entry(self):
e = ContentsDirEntry("/foo")
self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo")
- self.assertEquals(e.name, "/foo")
+ self.assertEquals(e.location_key().value(), "/foo")
- def test_04_misc_entry(self):
- e = ContentsMiscEntry("/foo")
+ def test_04_other_entry(self):
+ e = ContentsOtherEntry("/foo")
self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo")
- self.assertEquals(e.name, "/foo")
-
- def test_05_fifo_entry(self):
- e = ContentsFifoEntry("/foo")
-
- self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo")
- self.assertEquals(e.name, "/foo")
-
- def test_06_dev_entry(self):
- e = ContentsDevEntry("/foo")
-
- self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo")
- self.assertEquals(e.name, "/foo")
+ self.assertEquals(e.location_key().value(), "/foo")
def test_07_sym_entry(self):
e = ContentsSymEntry("/foo", "/blah")
self.assert_(isinstance(e, ContentsEntry))
- self.assertEquals(str(e), "/foo -> /blah")
- self.assertEquals(e.name, "/foo")
- self.assertEquals(e.target, "/blah")
+ self.assertEquals(e.location_key().value(), "/foo")
+ self.assertEquals(e.target_key().value(), "/blah")
def test_08_contents(self):
entries = []
entries.append(ContentsSymEntry("/foo", "/blah"))
entries.append(ContentsFileEntry("/foo"))
- entries.append(ContentsDevEntry("/dev/foo"))
+ entries.append(ContentsOtherEntry("/dev/foo"))
entries.append(ContentsDirEntry("/bar"))
- entries.append(ContentsFifoEntry("/baz"))
c = Contents()
for entry in entries:
c.add(entry)
for (i, entry) in enumerate(c):
- self.assertEquals(entry.name, entries[i].name)
+ self.assertEquals(entry.location_key().value(), entries[i].location_key().value())
self.assertEquals(type(entry), type(entries[i]))
if i==0:
- self.assertEquals(entry.target, entries[i].target)
- if i>4:
+ self.assertEquals(entry.target_key().value(), entries[i].target_key().value())
+ if i>3:
self.assertEquals("TOO MANY ENTRIES", "OK")
if __name__ == "__main__":
diff --git a/ruby/contents.cc b/ruby/contents.cc
index 15978c5..cd2bb15 100644
--- a/ruby/contents.cc
+++ b/ruby/contents.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2006, 2007 Richard Brown
+ * Copyright (c) 2009 Ciaran McCreesh
*
* 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
@@ -32,9 +33,7 @@ namespace
static VALUE c_contents_file_entry;
static VALUE c_contents_dir_entry;
static VALUE c_contents_sym_entry;
- static VALUE c_contents_misc_entry;
- static VALUE c_contents_dev_entry;
- static VALUE c_contents_fifo_entry;
+ static VALUE c_contents_other_entry;
struct V
{
@@ -58,9 +57,9 @@ namespace
new std::tr1::shared_ptr<const ContentsEntry>(mm));
}
- void visit(const ContentsMiscEntry &)
+ void visit(const ContentsOtherEntry &)
{
- value = Data_Wrap_Struct(c_contents_misc_entry, 0, &Common<std::tr1::shared_ptr<const ContentsEntry> >::free,
+ value = Data_Wrap_Struct(c_contents_other_entry, 0, &Common<std::tr1::shared_ptr<const ContentsEntry> >::free,
new std::tr1::shared_ptr<const ContentsEntry>(mm));
}
@@ -69,18 +68,6 @@ namespace
value = Data_Wrap_Struct(c_contents_sym_entry, 0, &Common<std::tr1::shared_ptr<const ContentsEntry> >::free,
new std::tr1::shared_ptr<const ContentsEntry>(mm));
}
-
- void visit(const ContentsFifoEntry &)
- {
- value = Data_Wrap_Struct(c_contents_fifo_entry, 0, &Common<std::tr1::shared_ptr<const ContentsEntry> >::free,
- new std::tr1::shared_ptr<const ContentsEntry>(mm));
- }
-
- void visit(const ContentsDevEntry &)
- {
- value = Data_Wrap_Struct(c_contents_dev_entry, 0, &Common<std::tr1::shared_ptr<const ContentsEntry> >::free,
- new std::tr1::shared_ptr<const ContentsEntry>(mm));
- }
};
VALUE
@@ -186,7 +173,8 @@ namespace
{
if (1 == argc)
{
- ptr = new std::tr1::shared_ptr<const ContentsEntry>(new A_(StringValuePtr(argv[0])));
+ ptr = new std::tr1::shared_ptr<const ContentsEntry>(new A_(
+ FSEntry(StringValuePtr(argv[0]))));
}
else
{
@@ -211,7 +199,8 @@ namespace
{
if (2 == argc)
{
- ptr = new std::tr1::shared_ptr<const ContentsEntry>(new ContentsSymEntry(StringValuePtr(argv[0]), StringValuePtr(argv[1])));
+ ptr = new std::tr1::shared_ptr<const ContentsEntry>(new ContentsSymEntry(
+ FSEntry(StringValuePtr(argv[0])), StringValuePtr(argv[1])));
}
else
{
@@ -229,26 +218,51 @@ namespace
}
/*
- * Document-method: name
+ * Document-method: location_key
*
- * Returns our name
+ * Returns our location
*/
+ static VALUE
+ contents_entry_location_key(VALUE self)
+ {
+ std::tr1::shared_ptr<const ContentsEntry> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const ContentsEntry>, ptr);
+ return metadata_key_to_value((*ptr)->location_key());
+ }
+
/*
- * Document-method: target
+ * Document-method: target_key
*
- * Returns the target
+ * Returns our target (as per readlink)
*/
- template <typename T_, std::string (T_::* m_) () const>
- struct ContentsThings
+ static VALUE
+ contents_sym_entry_target_key(VALUE self)
{
- static VALUE
- fetch(VALUE self)
+ std::tr1::shared_ptr<const ContentsEntry> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const ContentsEntry>, ptr);
+ return metadata_key_to_value((std::tr1::static_pointer_cast<const ContentsSymEntry>(*ptr))->target_key());
+ }
+
+ /*
+ * call-seq:
+ * each_metadata {|key| block } -> Nil
+ *
+ * Our metadata.
+ */
+ VALUE
+ contents_entry_each_metadata(VALUE self)
+ {
+ std::tr1::shared_ptr<const ContentsEntry> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const ContentsEntry>, self_ptr);
+ for (ContentsEntry::MetadataConstIterator it((*self_ptr)->begin_metadata()),
+ it_end((*self_ptr)->end_metadata()); it_end != it; ++it)
{
- std::tr1::shared_ptr<const ContentsEntry> * ptr;
- Data_Get_Struct(self, std::tr1::shared_ptr<const ContentsEntry>, ptr);
- return rb_str_new2((((*std::tr1::static_pointer_cast<const T_>(*ptr)).*m_)()).c_str());
+ VALUE val(metadata_key_to_value(*it));
+ if (Qnil != val)
+ rb_yield(val);
}
- };
+ return Qnil;
+ }
void do_register_contents()
{
@@ -272,9 +286,9 @@ namespace
*/
c_contents_entry = rb_define_class_under(paludis_module(), "ContentsEntry", rb_cObject);
rb_funcall(c_contents_entry, rb_intern("private_class_method"), 1, rb_str_new2("new"));
- rb_define_method(c_contents_entry, "name", RUBY_FUNC_CAST((&ContentsThings<ContentsEntry,&ContentsEntry::name>::fetch)), 0);
+ rb_define_method(c_contents_entry, "location_key", RUBY_FUNC_CAST(&contents_entry_location_key), 0);
rb_define_method(c_contents_entry, "initialize", RUBY_FUNC_CAST(&contents_entry_init),-1);
- rb_define_method(c_contents_entry, "to_s", RUBY_FUNC_CAST(&Common<std::tr1::shared_ptr<const ContentsEntry> >::to_s_via_ptr), 0);
+ rb_define_method(c_contents_entry, "each_metadata", RUBY_FUNC_CAST(&contents_entry_each_metadata), 0);
/*
* Document-class: Paludis::ContentsFileEntry
@@ -293,39 +307,22 @@ namespace
rb_define_singleton_method(c_contents_dir_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsDirEntry>::contents_entry_new)), -1);
/*
- * Document-class: Paludis::ContentsMiscEntry
+ * Document-class: Paludis::ContentsOtherEntry
*
- * A miscellaneous ContentsEntry
+ * An 'other' ContentsEntry
*/
- c_contents_misc_entry = rb_define_class_under(paludis_module(), "ContentsMiscEntry", c_contents_entry);
- rb_define_singleton_method(c_contents_misc_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsMiscEntry>::contents_entry_new)), -1);
+ c_contents_other_entry = rb_define_class_under(paludis_module(), "ContentsOtherEntry", c_contents_entry);
+ rb_define_singleton_method(c_contents_other_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsOtherEntry>::contents_entry_new)), -1);
/*
- * Document-class: Paludis::ContentsFifoEntry
- *
- * A fifo ContentsEntry
- */
- c_contents_fifo_entry = rb_define_class_under(paludis_module(), "ContentsFifoEntry", c_contents_entry);
- rb_define_singleton_method(c_contents_fifo_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsFifoEntry>::contents_entry_new)), -1);
-
-
- /*
- * Document-class: Paludis::ContentsDevEntry
- *
- * A device ContentsEntry
- */
- c_contents_dev_entry = rb_define_class_under(paludis_module(), "ContentsDevEntry", c_contents_entry);
- rb_define_singleton_method(c_contents_dev_entry, "new", RUBY_FUNC_CAST((&ContentsNew<ContentsDevEntry>::contents_entry_new)), -1);
-
- /*
* Document-class: Paludis::ContentsSymEntry
*
* A symlink ContentsEntry
*/
c_contents_sym_entry = rb_define_class_under(paludis_module(), "ContentsSymEntry", c_contents_entry);
rb_define_singleton_method(c_contents_sym_entry, "new", RUBY_FUNC_CAST(&contents_sym_entry_new), -1);
- rb_define_method(c_contents_sym_entry, "target", RUBY_FUNC_CAST((&ContentsThings<ContentsSymEntry,&ContentsSymEntry::target>::fetch)), 0);
+ rb_define_method(c_contents_sym_entry, "target_key", RUBY_FUNC_CAST(&contents_sym_entry_target_key), 0);
}
}
diff --git a/ruby/contents_TEST.rb b/ruby/contents_TEST.rb
index 2c903fa..d53b5f9 100644
--- a/ruby/contents_TEST.rb
+++ b/ruby/contents_TEST.rb
@@ -54,17 +54,12 @@ module Paludis
def test_respond_to
ce = get_ce
- assert_respond_to ce, :name
+ assert_respond_to ce, :location_key
end
def test_name
ce = get_ce
- assert_equal 'test', ce.name
- end
-
- def test_to_s
- ce = get_ce
- assert_equal 'test', ce.to_s
+ assert_equal 'test', ce.location_key.value
end
end
@@ -93,23 +88,18 @@ module Paludis
def test_respond_to
ce = get_ce
- assert_respond_to ce, :name
+ assert_respond_to ce, :location_key
end
def test_name
ce = get_ce
- assert_equal 'test', ce.name
- end
-
- def test_to_s
- ce = get_ce
- assert_equal 'test', ce.to_s
+ assert_equal 'test', ce.location_key.value
end
end
- class TestCase_ContentsMiscEntry < Test::Unit::TestCase
+ class TestCase_ContentsOtherEntry < Test::Unit::TestCase
def get_ce
- ContentsMiscEntry.new('test')
+ ContentsOtherEntry.new('test')
end
def test_create
@@ -118,31 +108,26 @@ module Paludis
def test_create_error
assert_raise ArgumentError do
- ContentsMiscEntry.new
+ ContentsOtherEntry.new
end
assert_raise ArgumentError do
- ContentsMiscEntry.new('a','b')
+ ContentsOtherEntry.new('a','b')
end
assert_raise TypeError do
- ContentsMiscEntry.new(1)
+ ContentsOtherEntry.new(1)
end
end
def test_respond_to
ce = get_ce
- assert_respond_to ce, :name
+ assert_respond_to ce, :location_key
end
def test_name
ce = get_ce
- assert_equal 'test', ce.name
- end
-
- def test_to_s
- ce = get_ce
- assert_equal 'test', ce.to_s
+ assert_equal 'test', ce.location_key.value
end
end
@@ -179,23 +164,18 @@ module Paludis
def test_respond_to
ce = get_ce
- assert_respond_to ce, :name
- assert_respond_to ce, :target
+ assert_respond_to ce, :location_key
+ assert_respond_to ce, :target_key
end
def test_name
ce = get_ce
- assert_equal 'test_name', ce.name
+ assert_equal 'test_name', ce.location_key.value
end
def test_target
ce = get_ce
- assert_equal 'test_target', ce.target
- end
-
- def test_to_s
- ce = get_ce
- assert_equal "test_name -> test_target", ce.to_s
+ assert_equal 'test_target', ce.target_key.value
end
end
class TestCase_Contents < Test::Unit::TestCase
@@ -236,13 +216,13 @@ module Paludis
c.add(cfe)
assert_equal 1, c.entries.length
- assert_equal cfe.to_s, c.entries.first.to_s
+ assert_equal cfe.location_key.value, c.entries.first.location_key.value
c.add(cse)
assert_equal 2, c.entries.length
- assert_equal cfe.to_s, c.entries.first.to_s
- assert_equal cse.to_s, c.entries.last.to_s
+ assert_equal cfe.location_key.value, c.entries.first.location_key.value
+ assert_equal cse.location_key.value, c.entries.last.location_key.value
end
end
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 848052d..e0e5e5d 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -2,7 +2,7 @@
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+# Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
# Copyright (c) 2006, 2007, 2008 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
@@ -259,23 +259,20 @@ module Paludis
def test_first_entry
assert_kind_of ContentsEntry, entries[0]
assert_kind_of ContentsDirEntry, entries[0]
- assert_equal '//test', entries[0].to_s
- assert_equal '//test', entries[0].name
+ assert_equal '/test', entries[0].location_key.value
end
def test_second_entry
assert_kind_of ContentsEntry, entries[1]
assert_kind_of ContentsFileEntry, entries[1]
- assert_equal '/test/test_file', entries[1].to_s
- assert_equal '/test/test_file', entries[1].name
+ assert_equal '/test/test_file', entries[1].location_key.value
end
def test_third_entry
assert_kind_of ContentsEntry, entries[2]
assert_kind_of ContentsSymEntry, entries[2]
- assert_equal '/test/test_link -> /test/test_file', entries[2].to_s
- assert_equal '/test/test_file', entries[2].target
- assert_equal '/test/test_link', entries[2].name
+ assert_equal '/test/test_file', entries[2].target_key.value
+ assert_equal '/test/test_link', entries[2].location_key.value
end
end