aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-03-29 21:56:57 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-03-29 21:56:57 +0000
commit1d076a592f297cf35fd7833f74a24f21739f75c4 (patch)
tree3b47541e0b1a7f9f85ffca9cf39b09662f8c382e
parent69ed7ec4664dcb819f082ac73169fbc4b0447542 (diff)
downloadpaludis-1d076a592f297cf35fd7833f74a24f21739f75c4.tar.gz
paludis-1d076a592f297cf35fd7833f74a24f21739f75c4.tar.xz
Ruby PortageRepository -> RepositoryPortageInterface, and query deprecation.
-rw-r--r--ruby/check.cc6
-rw-r--r--ruby/check_TEST.rb2
-rw-r--r--ruby/demos/qualudis.rb4
-rw-r--r--ruby/package_database.cc23
-rw-r--r--ruby/paludis_ruby.hh3
-rw-r--r--ruby/repository.cc211
-rw-r--r--ruby/repository_TEST.rb106
7 files changed, 289 insertions, 66 deletions
diff --git a/ruby/check.cc b/ruby/check.cc
index b735f95..3855bf7 100644
--- a/ruby/check.cc
+++ b/ruby/check.cc
@@ -136,7 +136,6 @@ namespace
return self;
}
-#ifdef CIARANM_NUKED_THIS
/*
* call-seq:
* ProfileCheckData.new(profiles_dir, profiles_desc_line)
@@ -153,7 +152,7 @@ namespace
{
ptr = new ProfileCheckData(
FSEntry(StringValuePtr(argv[0])),
- value_to_portage_repository_profiles_desc_line(argv[1])
+ value_to_profiles_desc_line(argv[1])
);
}
else
@@ -170,7 +169,6 @@ namespace
exception_to_ruby_exception(e);
}
}
-#endif
/*
* Document-method: describe
@@ -506,7 +504,6 @@ namespace
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);
-#ifdef CIARANM_NUKED_THIS
/*
* Document-class: Paludis::QA::ProfileCheckData
*
@@ -515,7 +512,6 @@ namespace
c_profile_check_data = rb_define_class_under(paludis_qa_module(), "ProfileCheckData", rb_cObject);
rb_define_singleton_method(c_profile_check_data, "new", RUBY_FUNC_CAST(&profile_check_data_new),-1);
rb_define_method(c_profile_check_data, "initialize", RUBY_FUNC_CAST(&profile_check_data_init),-1);
-#endif
/*
* Document-class: Paludis::QA::PackageDirCheck
diff --git a/ruby/check_TEST.rb b/ruby/check_TEST.rb
index a6b2fea..b9c735c 100644
--- a/ruby/check_TEST.rb
+++ b/ruby/check_TEST.rb
@@ -21,8 +21,6 @@
require 'test/unit'
require 'Paludis'
-exit 0
-
Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
module Paludis
diff --git a/ruby/demos/qualudis.rb b/ruby/demos/qualudis.rb
index 887f7ed..752d4a9 100644
--- a/ruby/demos/qualudis.rb
+++ b/ruby/demos/qualudis.rb
@@ -135,7 +135,7 @@ def do_check_package_dir(dir, env)
unless fatal
Dir["#{dir}/*.ebuild"].each do |d|
- env.portage_repository.profiles.each do |profile|
+ env.main_repository.profiles.each do |profile|
unless @arches.empty?
next unless @arches.include? profile.arch
end
@@ -225,7 +225,7 @@ def do_check_profiles_dir(dir, env)
ok, fatal = do_check_kind(ProfilesCheckMaker.instance, ok, fatal, dir)
- env.portage_repository.profiles.each do |p|
+ env.main_repository.profiles.each do |p|
break if fatal;
set_entry_heading "QA checks for profile.desc entry #{p.path} #{p.arch} #{p.status}:"
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index a6c9b2e..67880e4 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -103,20 +103,39 @@ namespace
else if (2 == argc || 3 == argc)
{
QueryOrder qo;
- std::tr1::shared_ptr<const PackageDepSpec> pda(value_to_package_dep_spec(argv[0]));
+ Query q = query::Matches(*value_to_package_dep_spec(argv[0]));
InstallState is = static_cast<InstallState>(NUM2INT(argv[1]));
+
+ switch (is)
+ {
+ case is_installed_only:
+ q = q & query::RepositoryHasInstalledInterface();
+ break;
+
+ case is_installable_only:
+ q = q & query::RepositoryHasInstallableInterface();
+ break;
+
+ case is_any:
+ case last_is:
+ ;
+
+ }
if (2 ==argc)
{
qo = qo_order_by_version;
rb_warn("Calling query with (PackageDepSpec, InstallState) has been deprecated");
}
else
+ {
qo = static_cast<QueryOrder>(NUM2INT(argv[2]));
+ rb_warn("Calling query with (PackageDepSpec, InstallState, QUeryOrder) has been deprecated");
+ }
std::tr1::shared_ptr<PackageDatabase> * self_ptr;
Data_Get_Struct(self, std::tr1::shared_ptr<PackageDatabase>, self_ptr);
- items = ((*self_ptr)->query(*pda, is, qo));
+ items = ((*self_ptr)->query(q, qo));
}
else
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index c8e50ee..33b3adb 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -93,7 +93,6 @@ namespace paludis
VALUE qualified_package_name_to_value(const QualifiedPackageName &);
VALUE contents_to_value(std::tr1::shared_ptr<const Contents>);
VALUE contents_entry_to_value(std::tr1::shared_ptr<const ContentsEntry>);
- VALUE portage_repository_profiles_desc_line_to_value(const RepositoryPortageInterface::ProfilesDescLine &);
VALUE dep_tag_to_value(std::tr1::shared_ptr<const DepTag>);
VersionSpec value_to_version_spec(VALUE v);
@@ -104,7 +103,7 @@ namespace paludis
PackageDatabaseEntry value_to_package_database_entry(VALUE v);
EnvironmentData* value_to_environment_data(VALUE v);
NoConfigEnvironment* value_to_no_config_environment(VALUE v);
- RepositoryPortageInterface::ProfilesDescLine value_to_portage_repository_profiles_desc_line(VALUE v);
+ RepositoryPortageInterface::ProfilesDescLine value_to_profiles_desc_line(VALUE v);
MaskReasons value_to_mask_reasons(VALUE v);
Query value_to_query(VALUE v);
std::tr1::shared_ptr<Repository> value_to_repository(VALUE);
diff --git a/ruby/repository.cc b/ruby/repository.cc
index fe6658d..2bb31e4 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -33,6 +33,14 @@ namespace
static VALUE c_repository;
static VALUE c_repository_info;
static VALUE c_repository_info_section;
+ static VALUE c_profiles_desc_line;
+
+ VALUE
+ profiles_desc_line_to_value(const RepositoryPortageInterface::ProfilesDescLine & v)
+ {
+ RepositoryPortageInterface::ProfilesDescLine * vv(new RepositoryPortageInterface::ProfilesDescLine(v));
+ return Data_Wrap_Struct(c_profiles_desc_line, 0, &Common<RepositoryPortageInterface::ProfilesDescLine>::free, vv);
+ }
/*
* call-seq:
@@ -403,6 +411,22 @@ namespace
*
* Returns self if the repository supports the interface, otherwise Nil.
*/
+ /*
+ * Document-method: contents_interface
+ *
+ * call-seq:
+ * contents_interface -> self or Nil
+ *
+ * Returns self if the repository supports the interface, otherwise Nil.
+ */
+ /*
+ * Document-method: portage_interface
+ *
+ * call-seq:
+ * portage_interface -> self or Nil
+ *
+ * Returns self if the repository supports the interface, otherwise Nil.
+ */
template <typename T_, T_ * RepositoryCapabilities::* m_>
struct Interface
{
@@ -756,6 +780,157 @@ namespace
}
}
+ /*
+ * call-seq:
+ * profiles -> Array
+ *
+ * Fetch an array of our profiles, as PortageRepositoryProfilesDescLine.
+ */
+ VALUE
+ repository_profiles(VALUE self)
+ {
+ try
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+ if ((*self_ptr)->portage_interface) {
+ VALUE result(rb_ary_new());
+ for (RepositoryPortageInterface::ProfilesIterator i((*self_ptr)->portage_interface->begin_profiles()),
+ i_end((*self_ptr)->portage_interface->end_profiles()) ; i != i_end ; ++i)
+ {
+ rb_ary_push(result, profiles_desc_line_to_value(*i));
+ }
+ return result;
+ }
+ else
+ {
+ return Qnil;
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * find_profile(profile_location) -> PortageRepositoryProfilesDescLine
+ *
+ * Fetches the named profile.
+ */
+ VALUE
+ repository_find_profile(VALUE self, VALUE profile)
+ {
+ try
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+
+ if ((*self_ptr)->portage_interface)
+ {
+ RepositoryPortageInterface::ProfilesIterator p((*self_ptr)->portage_interface->find_profile(FSEntry(StringValuePtr(profile))));
+
+ if (p == (*self_ptr)->portage_interface->end_profiles())
+ return Qnil;
+
+ return profiles_desc_line_to_value(*p);
+ }
+ else
+ {
+ return Qnil;
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * set_profile(profile) -> Nil
+ *
+ * Sets the repository profile to the given profile.
+ */
+ VALUE
+ repository_set_profile(VALUE self, VALUE profile)
+ {
+ try
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+ if ((*self_ptr)->portage_interface)
+ (*self_ptr)->portage_interface->set_profile(
+ (*self_ptr)->portage_interface->find_profile(
+ value_to_profiles_desc_line(profile).path));
+ return Qnil;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * profile_variable(variable) -> String
+ *
+ * Fetches the named variable.
+ */
+ VALUE
+ repository_profile_variable(VALUE self, VALUE var)
+ {
+ try
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+ if ((*self_ptr)->portage_interface)
+ return rb_str_new2(((*self_ptr)->portage_interface->profile_variable(StringValuePtr(var))).c_str());
+ return Qnil;
+ }
+ 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_ RepositoryPortageInterface::ProfilesDescLine::* m_>
+ struct DescLineValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ RepositoryPortageInterface::ProfilesDescLine * ptr;
+ Data_Get_Struct(self, RepositoryPortageInterface::ProfilesDescLine, ptr);
+ return rb_str_new2(stringify((*ptr).*m_).c_str());
+ }
+ };
+
void do_register_repository()
{
/*
@@ -808,6 +983,8 @@ namespace
&Repository::virtuals_interface>::fetch)), 0);
rb_define_method(c_repository, "contents_interface", RUBY_FUNC_CAST((&Interface<RepositoryContentsInterface,
&Repository::contents_interface>::fetch)), 0);
+ rb_define_method(c_repository, "portage_interface", RUBY_FUNC_CAST((&Interface<RepositoryPortageInterface,
+ &Repository::portage_interface>::fetch)), 0);
rb_define_method(c_repository, "info", RUBY_FUNC_CAST(&repository_info), 1);
rb_define_method(c_repository, "contents", RUBY_FUNC_CAST(&repository_contents), 2);
@@ -822,6 +999,11 @@ namespace
rb_define_method(c_repository, "describe_use_flag", RUBY_FUNC_CAST(&repository_describe_use_flag),-1);
+ rb_define_method(c_repository, "profiles", RUBY_FUNC_CAST(&repository_profiles),0);
+ rb_define_method(c_repository, "find_profile", RUBY_FUNC_CAST(&repository_find_profile),1);
+ rb_define_method(c_repository, "profile_variable", RUBY_FUNC_CAST(&repository_profile_variable),1);
+ rb_define_method(c_repository, "set_profile", RUBY_FUNC_CAST(&repository_set_profile),1);
+
/*
* Document-class: Paludis::RepositoryInfo
*
@@ -840,6 +1022,20 @@ 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::ProfilesDescLine
+ *
+ *
+ */
+ c_profiles_desc_line = rb_define_class_under(paludis_module(), "ProfilesDescLine", rb_cObject);
+ rb_funcall(c_repository_info, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_profiles_desc_line, "path",
+ RUBY_FUNC_CAST((&DescLineValue<FSEntry,&RepositoryPortageInterface::ProfilesDescLine::path>::fetch)), 0);
+ rb_define_method(c_profiles_desc_line, "arch",
+ RUBY_FUNC_CAST((&DescLineValue<std::string,&RepositoryPortageInterface::ProfilesDescLine::arch>::fetch)), 0);
+ rb_define_method(c_profiles_desc_line, "status",
+ RUBY_FUNC_CAST((&DescLineValue<std::string,&RepositoryPortageInterface::ProfilesDescLine::status>::fetch)), 0);
}
}
@@ -883,6 +1079,21 @@ paludis::ruby::value_to_repository(VALUE v)
}
}
+RepositoryPortageInterface::ProfilesDescLine
+paludis::ruby::value_to_profiles_desc_line(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_profiles_desc_line))
+ {
+ RepositoryPortageInterface::ProfilesDescLine * v_ptr;
+ Data_Get_Struct(v, RepositoryPortageInterface::ProfilesDescLine, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into ProfilesDescLine", rb_obj_classname(v));
+ }
+}
+
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 1735d48..0dc3f74 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -19,8 +19,6 @@
# Place, Suite 330, Boston, MA 02111-1307 USA
#
-exit 0
-
ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/repository_TEST_dir/home";
require 'test/unit'
@@ -37,55 +35,6 @@ module Paludis
end
end
- class TestCase_PortageRepository < Test::Unit::TestCase
- def no_config_testrepo
- NoConfigEnvironment.new Dir.getwd().to_s + "/repository_TEST_dir/testrepo"
- end
-
- def test_no_create
- assert_raise NoMethodError do
- p = PortageRepository.new
- end
- end
-
- def test_responds
- repo = no_config_testrepo.main_repository
- [:profile_variable, :profiles, :find_profile, :set_profile].each do |sym|
- assert_respond_to repo, sym
- end
- end
-
- def test_profiles
- repo = no_config_testrepo.main_repository
- assert_kind_of Array, repo.profiles
- end
-
- def test_find_profile
- repo = no_config_testrepo.main_repository
- assert_nothing_raised do
- profile = repo.find_profile(Dir.getwd().to_s + '/repository_TEST_dir/testrepo/profiles/testprofile')
- assert_kind_of PortageRepositoryProfilesDescLine, profile
- profile = repo.find_profile('broken')
- assert profile.nil?
- end
- end
-
- def test_set_profile
- repo = no_config_testrepo.main_repository
- assert_nothing_raised do
- profile = repo.profiles.first
- repo.set_profile(profile)
- end
- end
-
- def test_profile_variable
- repo = no_config_testrepo.main_repository
- assert_nothing_raised do
- assert_equal 'test', repo.profile_variable('ARCH')
- end
- end
- end
-
module RepositoryTestCase
def installed_repo
db.fetch_repository "installed"
@@ -237,6 +186,16 @@ module Paludis
class TestCase_RepositoryInterfaces < Test::Unit::TestCase
include RepositoryTestCase
+ def test_responds
+ repo = no_config_testrepo.main_repository
+ [:installable_interface, :installed_interface, :mask_interface, :news_interface,
+ :sets_interface, :syncable_interface, :uninstallable_interface, :use_interface,
+ :world_interface, :mirrors_interface, :environment_variable_interface,
+ :provides_interface, :virtuals_interface, :contents_interface, :portage_interface].each do |sym|
+ assert_respond_to repo, sym
+ end
+ end
+
def test_interfaces
assert_equal repo.name, repo.installable_interface.name
assert_nil repo.installed_interface
@@ -501,7 +460,48 @@ module Paludis
end
end
- class TestCase_PortageRepositoryProfilesDescLine < Test::Unit::TestCase
+ class TestCase_RepositoryPortageInterface < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_responds
+ repo = no_config_testrepo.main_repository
+ [:profile_variable, :profiles, :find_profile, :set_profile].each do |sym|
+ assert_respond_to repo, sym
+ end
+ end
+
+ def test_profiles
+ repo = no_config_testrepo.main_repository
+ assert_kind_of Array, repo.profiles
+ end
+
+ def test_find_profile
+ repo = no_config_testrepo.main_repository
+ assert_nothing_raised do
+ profile = repo.find_profile(Dir.getwd().to_s + '/repository_TEST_dir/testrepo/profiles/testprofile')
+ assert_kind_of ProfilesDescLine, profile
+ profile = repo.find_profile('broken')
+ assert profile.nil?
+ end
+ end
+
+ def test_set_profile
+ repo = no_config_testrepo.main_repository
+ assert_nothing_raised do
+ profile = repo.profiles.first
+ repo.set_profile(profile)
+ end
+ end
+
+ def test_profile_variable
+ repo = no_config_testrepo.main_repository
+ assert_nothing_raised do
+ assert_equal 'test', repo.profile_variable('ARCH')
+ end
+ end
+ end
+
+ class TestCase_ProfilesDescLine < Test::Unit::TestCase
include RepositoryTestCase
def profiles
@@ -511,7 +511,7 @@ module Paludis
def test_profiles
assert_kind_of Array, profiles
assert_equal 1, profiles.length
- assert_kind_of PortageRepositoryProfilesDescLine, profiles.first
+ assert_kind_of ProfilesDescLine, profiles.first
end
def test_respond