aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2008-05-17 14:58:07 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2008-05-17 14:58:07 +0000
commitf3b0917abaf1406d82f2b3f13629323be092cbd1 (patch)
tree599828924ddc2d564b83eb57085d4ac7723cf801
parent9a269bbb0d26e39ffaf2fc6fc6769a43d04d3ed2 (diff)
downloadpaludis-f3b0917abaf1406d82f2b3f13629323be092cbd1.tar.gz
paludis-f3b0917abaf1406d82f2b3f13629323be092cbd1.tar.xz
Add mirrors to Environment and Repository.
-rw-r--r--ruby/environment.cc27
-rw-r--r--ruby/environment_TEST.rb26
-rwxr-xr-xruby/environment_TEST_setup.sh5
-rw-r--r--ruby/repository.cc42
-rw-r--r--ruby/repository_TEST.rb22
-rwxr-xr-xruby/repository_TEST_setup.sh4
6 files changed, 123 insertions, 3 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index 7a7d9b1..d5ba4fd 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
- * Copyright (c) 2007 Richard Brown
+ * Copyright (c) 2007, 2008 Richard Brown
*
* 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
@@ -25,6 +25,7 @@
#include <paludis/environment_maker.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
#include <ruby.h>
using namespace paludis;
@@ -170,6 +171,29 @@ namespace
/*
* call-seq:
+ * mirrors(mirror_name) -> Array
+ *
+ * Return the mirror URI prefixes for a named mirror.
+ */
+ VALUE
+ environment_mirrors(VALUE self, VALUE mirror)
+ {
+ try
+ {
+ VALUE result(rb_ary_new());
+ std::tr1::shared_ptr<const MirrorsSequence> m(value_to_environment(self)->mirrors(StringValuePtr(mirror)));
+ for (MirrorsSequence::ConstIterator i(m->begin()), i_end(m->end()) ; i != i_end ; i++)
+ rb_ary_push(result, rb_str_new2(stringify(*i).c_str()));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* root -> String
*
* Default root location, default is /.
@@ -498,6 +522,7 @@ namespace
rb_define_method(c_environment, "default_destinations", RUBY_FUNC_CAST(&environment_default_destinations), 0);
rb_define_method(c_environment, "accept_license", RUBY_FUNC_CAST(&environment_accept_license), 2);
rb_define_method(c_environment, "accept_keywords", RUBY_FUNC_CAST(&environment_accept_keywords), 2);
+ rb_define_method(c_environment, "mirrors", RUBY_FUNC_CAST(&environment_mirrors), 1);
/*
* Document-class: Paludis::PaludisEnvironment
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 211015d..e77d464 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -3,7 +3,7 @@
#
# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
-# Copyright (c) 2007 Richard Brown
+# Copyright (c) 2007, 2008 Richard Brown
#
# 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
@@ -378,5 +378,29 @@ module Paludis
end
end
end
+
+ class TestCase_EnvironmentMirrors < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def test_respond_and_return
+ assert_respond_to env, :mirrors
+ assert_kind_of Array, env.mirrors('')
+ end
+
+
+ def test_mirrors_star
+ assert_equal ['http://a', 'http://b'], env.mirrors('*')
+ end
+
+ def test_named_mirror
+ assert_equal ['http://c'], env.mirrors('testmirror')
+ end
+
+ def test_empty_mirror
+ assert env.mirrors('missingmirror').empty?
+ end
+ end
end
diff --git a/ruby/environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index 12c0f5d..ed968f9 100755
--- a/ruby/environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -37,6 +37,11 @@ foo/bar GPL-2
foo/baz *
END
+cat <<END > home/.paludis/mirrors.conf
+* http://a http://b
+testmirror http://c
+END
+
cat <<END > home/.paludis/environment.conf
world = /dev/null
END
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 5edfd2f..eb2ba9e 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
- * Copyright (c) 2006, 2007, 2008 Richard Brown
+ * Copyright (c) 2006, 2007, 2008 Richard Brown
* Copyright (c) 2007 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -897,6 +897,43 @@ namespace
return Qnil;
}
+ /*
+ * call-seq:
+ * is_mirror?(mirror_name) -> true or false
+ *
+ * Is the named item a mirror?
+ */
+ VALUE
+ repository_is_mirror(VALUE self, VALUE mirror)
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+ if ((**self_ptr)[k::mirrors_interface()])
+ return (**self_ptr)[k::mirrors_interface()]->is_mirror(StringValuePtr(mirror)) ? Qtrue : Qfalse;
+ return Qnil;
+ }
+
+ /*
+ * call-seq:
+ * mirrors(mirror_name) -> Array
+ *
+ * Return the mirror URI prefixes for a named mirror.
+ */
+ VALUE
+ repository_mirrors(VALUE self, VALUE mirror)
+ {
+ std::tr1::shared_ptr<Repository> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<Repository>, self_ptr);
+ if (!(**self_ptr)[k::mirrors_interface()])
+ return Qnil;
+ VALUE result(rb_ary_new());
+ for (RepositoryMirrorsInterface::MirrorsConstIterator m((**self_ptr)[k::mirrors_interface()]->begin_mirrors(StringValuePtr(mirror))),
+ m_end((**self_ptr)[k::mirrors_interface()]->end_mirrors(StringValuePtr(mirror))) ;
+ m != m_end ; ++m)
+ rb_ary_push(result, rb_str_new2((m->second).c_str()));
+ return result;
+ }
+
void do_register_repository()
{
/*
@@ -953,6 +990,9 @@ namespace
RUBY_FUNC_CAST((&RepositoryKey<MetadataValueKey<FSEntry>, &Repository::installed_root_key>::fetch)), 0);
rb_define_method(c_repository, "get_environment_variable", RUBY_FUNC_CAST(&repository_get_environment_variable), 2);
+ rb_define_method(c_repository, "is_mirror?", RUBY_FUNC_CAST(&repository_is_mirror), 1);
+ rb_define_method(c_repository, "mirrors", RUBY_FUNC_CAST(&repository_mirrors), 1);
+
/*
* Document-class: Paludis::ProfilesDescLine
*
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index f1416c7..f22a94a 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -361,6 +361,28 @@ module Paludis
end
end
+ class TestCase_RepositoryMirrorsInterface < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_responds
+ repo = no_config_testrepo.main_repository
+ [:is_mirror?, :mirrors].each do |sym|
+ assert_respond_to repo, sym
+ end
+ end
+
+ def test_is_mirror?
+ repo = no_config_testrepo.main_repository
+ assert repo.is_mirror?('cat')
+ assert !repo.is_mirror?('dog')
+ end
+
+ def test_mirrors
+ assert_equal ['http://a', 'http://b'], repo.mirrors('cat')
+ assert repo.mirrors('dog').empty?
+ end
+ end
+
class TestCase_RepositoryPortageInterface < Test::Unit::TestCase
include RepositoryTestCase
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index a32fd80..bf71211 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -98,6 +98,10 @@ cat <<END > profiles/use.local.desc || exit 1
foo/bar:test2 - A test local use flag
END
+cat <<END > profiles/thirdpartymirrors || exit 1
+cat http://a http://b
+END
+
touch foo/metadata.xml
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1