aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-12-18 13:48:14 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-12-18 13:48:14 +0000
commit86ec4c1d61197ed2a7d8c918027dd7ad6c7cb4e5 (patch)
treee0e3d1593cc216e90ebc7acf6ef94c18518c23d6
parent665c7d90e8d9379513d41826f9875547d93fc3b4 (diff)
downloadpaludis-86ec4c1d61197ed2a7d8c918027dd7ad6c7cb4e5.tar.gz
paludis-86ec4c1d61197ed2a7d8c918027dd7ad6c7cb4e5.tar.xz
Update ruby QA binding for PerProfileEbuildCheck.
-rw-r--r--doc/create_ruby_doc.rb3
-rw-r--r--ruby/check.cc155
-rw-r--r--ruby/check_TEST.rb94
-rw-r--r--ruby/demos/qualudis.rb22
-rw-r--r--ruby/environment.cc35
-rw-r--r--ruby/environment_TEST.rb10
-rw-r--r--ruby/paludis_ruby.hh8
-rw-r--r--ruby/qa_environment.cc13
-rw-r--r--ruby/repository.cc113
-rw-r--r--ruby/repository_TEST.rb48
-rwxr-xr-xruby/repository_TEST_setup.sh5
11 files changed, 503 insertions, 3 deletions
diff --git a/doc/create_ruby_doc.rb b/doc/create_ruby_doc.rb
index 74554d9..80d0ad6 100644
--- a/doc/create_ruby_doc.rb
+++ b/doc/create_ruby_doc.rb
@@ -19,6 +19,7 @@ module RDoc
# body.gsub!('c_paludis_module','rb_mPaludis')
body.gsub!('paludis_qa_module()','c_paludis_qa_module')
# body.gsub!('c_paludis_qa_module','rb_mQA')
+ body.gsub!('no_config_environment_class()','c_no_config_environment')
body.gsub!('environment_class()','c_environment')
# body.gsub!('paludis_qa_module()','rb_mQA')
@@ -28,10 +29,12 @@ module RDoc
new_body += "\n" + 'c_paludis_module = rb_define_module("Paludis");' + "\n"
new_body += 'c_paludis_qa_module = rb_define_module_under(c_paludis_module, "QA");' + "\n"
new_body += 'c_environment = rb_define_class_under(c_paludis_module, "Environment", rb_cObject);' + "\n"
+ new_body += 'c_no_config_environment = rb_define_class_under(c_paludis_module, "NoConfigEnvironment", c_environment);' + "\n"
body.each_line do |line|
next if line =~ /rb_mPaludis\s*=/
next if line =~ /rb_mQA\s*=/
next if line =~ /c_environment\s*=/
+ next if line =~ /c_no_config_environment\s*=/
if line =~ /cc_enum_special/
line.scan(/cc_enum_special<([^,]+),\s*([^,]+),\s*([^>]+)>/) do
|header_file, type, in_class|
diff --git a/ruby/check.cc b/ruby/check.cc
index eff3e9d..7922309 100644
--- a/ruby/check.cc
+++ b/ruby/check.cc
@@ -36,12 +36,15 @@ using std::cerr;
namespace
{
static VALUE c_ebuild_check_data;
+ static VALUE c_per_profile_ebuild_check_data;
static VALUE c_package_dir_check;
static VALUE c_package_dir_check_maker;
static VALUE c_file_check;
static VALUE c_file_check_maker;
static VALUE c_ebuild_check;
static VALUE c_ebuild_check_maker;
+ static VALUE c_per_profile_ebuild_check;
+ static VALUE c_per_profile_ebuild_check_maker;
VALUE
ebuild_check_data_init(int, VALUE *, VALUE self)
@@ -84,6 +87,48 @@ namespace
}
}
+ VALUE
+ per_profile_ebuild_check_data_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ /*
+ * call-seq:
+ * new(qualified_package_name, version_spec, environment_data, profile)
+ *
+ * Creates a new PerProfileEbuildCheckData for PerProfileEbuildCheck.
+ */
+ VALUE
+ per_profile_ebuild_check_data_new(int argc, VALUE *argv, VALUE self)
+ {
+ PerProfileEbuildCheckData * ptr(0);
+ try
+ {
+ if (4 == argc)
+ {
+ ptr = new PerProfileEbuildCheckData(
+ value_to_qualified_package_name(argv[0]),
+ value_to_version_spec(argv[1]),
+ value_to_qa_environment(argv[2]),
+ FSEntry(StringValuePtr(argv[3]))
+ );
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "PerProfileEbuildCheckData expects three arguments, but got %d",argc);
+ }
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PerProfileEbuildCheckData>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
/*
* Document-method: describe
*
@@ -194,6 +239,25 @@ namespace
}
/*
+ * call-seq:
+ * check(per_profile_ebuild_check_data) -> CheckResult
+ *
+ * Runs check on PerProfileEbuildCheckData.
+ */
+ VALUE
+ per_profile_ebuild_check_check(VALUE self, VALUE f)
+ {
+ try
+ {
+ return (check_check <PerProfileEbuildCheck::Pointer, PerProfileEbuildCheckData> (self, value_to_per_profile_ebuild_check_data(f)));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
* Document-method: keys
*
* call-seq:
@@ -276,6 +340,25 @@ namespace
}
}
+ /*
+ * call-seq:
+ * find_maker(name)
+ *
+ * Fetch the named check.
+ */
+ VALUE per_profile_ebuild_check_maker_find_maker(VALUE, VALUE maker)
+ {
+ try
+ {
+ PerProfileEbuildCheck::Pointer p = (PerProfileEbuildCheckMaker::get_instance()->find_maker(StringValuePtr(maker)))();
+ return per_profile_ebuild_check_to_value(p);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_check()
{
rb_require("singleton");
@@ -289,6 +372,16 @@ namespace
rb_define_singleton_method(c_ebuild_check_data, "new", RUBY_FUNC_CAST(&ebuild_check_data_new),-1);
rb_define_method(c_ebuild_check_data, "initialize", RUBY_FUNC_CAST(&ebuild_check_data_init),-1);
+
+ /*
+ * Document-class: Paludis::QA::PerProfileEbuildCheckData
+ *
+ * A collection class for PerProfileEbuildCheck.
+ */
+ c_per_profile_ebuild_check_data = rb_define_class_under(paludis_qa_module(), "PerProfileEbuildCheckData", rb_cObject);
+ rb_define_singleton_method(c_per_profile_ebuild_check_data, "new", RUBY_FUNC_CAST(&per_profile_ebuild_check_data_new),-1);
+ rb_define_method(c_per_profile_ebuild_check_data, "initialize", RUBY_FUNC_CAST(&per_profile_ebuild_check_data_init),-1);
+
/*
* Document-class: Paludis::QA::PackageDirCheck
*
@@ -323,6 +416,17 @@ namespace
rb_define_method(c_ebuild_check, "is_important?", RUBY_FUNC_CAST(&CheckStruct<EbuildCheck::Pointer>::is_important),0);
/*
+ * Document-class: Paludis::QA::PerProfileEbuildCheck
+ *
+ * Base class for QA checks that operate upon ebuilds.
+ */
+ c_per_profile_ebuild_check = rb_define_class_under(paludis_qa_module(), "PerProfileEbuildCheck", rb_cObject);
+ rb_funcall(c_per_profile_ebuild_check, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_per_profile_ebuild_check, "check", RUBY_FUNC_CAST(&per_profile_ebuild_check_check),1);
+ rb_define_method(c_per_profile_ebuild_check, "describe", RUBY_FUNC_CAST(&CheckStruct<PerProfileEbuildCheck::Pointer>::describe),0);
+ rb_define_method(c_per_profile_ebuild_check, "is_important?", RUBY_FUNC_CAST(&CheckStruct<PerProfileEbuildCheck::Pointer>::is_important),0);
+
+ /*
* Document-class: Paludis::QA::PackageDirCheckMaker
*
* Class to access PackageDirChecks
@@ -363,6 +467,20 @@ namespace
rb_define_method(c_ebuild_check_maker, "find_maker", RUBY_FUNC_CAST(&ebuild_check_maker_find_maker),1);
rb_define_alias(c_ebuild_check_maker, "check_names", "keys");
rb_define_alias(c_ebuild_check_maker, "find_check", "find_maker");
+
+ /*
+ * Document-class: Paludis::QA::PerProfileEbuildCheckMaker
+ *
+ * Class to access PerProfileEbuildChecks
+ *
+ */
+ c_per_profile_ebuild_check_maker = rb_define_class_under(paludis_qa_module(), "PerProfileEbuildCheckMaker", rb_cObject);
+ rb_funcall(c_per_profile_ebuild_check_maker, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_per_profile_ebuild_check_maker);
+ rb_define_method(c_per_profile_ebuild_check_maker, "keys", RUBY_FUNC_CAST(&CheckMakerStruct<PerProfileEbuildCheckMaker>::keys),0);
+ rb_define_method(c_per_profile_ebuild_check_maker, "find_maker", RUBY_FUNC_CAST(&per_profile_ebuild_check_maker_find_maker),1);
+ rb_define_alias(c_per_profile_ebuild_check_maker, "check_names", "keys");
+ rb_define_alias(c_per_profile_ebuild_check_maker, "find_check", "find_maker");
}
}
@@ -415,12 +533,49 @@ paludis::ruby::ebuild_check_to_value(EbuildCheck::Pointer m)
}
VALUE
+paludis::ruby::per_profile_ebuild_check_to_value(PerProfileEbuildCheck::Pointer m)
+{
+ PerProfileEbuildCheck::Pointer * m_ptr(0);
+ try
+ {
+ m_ptr = new PerProfileEbuildCheck::Pointer(m);
+ return Data_Wrap_Struct(c_per_profile_ebuild_check, 0, &Common<PerProfileEbuildCheck::Pointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+VALUE
paludis::ruby::ebuild_check_data_to_value(const EbuildCheckData & v)
{
EbuildCheckData * vv(new EbuildCheckData(v));
return Data_Wrap_Struct(c_ebuild_check_data, 0, &Common<EbuildCheckData>::free, vv);
}
+PerProfileEbuildCheckData
+paludis::ruby::value_to_per_profile_ebuild_check_data(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_per_profile_ebuild_check_data))
+ {
+ PerProfileEbuildCheckData * v_ptr;
+ Data_Get_Struct(v, PerProfileEbuildCheckData, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into PerProfileEbuildCheckData", rb_obj_classname(v));
+ }
+}
+
+VALUE
+paludis::ruby::per_profile_ebuild_check_data_to_value(const PerProfileEbuildCheckData & v)
+{
+ PerProfileEbuildCheckData * vv(new PerProfileEbuildCheckData(v));
+ return Data_Wrap_Struct(c_per_profile_ebuild_check_data, 0, &Common<PerProfileEbuildCheckData>::free, vv);
+}
EbuildCheckData
paludis::ruby::value_to_ebuild_check_data(VALUE v)
diff --git a/ruby/check_TEST.rb b/ruby/check_TEST.rb
index cdc9f0b..0686c1a 100644
--- a/ruby/check_TEST.rb
+++ b/ruby/check_TEST.rb
@@ -154,6 +154,49 @@ module Paludis
end
end
+ class TestCase_PerProfileEbuildCheckMaker < Test::Unit::TestCase
+ def instance
+ PerProfileEbuildCheckMaker.instance
+ end
+
+ def test_instance
+ assert_equal PerProfileEbuildCheckMaker.instance.__id__, PerProfileEbuildCheckMaker.instance.__id__
+ assert_kind_of PerProfileEbuildCheckMaker, PerProfileEbuildCheckMaker.instance
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = PerProfileEbuildCheckMaker.new()
+ end
+ end
+
+ def test_respond_to
+ assert_respond_to instance, :keys
+ assert_respond_to instance, :find_maker
+ assert_respond_to instance, :check_names
+ assert_respond_to instance, :find_check
+ end
+
+ def test_keys
+ assert_kind_of Array, instance.keys
+ assert_not_equal 0, instance.keys
+ end
+
+ def test_find_maker
+ name = instance.keys.first
+ assert_kind_of PerProfileEbuildCheck, instance.find_maker(name)
+ end
+ def test_check_names
+ assert_kind_of Array, instance.check_names
+ assert_equal instance.keys, instance.check_names
+ end
+
+ def test_find_check
+ name = instance.keys.first
+ assert_equal instance.find_maker(name).describe, instance.find_check(name).describe
+ end
+ end
+
class TestCase_EbuildCheckData < Test::Unit::TestCase
def test_create
env = QAEnvironment.new('check_TEST_dir/repo1')
@@ -161,6 +204,16 @@ module Paludis
end
end
+ class TestCase_EbuildCheckData < Test::Unit::TestCase
+ def test_create
+ env = QAEnvironment.new('check_TEST_dir/repo1')
+ ecd = PerProfileEbuildCheckData.new('cat-one/pkg-one',
+ "1",
+ env,
+ 'check_TEST_dir/repo1/profiles/profile')
+ end
+ end
+
class TestCase_PackageDirCheck < Test::Unit::TestCase
def get_check
PackageDirCheckMaker.instance.find_maker('package_name')
@@ -273,6 +326,47 @@ module Paludis
end
end
end
+
+ class TestCase_PerProfileEbuildCheck < Test::Unit::TestCase
+ def get_ecd
+ env = QAEnvironment.new('check_TEST_dir/repo1')
+ ecd = PerProfileEbuildCheckData.new('cat-one/pkg-one', "1", env, 'check_TEST_dir/repo1/profiles/profile')
+ end
+
+ def get_check
+ PerProfileEbuildCheckMaker.instance.find_maker('deps_visible')
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = PerProfileEbuildCheck.new()
+ end
+ end
+
+ def test_respond_to
+ check = get_check
+ assert_respond_to check, :describe
+ assert_respond_to check, :is_important?
+ assert_respond_to check, :check
+ end
+
+ def test_describe
+ check = get_check
+ assert_equal "Checks that packages in *DEPEND are visible", check.describe
+ end
+
+ def test_is_important
+ check = get_check
+ assert_equal false, check.is_important?
+ end
+
+ def test_check
+ check = get_check
+ assert_nothing_raised do
+ cr = check.check(get_ecd)
+ end
+ end
+ end
end
end
diff --git a/ruby/demos/qualudis.rb b/ruby/demos/qualudis.rb
index 715dcdc..fc360f6 100644
--- a/ruby/demos/qualudis.rb
+++ b/ruby/demos/qualudis.rb
@@ -14,9 +14,9 @@ def need_entry_heading
end
end
-def set_entry_heading(heading)
+def set_entry_heading(heading, local_quiet = false)
@current_heading = heading
- need_entry_heading
+ need_entry_heading unless @quiet || local_quiet
end
def display_header(result)
@@ -125,6 +125,23 @@ def do_check_package_dir(dir, env)
end
end
+ unless fatal
+ Dir["#{dir}/*.ebuild"].each do |d|
+ env.portage_repository.profiles.each do |profile|
+ set_entry_heading("QA checks for package directory #{d} with profile #{profile.path}", true)
+ qpn = QualifiedPackageName.new(File.basename(File.dirname(dir)), File.basename(dir))
+ ver = File.basename(d, '.ebuild').gsub(File.basename(dir) + '-','')
+ ppecd = PerProfileEbuildCheckData.new(qpn, ver, env, profile.path)
+
+ ok, fatal = do_check_kind(PerProfileEbuildCheckMaker.instance, ok, fatal, ppecd)
+
+ break if fatal
+ end
+
+ break if fatal
+ end
+ end
+
if !ok && File.file?("#{dir}/metadata.xml")
puts "metadata.xml"
metadata = MetadataFile.new("#{dir}/metadata.xml")
@@ -289,6 +306,7 @@ opts.each do | opt, arg |
describe_check("Package Directory Checks", PackageDirCheckMaker.instance)
describe_check("File Checks", FileCheckMaker.instance)
describe_check("Ebuild Checks", EbuildCheckMaker.instance)
+ describe_check("Per Profile Ebuild Checks", PerProfileEbuildCheckMaker.instance)
exit 0
when '--qa-check'
diff --git a/ruby/environment.cc b/ruby/environment.cc
index dcd5637..0401f6b 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -312,6 +312,25 @@ namespace
}
}
+ /*
+ * call-seq:
+ * portage_repository -> PortageRepository
+ *
+ * Return the PortageRepository in this environment
+ */
+ VALUE
+ no_config_environment_portage_repository(VALUE self)
+ {
+ try
+ {
+ return portage_repository_to_value(value_to_no_config_environment(self)->portage_repository());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_environment()
{
rb_require("singleton");
@@ -362,9 +381,10 @@ namespace
*
* An environment that uses a single repository, with no user configuration.
*/
- c_no_config_environment = rb_define_class_under(paludis_module(), "NoConfigEnvironment", c_environment);
+ c_no_config_environment = no_config_environment_class();
rb_define_singleton_method(c_no_config_environment, "new", RUBY_FUNC_CAST(&no_config_environment_new), 1);
rb_define_method(c_no_config_environment, "initialize", RUBY_FUNC_CAST(&no_config_environment_init), 1);
+ rb_define_method(c_no_config_environment, "portage_repository", RUBY_FUNC_CAST(&no_config_environment_portage_repository), 0);
}
}
@@ -383,6 +403,19 @@ paludis::ruby::value_to_environment_data(VALUE v)
}
}
+NoConfigEnvironment *
+paludis::ruby::value_to_no_config_environment(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_no_config_environment))
+ {
+ return static_cast<NoConfigEnvironment *>(value_to_environment_data(v)->env_ptr);
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into NoConfigEnvironment", rb_obj_classname(v));
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_environment PALUDIS_ATTRIBUTE((used))
(&do_register_environment);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 75d073c..e2cca4d 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -284,6 +284,16 @@ module Paludis
end
end
+ class TestCase_NoConfigEnvirontmentPortageRepository < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def test_portage_repository
+ assert_kind_of PortageRepository, env.portage_repository
+ end
+ end
+
class TestCase_DefaultConfig < Test::Unit::TestCase
def test_respond_to
assert_respond_to DefaultConfig, :config_suffix
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index c16af59..fde0b97 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -30,6 +30,7 @@
#include <paludis/package_database.hh>
#include <paludis/mask_reasons.hh>
#include <paludis/util/fs_entry.hh>
+#include <paludis/repositories/portage/portage_repository.hh>
#ifdef ENABLE_RUBY_QA
#include <paludis/qa/qa.hh>
@@ -78,12 +79,14 @@ namespace paludis
VALUE package_database_to_value(PackageDatabase::Pointer);
VALUE package_database_entry_to_value(const PackageDatabaseEntry &);
VALUE repository_to_value(Repository::ConstPointer);
+ VALUE portage_repository_to_value(PortageRepository::ConstPointer);
VALUE version_spec_to_value(const VersionSpec &);
VALUE version_metadata_to_value(VersionMetadata::ConstPointer);
VALUE dep_atom_to_value(DepAtom::ConstPointer);
VALUE qualified_package_name_to_value(const QualifiedPackageName &);
VALUE contents_to_value(Contents::ConstPointer);
VALUE contents_entry_to_value(ContentsEntry::ConstPointer);
+ VALUE portage_repository_profiles_desc_line_to_value(const PortageRepositoryProfilesDescLine &);
VersionSpec value_to_version_spec(VALUE v);
VersionMetadata::ConstPointer value_to_version_metadata(VALUE);
@@ -91,16 +94,21 @@ namespace paludis
QualifiedPackageName value_to_qualified_package_name(VALUE v);
PackageDatabaseEntry value_to_package_database_entry(VALUE v);
EnvironmentData* value_to_environment_data(VALUE v);
+ NoConfigEnvironment* value_to_no_config_environment(VALUE v);
#ifdef ENABLE_RUBY_QA
VALUE paludis_qa_module();
qa::Message value_to_message(VALUE v);
qa::EbuildCheckData value_to_ebuild_check_data(VALUE v);
+ qa::PerProfileEbuildCheckData value_to_per_profile_ebuild_check_data(VALUE v);
+ qa::QAEnvironment* value_to_qa_environment(VALUE v);
VALUE ebuild_check_data_to_value(const qa::EbuildCheckData &);
+ VALUE per_profile_ebuild_check_data_to_value(const qa::PerProfileEbuildCheckData &);
VALUE check_result_to_value(const qa::CheckResult &);
VALUE package_dir_check_to_value(qa::PackageDirCheck::Pointer);
VALUE file_check_to_value(qa::FileCheck::Pointer);
VALUE ebuild_check_to_value(qa::EbuildCheck::Pointer);
+ VALUE per_profile_ebuild_check_to_value(qa::PerProfileEbuildCheck::Pointer);
VALUE message_to_value(const qa::Message &);
VALUE metadata_file_to_value(const qa::MetadataFile &);
#endif
diff --git a/ruby/qa_environment.cc b/ruby/qa_environment.cc
index 7b14e6d..54311dc 100644
--- a/ruby/qa_environment.cc
+++ b/ruby/qa_environment.cc
@@ -89,5 +89,18 @@ namespace
}
}
+QAEnvironment*
+paludis::ruby::value_to_qa_environment(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_qa_environment))
+ {
+ return static_cast<QAEnvironment *>(value_to_environment_data(v)->env_ptr);
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into QAEnvironment", rb_obj_classname(v));
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_qa_environment PALUDIS_ATTRIBUTE((used))
(&do_register_qa_environment);
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 49109e4..3f40082 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -19,6 +19,7 @@
#include <paludis_ruby.hh>
#include <paludis/repository.hh>
+#include <paludis/repositories/portage/portage_repository.hh>
#include <paludis/util/stringify.hh>
#include <ruby.h>
@@ -32,6 +33,8 @@ namespace
static VALUE c_repository;
static VALUE c_repository_info;
static VALUE c_repository_info_section;
+ static VALUE c_portage_repository;
+ static VALUE c_portage_repository_profiles_desc_line;
/*
* call-seq:
@@ -401,6 +404,7 @@ namespace
exception_to_ruby_exception(e);
}
}
+
/*
* call-seq:
* kvs -> Hash
@@ -507,6 +511,70 @@ namespace
}
}
+ /*
+ * call-seq:
+ * profiles -> Array
+ *
+ * Fetch an array of our profiles, as PortageRepositoryProfilesDescLine.
+ */
+ VALUE
+ portage_repository_profiles(VALUE self)
+ {
+ try
+ {
+ PortageRepository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, PortageRepository::ConstPointer, self_ptr);
+
+ VALUE result(rb_ary_new());
+ for (PortageRepository::ProfilesIterator i((*self_ptr)->begin_profiles()),
+ i_end((*self_ptr)->end_profiles()) ; i != i_end ; ++i)
+ {
+ rb_ary_push(result, portage_repository_profiles_desc_line_to_value(*i));
+ }
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * Document-method: arch
+ *
+ * call-seq:
+ * arch -> String
+ *
+ * Fetch arch for this PortageRepositoryProfilesDescLine.
+ */
+ /*
+ * Document-method: status
+ *
+ * call-seq:
+ * status -> String
+ *
+ * Fetch status for this PortageRepositoryProfilesDescLine.
+ */
+ /*
+ * Document-method: path
+ *
+ * call-seq:
+ * path -> String
+ *
+ * Fetch path to this PortageRepositoryProfilesDescLine.
+ */
+ template <typename T_, T_ PortageRepositoryProfilesDescLine::* m_>
+ struct DescLineValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ PortageRepositoryProfilesDescLine * ptr;
+ Data_Get_Struct(self, PortageRepositoryProfilesDescLine, ptr);
+ return rb_str_new2(stringify((*ptr).*m_).c_str());
+ }
+ };
+
void do_register_repository()
{
/*
@@ -579,6 +647,28 @@ namespace
rb_funcall(c_repository_info_section, rb_intern("private_class_method"), 1, rb_str_new2("new"));
rb_define_method(c_repository_info_section, "kvs", RUBY_FUNC_CAST(&repository_info_section_kvs), 0);
rb_define_method(c_repository_info_section, "header", RUBY_FUNC_CAST(&repository_info_section_header), 0);
+
+ /*
+ * Document-class: Paludis::PortageRepository
+ *
+ * A PortageRepository is a Repository that handles the layout used by Portage for the main Gentoo tree.
+ */
+ c_portage_repository = rb_define_class_under(paludis_module(), "PortageRepository", c_repository);
+ rb_define_method(c_portage_repository, "profiles", RUBY_FUNC_CAST(&portage_repository_profiles), 0);
+
+ /*
+ * Document-class: Paludis::PortageRepositoryProfilesDescLine
+ *
+ *
+ */
+ c_portage_repository_profiles_desc_line = rb_define_class_under(paludis_module(), "PortageRepositoryProfilesDescLine", rb_cObject);
+ rb_funcall(c_repository_info, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_portage_repository_profiles_desc_line, "path",
+ RUBY_FUNC_CAST((&DescLineValue<FSEntry,&PortageRepositoryProfilesDescLine::path>::fetch)), 0);
+ rb_define_method(c_portage_repository_profiles_desc_line, "arch",
+ RUBY_FUNC_CAST((&DescLineValue<std::string,&PortageRepositoryProfilesDescLine::arch>::fetch)), 0);
+ rb_define_method(c_portage_repository_profiles_desc_line, "status",
+ RUBY_FUNC_CAST((&DescLineValue<std::string,&PortageRepositoryProfilesDescLine::status>::fetch)), 0);
}
}
@@ -598,6 +688,29 @@ paludis::ruby::repository_to_value(Repository::ConstPointer m)
}
}
+VALUE
+paludis::ruby::portage_repository_to_value(PortageRepository::ConstPointer m)
+{
+ PortageRepository::ConstPointer * m_ptr(0);
+ try
+ {
+ m_ptr = new PortageRepository::ConstPointer(m);
+ return Data_Wrap_Struct(c_portage_repository, 0, &Common<PortageRepository::ConstPointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+VALUE
+paludis::ruby::portage_repository_profiles_desc_line_to_value(const PortageRepositoryProfilesDescLine & v)
+{
+ PortageRepositoryProfilesDescLine * vv(new PortageRepositoryProfilesDescLine(v));
+ return Data_Wrap_Struct(c_portage_repository_profiles_desc_line, 0, &Common<PortageRepositoryProfilesDescLine>::free, vv);
+}
+
RegisterRubyClass::Register paludis_ruby_register_repository PALUDIS_ATTRIBUTE((used))
(&do_register_repository);
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 8148ef1..563e4a8 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -34,6 +34,14 @@ module Paludis
end
end
+ class TestCase_PortageRepository < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ p = PortageRepository.new
+ end
+ end
+ end
+
module RepositoryTestCase
def installed_repo
db.fetch_repository "installed"
@@ -46,6 +54,10 @@ module Paludis
def db
DefaultEnvironment.instance.package_database
end
+
+ def no_config_testrepo
+ NoConfigEnvironment.new Dir.getwd().to_s + "/repository_TEST_dir/testrepo"
+ end
end
class TestCase_RepositoryHasVersion < Test::Unit::TestCase
@@ -223,5 +235,41 @@ module Paludis
assert_equal 'vdb', installed_repo.info(false).sections.first.kvs['format']
end
end
+
+ class TestCase_PortageRepositoryProfilesDescLine < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def profiles
+ no_config_testrepo.portage_repository.profiles
+ end
+
+ def test_profiles
+ assert_kind_of Array, profiles
+ assert_equal 1, profiles.length
+ assert_kind_of PortageRepositoryProfilesDescLine, profiles.first
+ end
+
+ def test_respond
+ assert_respond_to profiles.first, :path
+ assert_respond_to profiles.first, :arch
+ assert_respond_to profiles.first, :status
+ end
+
+ def test_profile_path
+ assert_kind_of String, profiles.first.path
+ assert_equal Dir.getwd().to_s + "/repository_TEST_dir/testrepo/profiles/testprofile",
+ profiles.first.path
+ end
+
+ def test_profile_arch
+ assert_kind_of String, profiles.first.arch
+ assert_equal 'x86', profiles.first.arch
+ end
+
+ def test_profile_status
+ assert_kind_of String, profiles.first.status
+ assert_equal 'stable', profiles.first.status
+ end
+ end
end
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index 54a0a7a..8c582ee 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -42,6 +42,11 @@ echo "testrepo" > profiles/repo_name || exit 1
cat <<END > profiles/categories || exit 1
foo
END
+
+cat <<END > profiles/profiles.desc || exit 1
+x86 testprofile stable
+END
+
cat <<END > profiles/testprofile/make.defaults
ARCH=test
USERLAND=test