aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-03-07 23:36:45 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-03-07 23:36:45 +0000
commit89e8818060814655dbe6804a0b61d9024a75ba12 (patch)
tree3fa426cf95d91c743c96241f0753854d1cf863c8
parent18f8ce9abc51d4d1b4be0240b81a5d840709c1e3 (diff)
downloadpaludis-89e8818060814655dbe6804a0b61d9024a75ba12.tar.gz
paludis-89e8818060814655dbe6804a0b61d9024a75ba12.tar.xz
More ruby work.
-rw-r--r--ruby/environment.cc20
-rw-r--r--ruby/environment_TEST.rb17
-rwxr-xr-xruby/environment_TEST_setup.sh22
-rw-r--r--ruby/repository.cc43
-rw-r--r--ruby/repository_TEST.rb10
5 files changed, 102 insertions, 10 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index df1be23..e3fe96c 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -410,6 +410,25 @@ namespace
}
}
+ /*
+ * call-seq:
+ * master_repository -> PortageRepository
+ *
+ * Return the master repository in this environment
+ */
+ VALUE
+ no_config_environment_master_repository(VALUE self)
+ {
+ try
+ {
+ return repository_to_value(value_to_no_config_environment(self)->master_repository());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
VALUE
environment_maker_make_from_spec(VALUE, VALUE spec)
{
@@ -472,6 +491,7 @@ namespace
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);
+ rb_define_method(c_no_config_environment, "master_repository", RUBY_FUNC_CAST(&no_config_environment_master_repository), 0);
c_environment_maker = rb_define_class_under(paludis_module(), "EnvironmentMaker", rb_cObject);
rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_environment_maker);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index d99f3d5..cc2572f 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -371,6 +371,23 @@ module Paludis
end
end
+ class TestCase_NoConfigEnvirontmentMasterRepository < Test::Unit::TestCase
+ def env
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
+ end
+
+ def env_master
+ NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo",
+ "/var/empty",
+ Dir.getwd().to_s + "/environment_TEST_dir/slaverepo")
+ end
+
+ def test_master_repository
+ assert_nil env.master_repository
+ assert_kind_of PortageRepository, env_master.master_repository
+ end
+ end
+
class TestCase_EnvironmentRoot < Test::Unit::TestCase
def test_root
assert_kind_of String, env.root
diff --git a/ruby/environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index d65b588..f1ce079 100755
--- a/ruby/environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -72,4 +72,26 @@ KEYWORDS="~test"
END
cd ..
+mkdir -p slaverepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+cd slaverepo || exit 1
+echo "slaverepo" > profiles/repo_name || exit 1
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+cat <<END > profiles/profiles.desc
+test testprofile stable
+END
+
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+cat <<END > profiles/profiles.desc
+test testprofile stable
+END
+
+cd ..
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 5d0b92a..1426c4e 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -579,8 +579,8 @@ namespace
{
try
{
- std::tr1::shared_ptr<const PortageRepository> * self_ptr;
- Data_Get_Struct(self, std::tr1::shared_ptr<const PortageRepository>, self_ptr);
+ std::tr1::shared_ptr<PortageRepository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<PortageRepository>, self_ptr);
VALUE result(rb_ary_new());
for (PortageRepository::ProfilesIterator i((*self_ptr)->begin_profiles()),
@@ -607,8 +607,8 @@ namespace
{
try
{
- std::tr1::shared_ptr<const PortageRepository> * self_ptr;
- Data_Get_Struct(self, std::tr1::shared_ptr<const PortageRepository>, self_ptr);
+ std::tr1::shared_ptr<PortageRepository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<PortageRepository>, self_ptr);
PortageRepository::ProfilesIterator p((*self_ptr)->find_profile(FSEntry(StringValuePtr(profile))));
@@ -625,6 +625,28 @@ namespace
/*
* call-seq:
+ * set_profile(portage_repository_profile_desc_line) -> Nil
+ *
+ * Sets the repository profile to the given profile.
+ */
+ VALUE
+ portage_repository_set_profile(VALUE self, VALUE profile)
+ {
+ try
+ {
+ std::tr1::shared_ptr<PortageRepository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<PortageRepository>, self_ptr);
+ (*self_ptr)->set_profile((*self_ptr)->find_profile(value_to_portage_repository_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.
@@ -634,8 +656,8 @@ namespace
{
try
{
- std::tr1::shared_ptr<const PortageRepository> * self_ptr;
- Data_Get_Struct(self, std::tr1::shared_ptr<const PortageRepository>, self_ptr);
+ std::tr1::shared_ptr<PortageRepository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<PortageRepository>, self_ptr);
return rb_str_new2(((*self_ptr)->profile_variable(StringValuePtr(var))).c_str());
}
catch (const std::exception & e)
@@ -964,6 +986,7 @@ namespace
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);
rb_define_method(c_portage_repository, "find_profile", RUBY_FUNC_CAST(&portage_repository_find_profile), 1);
+ rb_define_method(c_portage_repository, "set_profile", RUBY_FUNC_CAST(&portage_repository_set_profile), 1);
rb_define_method(c_portage_repository, "profile_variable", RUBY_FUNC_CAST(&portage_repository_profile_variable), 1);
/*
@@ -1001,9 +1024,11 @@ VALUE repo_to_value(T_ m, VALUE * klass)
VALUE
paludis::ruby::repository_to_value(std::tr1::shared_ptr<Repository> m)
{
- if (0 != dynamic_cast<const PortageRepository *>(m.get()))
- return repo_to_value<std::tr1::shared_ptr<const PortageRepository> >(
- std::tr1::static_pointer_cast<const PortageRepository>(m), &c_portage_repository);
+ if (0 == m)
+ return Qnil;
+ else if (0 != dynamic_cast<PortageRepository *>(m.get()))
+ return repo_to_value<std::tr1::shared_ptr<PortageRepository> >(
+ std::tr1::static_pointer_cast<PortageRepository>(m), &c_portage_repository);
else
return repo_to_value<std::tr1::shared_ptr<Repository> >(m, &c_repository);
}
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index a604bb9..0c3d625 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -48,7 +48,7 @@ module Paludis
def test_responds
repo = no_config_testrepo.portage_repository
- [:profile_variable, :profiles, :find_profile].each do |sym|
+ [:profile_variable, :profiles, :find_profile, :set_profile].each do |sym|
assert_respond_to repo, sym
end
end
@@ -68,6 +68,14 @@ module Paludis
end
end
+ def test_set_profile
+ repo = no_config_testrepo.portage_repository
+ assert_nothing_raised do
+ profile = repo.profiles.first
+ repo.set_profile(profile)
+ end
+ end
+
def test_profile_variable
repo = no_config_testrepo.portage_repository
assert_nothing_raised do