aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-08-03 15:55:44 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-08-03 15:55:44 +0000
commitf7b523dc3a006d78884cd744344fc88a3cf294c2 (patch)
treef9fe7d8444efb9c22424149855caa26cb9cdf935
parent4cee663f11f28a739e7c8b8b435b4712d32b9a12 (diff)
downloadpaludis-f7b523dc3a006d78884cd744344fc88a3cf294c2.tar.gz
paludis-f7b523dc3a006d78884cd744344fc88a3cf294c2.tar.xz
(ruby) Add interface to arbitrary metadata keys, and RepositoryMaskInfo.
-rw-r--r--paludis/package_id.cc4
-rw-r--r--paludis/package_id.hh2
-rw-r--r--paludis/repositories/gems/gem_specification_TEST.cc2
-rw-r--r--python/package_id.cc2
-rw-r--r--ruby/package_id.cc117
-rw-r--r--ruby/package_id_TEST.rb22
-rwxr-xr-xruby/package_id_TEST_setup.sh5
-rw-r--r--ruby/paludis_ruby.hh2
-rw-r--r--src/output/console_query_task.cc8
9 files changed, 154 insertions, 10 deletions
diff --git a/paludis/package_id.cc b/paludis/package_id.cc
index 2609495..810712d 100644
--- a/paludis/package_id.cc
+++ b/paludis/package_id.cc
@@ -80,14 +80,14 @@ PackageID::MetadataIterator
PackageID::begin_metadata() const
{
need_keys_added();
- return MetadataIterator(indirect_iterator(_imp->keys.begin()));
+ return MetadataIterator(_imp->keys.begin());
}
PackageID::MetadataIterator
PackageID::end_metadata() const
{
need_keys_added();
- return MetadataIterator(indirect_iterator(_imp->keys.end()));
+ return MetadataIterator(_imp->keys.end());
}
void
diff --git a/paludis/package_id.hh b/paludis/package_id.hh
index 7681429..756c834 100644
--- a/paludis/package_id.hh
+++ b/paludis/package_id.hh
@@ -95,7 +95,7 @@ namespace paludis
///\name Finding and iterating over metadata keys
///\{
- typedef libwrapiter::ForwardIterator<PackageID, const MetadataKey> MetadataIterator;
+ typedef libwrapiter::ForwardIterator<PackageID, tr1::shared_ptr<const MetadataKey> > MetadataIterator;
MetadataIterator begin_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
MetadataIterator end_metadata() const PALUDIS_ATTRIBUTE((warn_unused_result));
MetadataIterator find_metadata(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/repositories/gems/gem_specification_TEST.cc b/paludis/repositories/gems/gem_specification_TEST.cc
index 1c373d9..e0fcbf6 100644
--- a/paludis/repositories/gems/gem_specification_TEST.cc
+++ b/paludis/repositories/gems/gem_specification_TEST.cc
@@ -140,7 +140,7 @@ namespace test_cases
TEST_CHECK(spec.find_metadata("authors") != spec.end_metadata());
ExtractValueVisitor v;
- spec.find_metadata("authors")->accept(v);
+ (*spec.find_metadata("authors"))->accept(v);
TEST_CHECK_EQUAL(v.s, "Fred, Barney");
#if 0
diff --git a/python/package_id.cc b/python/package_id.cc
index f3c4e37..4659d49 100644
--- a/python/package_id.cc
+++ b/python/package_id.cc
@@ -39,7 +39,7 @@ struct PackageIDWrapper
{
PackageID::MetadataIterator i(self.find_metadata(key));
if (i != self.end_metadata())
- return bp::incref(bp::object(*i).ptr());
+ return bp::incref(bp::object(**i).ptr());
else
return Py_None;
}
diff --git a/ruby/package_id.cc b/ruby/package_id.cc
index ecf7bda..e5b78c8 100644
--- a/ruby/package_id.cc
+++ b/ruby/package_id.cc
@@ -22,6 +22,7 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/package_id.hh>
#include <paludis/metadata_key.hh>
+#include <paludis/mask.hh>
#include <paludis/util/set.hh>
#include <ruby.h>
@@ -39,12 +40,14 @@ namespace
static VALUE c_metadata_string_key;
static VALUE c_metadata_time_key;
static VALUE c_metadata_contents_key;
+ static VALUE c_metadata_repository_mask_info_key;
static VALUE c_metadata_keyword_name_set_key;
static VALUE c_metadata_use_flag_name_set_key;
static VALUE c_metadata_iuse_flag_set_key;
static VALUE c_metadata_inherited_set_key;
static VALUE c_metadata_package_id_sequence_key;
static VALUE c_metadata_key_type;
+ static VALUE c_repository_mask_info;
struct V :
ConstVisitor<MetadataKeyVisitorTypes>
@@ -83,7 +86,8 @@ namespace
void visit(const MetadataRepositoryMaskInfoKey &)
{
- value = Qnil;
+ value = Data_Wrap_Struct(c_metadata_repository_mask_info_key, 0, &Common<tr1::shared_ptr<const MetadataContentsKey> >::free,
+ new tr1::shared_ptr<const MetadataRepositoryMaskInfoKey>(tr1::static_pointer_cast<const MetadataRepositoryMaskInfoKey>(mm)));
}
void visit(const MetadataSetKey<KeywordNameSet> &)
@@ -203,6 +207,14 @@ namespace
*
* Our human name
*/
+ /*
+ * Document-method: mask_file
+ *
+ * call-seq:
+ * mask_file -> String
+ *
+ * The file that specifies this mask
+ */
template <typename T_, typename S_, const T_ (S_::* m_) () const>
struct BaseValue
{
@@ -244,6 +256,44 @@ namespace
}
/*
+ * call-seq:
+ * [String] -> MetadataKey or Nil
+ *
+ * The named metadata key.
+ */
+ VALUE
+ package_id_subscript(VALUE self, VALUE raw_name)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ PackageID::MetadataIterator it((*self_ptr)->find_metadata(StringValuePtr(raw_name)));
+ if ((*self_ptr)->end_metadata() == it)
+ return Qnil;
+ return metadata_key_to_value(*it);
+ }
+
+ /*
+ * call-seq:
+ * each_metadata {|key| block } -> Nil
+ *
+ * Our metadata.
+ */
+ VALUE
+ package_id_each_metadata(VALUE self)
+ {
+ tr1::shared_ptr<const PackageID> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const PackageID>, self_ptr);
+ for (PackageID::MetadataIterator it((*self_ptr)->begin_metadata()),
+ it_end((*self_ptr)->end_metadata()); it_end != it; ++it)
+ {
+ VALUE val(metadata_key_to_value(*it));
+ if (Qnil != val)
+ rb_yield(val);
+ }
+ return Qnil;
+ }
+
+ /*
* Document-method: keywords_key
*
* call-seq:
@@ -398,6 +448,15 @@ namespace
return Qnil;
}
+ VALUE
+ metadata_repository_mask_info_key_value(VALUE self) {
+ tr1::shared_ptr<const MetadataRepositoryMaskInfoKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataRepositoryMaskInfoKey>, self_ptr);
+ if ((*self_ptr)->value())
+ return repository_mask_info_to_value((*self_ptr)->value());
+ return Qnil;
+ }
+
template <typename T_>
struct SetValue
{
@@ -430,6 +489,26 @@ namespace
}
};
+ VALUE
+ repository_mask_info_mask_file(VALUE self)
+ {
+ tr1::shared_ptr<const RepositoryMaskInfo> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const RepositoryMaskInfo>, ptr);
+ return rb_str_new2(stringify((*ptr)->mask_file).c_str());
+ }
+
+ VALUE
+ repository_mask_info_comment(VALUE self)
+ {
+ tr1::shared_ptr<const RepositoryMaskInfo> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const RepositoryMaskInfo>, ptr);
+ VALUE result(rb_ary_new());
+ for (Sequence<std::string>::Iterator it((*ptr)->comment->begin()),
+ it_end((*ptr)->comment->end()); it_end != it; ++it)
+ rb_ary_push(result, rb_str_new2(it->c_str()));
+ return result;
+ }
+
void do_register_package_id()
{
/*
@@ -445,6 +524,8 @@ namespace
rb_define_method(c_package_id, "slot", RUBY_FUNC_CAST((&BaseValue<SlotName,PackageID,&PackageID::slot>::fetch)), 0);
rb_define_method(c_package_id, "repository_name", RUBY_FUNC_CAST(&package_id_repository_name), 0);
rb_define_method(c_package_id, "==", RUBY_FUNC_CAST(&package_id_equal), 1);
+ rb_define_method(c_package_id, "[]", RUBY_FUNC_CAST(&package_id_subscript), 1);
+ rb_define_method(c_package_id, "each_metadata", RUBY_FUNC_CAST(&package_id_each_metadata), 0);
rb_define_method(c_package_id, "keywords_key", RUBY_FUNC_CAST((&KeyValue<MetadataSetKey<KeywordNameSet>,&PackageID::keywords_key>::fetch)), 0);
rb_define_method(c_package_id, "use_key", RUBY_FUNC_CAST((&KeyValue<MetadataSetKey<UseFlagNameSet>,&PackageID::use_key>::fetch)), 0);
rb_define_method(c_package_id, "iuse_key", RUBY_FUNC_CAST((&KeyValue<MetadataSetKey<IUseFlagSet>,&PackageID::iuse_key>::fetch)), 0);
@@ -512,6 +593,14 @@ namespace
rb_define_method(c_metadata_contents_key, "value", RUBY_FUNC_CAST(&metadata_contents_key_value), 0);
/*
+ * Document-class: Paludis::MetadataRepositoryMaskInfoKey
+ *
+ * Metadata class for RepositoryMaskInfo
+ */
+ c_metadata_repository_mask_info_key = rb_define_class_under(paludis_module(), "MetadataRepositoryMaskInfoKey", c_metadata_key);
+ rb_define_method(c_metadata_repository_mask_info_key, "value", RUBY_FUNC_CAST(&metadata_repository_mask_info_key_value), 0);
+
+ /*
* Document-class: Paludis::MetadataKeywordNameSetKey
*
* Metadata class for Use flag names
@@ -562,6 +651,16 @@ namespace
rb_define_const(c_metadata_key_type, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
// cc_enum_special<paludis/metadata_key-se.hh, MetadataKeyType, c_metadata_key_type>
+
+ /*
+ * Document-class: Paludis::RepositoryMaskInfo
+ *
+ * Information about a RepositoryMask.
+ */
+ c_repository_mask_info = rb_define_class_under(paludis_module(), "RepositoryMaskInfo", rb_cObject);
+ rb_funcall(c_repository_mask_info, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_repository_mask_info, "mask_file", RUBY_FUNC_CAST(&repository_mask_info_mask_file), 0);
+ rb_define_method(c_repository_mask_info, "comment", RUBY_FUNC_CAST(&repository_mask_info_comment), 0);
}
}
@@ -596,6 +695,22 @@ paludis::ruby::value_to_package_id(VALUE v)
}
}
+VALUE
+paludis::ruby::repository_mask_info_to_value(tr1::shared_ptr<const RepositoryMaskInfo> m)
+{
+ tr1::shared_ptr<const RepositoryMaskInfo> * m_ptr(0);
+ try
+ {
+ m_ptr = new tr1::shared_ptr<const RepositoryMaskInfo>(m);
+ return Data_Wrap_Struct(c_repository_mask_info, 0, &Common<tr1::shared_ptr<const RepositoryMaskInfo> >::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_package_id PALUDIS_ATTRIBUTE((used))
(&do_register_package_id);
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 2431faa..e59fdd9 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -122,6 +122,20 @@ module Paludis
def test_=
assert_equal pid_testrepo, pid_testrepo
end
+
+ def test_subscript
+ assert_equal pid_testrepo["DESCRIPTION"].value, "Test package"
+ assert_nil pid_testrepo["PRESCRIPTION"]
+ end
+
+ def test_each_metadata
+ keys = { "DESCRIPTION"=>1, "IUSE"=>1, "INHERITED"=>1, "KEYWORDS"=>1, "EAPI"=>1, "repository_mask"=>1, "profile_mask"=>1 }
+ pid_testrepo.each_metadata do | key |
+ assert keys.has_key?(key.raw_name)
+ keys.delete key.raw_name
+ end
+ assert keys.empty?
+ end
end
class TestCase_ERepo < Test::Unit::TestCase
@@ -197,6 +211,14 @@ module Paludis
#assert_kind_of Array, pid_testrepo.iuse_key.value
#assert_equal ['testflag'], pid_testrepo.iuse_key.value
end
+
+ def test_repository_mask_info_keys
+ assert_kind_of MetadataRepositoryMaskInfoKey, pid_testrepo["repository_mask"]
+ assert_kind_of RepositoryMaskInfo, pid_testrepo["repository_mask"].value
+ assert_equal "package_id_TEST_dir/testrepo/profiles/package.mask", pid_testrepo["repository_mask"].value.mask_file
+ assert_equal ["this is", "a test"], pid_testrepo["repository_mask"].value.comment
+ assert_nil pid_testrepo["profile_mask"].value
+ end
end
class TestCase_VDBRepo < Test::Unit::TestCase
diff --git a/ruby/package_id_TEST_setup.sh b/ruby/package_id_TEST_setup.sh
index 05efdec..9087d21 100755
--- a/ruby/package_id_TEST_setup.sh
+++ b/ruby/package_id_TEST_setup.sh
@@ -18,6 +18,11 @@ ARCH=test
USERLAND=test
KERNEL=test
END
+cat <<END > profiles/package.mask
+# this is
+# a test
+foo/bar
+END
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
DESCRIPTION="Test package"
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index a102795..fb0cc87 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -34,6 +34,7 @@
#include <paludis/repository.hh>
#include <paludis/contents.hh>
#include <paludis/dep_tag.hh>
+#include <paludis/mask-fwd.hh>
#include <paludis/util/stringify.hh>
#ifdef ENABLE_RUBY_QA
@@ -83,6 +84,7 @@ namespace paludis
VALUE dep_tag_to_value(tr1::shared_ptr<const DepTag>);
VALUE qualified_package_name_to_value(const QualifiedPackageName &);
VALUE contents_to_value(tr1::shared_ptr<const Contents>);
+ VALUE repository_mask_info_to_value(tr1::shared_ptr<const RepositoryMaskInfo>);
VersionSpec value_to_version_spec(VALUE v);
tr1::shared_ptr<const PackageID> value_to_package_id(VALUE);
diff --git a/src/output/console_query_task.cc b/src/output/console_query_task.cc
index 488ec09..9f50024 100644
--- a/src/output/console_query_task.cc
+++ b/src/output/console_query_task.cc
@@ -367,21 +367,21 @@ void
ConsoleQueryTask::display_metadata(const PackageDepSpec &, const tr1::shared_ptr<const PackageID> & id) const
{
Displayer ds(this, _imp->env, id, mkt_significant);
- std::for_each(id->begin_metadata(), id->end_metadata(), accept_visitor(ds));
+ std::for_each(indirect_iterator(id->begin_metadata()), indirect_iterator(id->end_metadata()), accept_visitor(ds));
Displayer dn(this, _imp->env, id, mkt_normal);
- std::for_each(id->begin_metadata(), id->end_metadata(), accept_visitor(dn));
+ std::for_each(indirect_iterator(id->begin_metadata()), indirect_iterator(id->end_metadata()), accept_visitor(dn));
if (want_deps() || want_raw())
{
Displayer dd(this, _imp->env, id, mkt_dependencies);
- std::for_each(id->begin_metadata(), id->end_metadata(), accept_visitor(dd));
+ std::for_each(indirect_iterator(id->begin_metadata()), indirect_iterator(id->end_metadata()), accept_visitor(dd));
}
if (want_raw())
{
Displayer dr(this, _imp->env, id, mkt_internal);
- std::for_each(id->begin_metadata(), id->end_metadata(), accept_visitor(dr));
+ std::for_each(indirect_iterator(id->begin_metadata()), indirect_iterator(id->end_metadata()), accept_visitor(dr));
}
}