aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-04-28 11:33:53 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-04-28 11:33:53 +0000
commita758785ff007a44b4c9953e1decaf7b62ff4147a (patch)
treeb0a56d5bedb6e27a00314c2fdf30a2cb8533965a
parent0a13a6f0dd4f73007d597995dd1f8d6d2c9f6d8a (diff)
downloadpaludis-a758785ff007a44b4c9953e1decaf7b62ff4147a.tar.gz
paludis-a758785ff007a44b4c9953e1decaf7b62ff4147a.tar.xz
Add accept_license and accept_keywords to ruby.
-rw-r--r--ruby/environment.cc64
-rw-r--r--ruby/environment_TEST.rb49
-rwxr-xr-xruby/environment_TEST_setup.sh4
3 files changed, 112 insertions, 5 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index 870ca04..eaf3ea6 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -21,6 +21,7 @@
#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
#include <paludis/environments/environment_maker.hh>
+#include <paludis/util/collection_concrete.hh>
#include <ruby.h>
using namespace paludis;
@@ -37,7 +38,7 @@ namespace
/*
* call-seq:
- * query_use(use_flag, package_database_entry)
+ * query_use(use_flag, package_database_entry) -> true or false
*
* Does the user want the specified USE flag set for a PackageDatabaseEntry.
*/
@@ -60,7 +61,7 @@ namespace
/*
* call-seq:
- * mask_reasons(package_database_entry)
+ * mask_reasons(package_database_entry) -> MaskReasons
*
* Fetch the MaskReasons for a PackageDatabaseEntry.
*/
@@ -83,6 +84,9 @@ namespace
}
/*
+ * call-seq:
+ * package_database -> PackageDatabase
+ *
* Fetch our PackageDatabase.
*/
VALUE
@@ -103,7 +107,7 @@ namespace
/*
* call-seq:
- * set(set_name)
+ * set(set_name) -> DepSpec
*
* Fetch a named package set as a DepSpec.
*/
@@ -125,6 +129,58 @@ namespace
/*
* call-seq:
+ * accept_license(license, pde) -> true of false
+ *
+ * Do we accept a particular license for a particular package?
+ */
+ VALUE
+ environment_accept_license(VALUE self, VALUE license, VALUE p)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+ try
+ {
+ PackageDatabaseEntry pde = value_to_package_database_entry(p);
+ return env_data->env_ptr->accept_license(std::string(StringValuePtr(license)), pde) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * accept_keywords(keywords, pde) -> true or false
+ *
+ * Do we accept any of the specified keywords for a particular package
+ */
+ VALUE
+ environment_accept_keywords(VALUE self, VALUE keywords, VALUE p)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+ try
+ {
+ PackageDatabaseEntry pde = value_to_package_database_entry(p);
+ std::tr1::shared_ptr<KeywordNameCollection> knc (new KeywordNameCollection::Concrete);
+ long len = NUM2LONG(rb_funcall(keywords,rb_intern("length"),0));
+ for (long i = 0; i < len; i++)
+ {
+ // Stupid macros won't let me do it on one line.
+ VALUE kw = rb_ary_entry(keywords, i);
+ knc->insert(KeywordName(StringValuePtr(kw)));
+ }
+ return env_data->env_ptr->accept_keywords(knc, pde) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* root -> String
*
* Default root location, default is /.
@@ -380,6 +436,8 @@ namespace
rb_define_method(c_environment, "set", RUBY_FUNC_CAST(&environment_set), 1);
rb_define_method(c_environment, "root", RUBY_FUNC_CAST(&environment_root), 0);
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);
/*
* Document-class: Paludis::PaludisEnvironment
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 9c79081..cc809ce 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -101,6 +101,55 @@ module Paludis
end
end
+ class TestCase_EnvironmentAcceptLicense < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def pde
+ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")
+ end
+
+ def test_accept_license
+ assert env.accept_license('GPL-2', pde)
+ assert !env.accept_license('Failure', pde)
+ end
+
+ def test_accept_license
+ assert_raise TypeError do
+ env.accept_keywords('license','a string')
+ end
+ end
+ end
+
+ class TestCase_EnvironmentAcceptKeywords < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentMaker.instance.make_from_spec("")
+ end
+
+ def pde
+ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")
+ end
+
+ def test_accept_keywords
+ assert env.accept_keywords(['test'], pde)
+ assert !env.accept_keywords(['test2'], pde)
+ assert env.accept_keywords(['test','testtest'], pde)
+ assert env.accept_keywords(['test2','testtest'], pde)
+ assert !env.accept_keywords(['test2','test3'], pde)
+ end
+
+ def test_accept_keywords_bad
+ assert_raise TypeError do
+ env.accept_keywords('test',pde)
+ end
+
+ assert_raise TypeError do
+ env.accept_keywords([],'a string')
+ end
+ end
+ end
+
class TestCase_NoConfigEnvironmentUse < Test::Unit::TestCase
def env
NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
diff --git a/ruby/environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index f83a38a..1e3dc12 100755
--- a/ruby/environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -15,7 +15,7 @@ profiles = \${location}/profiles/testprofile
END
cat <<END > home/.paludis/keywords.conf
-*/* test
+*/* test testtest testtesttest
~foo/bar-1.0 ~test
END
@@ -58,7 +58,7 @@ SRC_URI=""
SLOT="0"
IUSE=""
LICENSE="GPL-2"
-KEYWORDS="test"
+KEYWORDS="test testtest testtesttest"
END
cat <<"END" > foo/bar/bar-2.0.ebuild || exit 1