aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-23 11:18:36 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-23 11:18:36 +0000
commit20be66033d2c1423f9b459a6180c8ba7265bf761 (patch)
tree9521b42d9c7390da3a1001a4fdb6213c0960f22b
parentf34c586ddea4ad5ceb49535382e77c30680416a3 (diff)
downloadpaludis-20be66033d2c1423f9b459a6180c8ba7265bf761.tar.gz
paludis-20be66033d2c1423f9b459a6180c8ba7265bf761.tar.xz
Extend Ruby API. From David Leverton.
-rw-r--r--ruby/environment.cc24
-rw-r--r--ruby/environment_TEST.rb24
-rwxr-xr-xruby/environment_TEST_setup.sh4
-rw-r--r--ruby/repository.cc152
-rw-r--r--ruby/repository_TEST.rb180
-rwxr-xr-xruby/repository_TEST_setup.sh33
6 files changed, 416 insertions, 1 deletions
diff --git a/ruby/environment.cc b/ruby/environment.cc
index 0401f6b..0222a2a 100644
--- a/ruby/environment.cc
+++ b/ruby/environment.cc
@@ -153,6 +153,29 @@ namespace
}
/*
+ * call-seq:
+ * query_user_masks(package_database_entry)
+ *
+ * Are there any user masks on a PackageDatabaseEntry?
+ */
+ VALUE
+ environment_query_user_masks(VALUE self, VALUE pde_value)
+ {
+ EnvironmentData * env_data;
+ Data_Get_Struct(self, EnvironmentData, env_data);
+
+ PackageDatabaseEntry pde = value_to_package_database_entry(pde_value);
+ try
+ {
+ return env_data->env_ptr->query_user_masks(pde) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
* Fetch our PackageDatabase.
*/
VALUE
@@ -346,6 +369,7 @@ namespace
rb_define_method(c_environment, "accept_keyword", RUBY_FUNC_CAST(&environment_accept_keyword), -1);
rb_define_method(c_environment, "accept_license", RUBY_FUNC_CAST(&environment_accept_license), -1);
rb_define_method(c_environment, "mask_reasons", RUBY_FUNC_CAST(&environment_mask_reasons), 1);
+ rb_define_method(c_environment, "query_user_masks", RUBY_FUNC_CAST(&environment_query_user_masks), 1);
rb_define_method(c_environment, "package_database", RUBY_FUNC_CAST(&environment_package_database), 0);
rb_define_method(c_environment, "package_set", RUBY_FUNC_CAST(&environment_package_set), 1);
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index e2cca4d..9cb5112 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -230,6 +230,30 @@ module Paludis
end
end
+ class TestCase_DefaultEnvironmentQueryUserMasks < Test::Unit::TestCase
+ def env
+ DefaultEnvironment.instance
+ end
+
+ def test_query_user_masks
+ p2 = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
+ p3 = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("3.0"), "testrepo")
+
+ assert ! env.query_user_masks(p2)
+ assert env.query_user_masks(p3)
+ end
+
+ def test_query_user_masks_bad
+ p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")
+ assert_raise ArgumentError do
+ env.query_user_masks(p, p)
+ end
+ assert_raise TypeError do
+ env.query_user_masks(123)
+ end
+ end
+ end
+
class TestCase_DefaultEnvironmentPackageDatabase < Test::Unit::TestCase
def db
DefaultEnvironment.instance.package_database
diff --git a/ruby/environment_TEST_setup.sh b/ruby/environment_TEST_setup.sh
index aaede32..c5403d1 100755
--- a/ruby/environment_TEST_setup.sh
+++ b/ruby/environment_TEST_setup.sh
@@ -24,6 +24,10 @@ cat <<END > home/.paludis/use.conf
~foo/bar-1 sometimes_enabled
END
+cat <<END > home/.paludis/package_mask.conf
+=foo/bar-3*
+END
+
cat <<END > home/.paludis/licenses.conf
* *
END
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 3f40082..3689883 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -575,6 +575,151 @@ namespace
}
};
+ /*
+ * Document-method: query_use
+ *
+ * call-seq:
+ * query_use(use_flag) -> true or false or nil
+ * query_use(use_flag, package_database_entry) -> true or false or nil
+ *
+ * Query the state of the specified use flag: true if set, false
+ * if unset, nil if unspecified. nil if the repository doesn't
+ * implement use_interface.
+ */
+ /*
+ * Document-method: query_use_mask
+ *
+ * call-seq:
+ * query_use_mask(use_flag) -> true or false or nil
+ * query_use_mask(use_flag, package_database_entry) -> true or false or nil
+ *
+ * Query whether the specified use flag is masked. nil if the
+ * repository doesn't implement use_interface.
+ */
+ /*
+ * Document-method: query_use_force
+ *
+ * call-seq:
+ * query_use_force(use_flag) -> true or false or nil
+ * query_use_force(use_flag, package_database_entry) -> true or false or nil
+ *
+ * Query whether the specified use flag is forced. nil if the
+ * repository doesn't implement use_interface.
+ */
+
+ template <typename T_, T_ (RepositoryUseInterface::* m_) (const UseFlagName &, const PackageDatabaseEntry *) const> struct QueryUseMessage;
+
+ template <typename T_, T_ trueval_, T_ falseval_, T_ (RepositoryUseInterface::* m_) (const UseFlagName &, const PackageDatabaseEntry *) const>
+ struct QueryUse
+ {
+ static VALUE
+ query(int argc, VALUE * argv, VALUE self)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ const RepositoryUseInterface * const use_interface ((**self_ptr).use_interface);
+
+ if (use_interface)
+ {
+ if (1 != argc && 2 != argc) {
+ rb_raise(rb_eArgError, QueryUseMessage<T_, m_>::message, argc);
+ }
+
+ T_ status;
+
+ if (1 == argc)
+ status = ((*use_interface).*m_)(UseFlagName(StringValuePtr(argv[0])), 0);
+ else
+ {
+ PackageDatabaseEntry pde = value_to_package_database_entry(argv[1]);
+ status = ((*use_interface).*m_)(UseFlagName(StringValuePtr(argv[0])), &pde);
+ }
+
+ return status == trueval_ ? Qtrue : status == falseval_ ? Qfalse : Qnil;
+ }
+ else
+ {
+ return Qnil;
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
+ template<>
+ struct QueryUseMessage<UseFlagState, &RepositoryUseInterface::query_use>
+ {
+ static const char * message;
+ };
+ const char * QueryUseMessage<UseFlagState, &RepositoryUseInterface::query_use>::message = "Repository.query_use expects one or two arguments, but got %d";
+
+ template<>
+ struct QueryUseMessage<bool, &RepositoryUseInterface::query_use_mask>
+ {
+ static const char * message;
+ };
+ const char * QueryUseMessage<bool, &RepositoryUseInterface::query_use_mask>::message = "Repository.query_use_mask expects one or two arguments, but got %d";
+
+ template<>
+ struct QueryUseMessage<bool, &RepositoryUseInterface::query_use_force>
+ {
+ static const char * message;
+ };
+ const char * QueryUseMessage<bool, &RepositoryUseInterface::query_use_force>::message = "Repository.query_use_force expects one or two arguments, but got %d";
+
+ /*
+ * Document-method: query_repository_masks
+ *
+ * call-seq:
+ * query_repository_masks(qualified_package_name, version_spec) -> true or false or nil
+ *
+ * Query repository masks. nil if the repository doesn't implement mask_interface.
+ */
+ /*
+ * Document-method: query_profile_masks
+ *
+ * call-seq:
+ * query_profile_masks(qualified_package_name, version_spec) -> true or false or nil
+ *
+ * Query profile masks. nil if the repository doesn't implement mask_interface.
+ */
+
+ template <bool (RepositoryMaskInterface::* m_) (const QualifiedPackageName &, const VersionSpec &) const>
+ struct QueryMasks
+ {
+ static VALUE
+ query(VALUE self, VALUE qpn, VALUE ver)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ const RepositoryMaskInterface * const mask_interface ((**self_ptr).mask_interface);
+
+ if (mask_interface)
+ {
+ QualifiedPackageName q = value_to_qualified_package_name(qpn);
+ VersionSpec v = value_to_version_spec(ver);
+
+ return ((*mask_interface).*m_)(q, v) ? Qtrue : Qfalse;
+ }
+ else
+ {
+ return Qnil;
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+ };
+
void do_register_repository()
{
/*
@@ -629,6 +774,13 @@ namespace
rb_define_method(c_repository, "contents", RUBY_FUNC_CAST(&repository_contents), 2);
rb_define_method(c_repository, "installed_time", RUBY_FUNC_CAST(&repository_installed_time), 2);
+ rb_define_method(c_repository, "query_use", RUBY_FUNC_CAST((&QueryUse<UseFlagState, use_enabled, use_disabled, &RepositoryUseInterface::query_use>::query)), -1);
+ rb_define_method(c_repository, "query_use_mask", RUBY_FUNC_CAST((&QueryUse<bool, true, false, &RepositoryUseInterface::query_use_mask>::query)), -1);
+ rb_define_method(c_repository, "query_use_force", RUBY_FUNC_CAST((&QueryUse<bool, true, false, &RepositoryUseInterface::query_use_force>::query)), -1);
+
+ rb_define_method(c_repository, "query_repository_masks", RUBY_FUNC_CAST(&QueryMasks<&RepositoryMaskInterface::query_repository_masks>::query), 2);
+ rb_define_method(c_repository, "query_profile_masks", RUBY_FUNC_CAST(&QueryMasks<&RepositoryMaskInterface::query_profile_masks>::query), 2);
+
/*
* Document-class: Paludis::RepositoryInfo
*
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 363f730..8d94a2c 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -211,6 +211,186 @@ module Paludis
end
end
+ class TestCase_RepositoryQueryUse < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_query_use_global
+ assert repo.query_use('test1') == true
+ assert repo.query_use('test2') == true
+ assert repo.query_use('test3') == nil
+ assert repo.query_use('test4') == false
+ assert repo.query_use('test5') == false
+ assert repo.query_use('test6') == true
+ assert repo.query_use('test7') == nil
+ end
+
+ def test_query_use_local
+ p = PackageDatabaseEntry.new('foo/bar','2.0',repo.name)
+
+ assert repo.query_use('test1',p) == true
+ assert repo.query_use('test2',p) == false
+ assert repo.query_use('test3',p) == true
+ assert repo.query_use('test4',p) == nil
+ assert repo.query_use('test5',p) == false
+ assert repo.query_use('test6',p) == true
+ assert repo.query_use('test7',p) == true
+ end
+
+ def test_query_use_bad
+ assert_raise TypeError do
+ repo.query_use(42)
+ end
+ assert_raise TypeError do
+ repo.query_use('test1',{})
+ end
+
+ assert_raise ArgumentError do
+ repo.query_use
+ repo.query_use(1,2,3)
+ end
+ end
+ end
+
+ class TestCase_RepositoryQueryUseMask < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_query_use_mask_global
+ assert ! repo.query_use_mask('test1')
+ assert ! repo.query_use_mask('test2')
+ assert ! repo.query_use_mask('test3')
+ assert repo.query_use_mask('test4')
+ assert ! repo.query_use_mask('test5')
+ assert ! repo.query_use_mask('test6')
+ assert ! repo.query_use_mask('test7')
+ end
+
+ def test_query_use_mask_local
+ p = PackageDatabaseEntry.new('foo/bar','2.0',repo.name)
+
+ assert ! repo.query_use_mask('test1',p)
+ assert ! repo.query_use_mask('test2',p)
+ assert ! repo.query_use_mask('test3',p)
+ assert ! repo.query_use_mask('test4',p)
+ assert repo.query_use_mask('test5',p)
+ assert ! repo.query_use_mask('test6',p)
+ assert ! repo.query_use_mask('test7',p)
+ end
+
+ def test_query_use_mask_bad
+ assert_raise TypeError do
+ repo.query_use_mask(42)
+ end
+ assert_raise TypeError do
+ repo.query_use_mask('test1',{})
+ end
+
+ assert_raise ArgumentError do
+ repo.query_use_mask
+ repo.query_use_mask(1,2,3)
+ end
+ end
+ end
+
+ class TestCase_RepositoryQueryUseForce < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_query_use_force_global
+ assert ! repo.query_use_force('test1')
+ assert ! repo.query_use_force('test2')
+ assert ! repo.query_use_force('test3')
+ assert ! repo.query_use_force('test4')
+ assert ! repo.query_use_force('test5')
+ assert repo.query_use_force('test6')
+ assert ! repo.query_use_force('test7')
+ end
+
+ def test_query_use_force_local
+ p = PackageDatabaseEntry.new('foo/bar','2.0',repo.name)
+
+ assert ! repo.query_use_force('test1',p)
+ assert ! repo.query_use_force('test2',p)
+ assert ! repo.query_use_force('test3',p)
+ assert ! repo.query_use_force('test4',p)
+ assert ! repo.query_use_force('test5',p)
+ assert repo.query_use_force('test6',p)
+ assert repo.query_use_force('test7',p)
+ end
+
+ def test_query_use_force_bad
+ assert_raise TypeError do
+ repo.query_use_force(42)
+ end
+ assert_raise TypeError do
+ repo.query_use_force('test1',{})
+ end
+
+ assert_raise ArgumentError do
+ repo.query_use_force
+ repo.query_use_force(1,2,3)
+ end
+ end
+ end
+
+ class TestCase_QueryRepositoryMasks < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_repository_masks
+ assert repo.query_repository_masks("foo1/bar","1.0")
+ assert repo.query_repository_masks("foo2/bar","1.0")
+ assert ! repo.query_repository_masks("foo3/bar","1.0")
+ assert ! repo.query_repository_masks("foo4/bar","1.0")
+ end
+
+ def test_repository_masks_bad
+ assert_raise TypeError do
+ repo.query_repository_masks(42,"1.0")
+ end
+ assert_raise TypeError do
+ repo.query_repository_masks("foo/bar",[])
+ end
+
+ assert_raise ArgumentError do
+ repo.query_repository_masks
+ end
+ assert_raise ArgumentError do
+ repo.query_repository_masks("foo/bar")
+ end
+ assert_raise ArgumentError do
+ repo.query_repository_masks("foo/bar","1.0","baz")
+ end
+ end
+ end
+
+ class TestCase_QueryProfileMasks < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_profile_masks
+ assert repo.query_profile_masks("foo1/bar","1.0")
+ assert ! repo.query_profile_masks("foo2/bar","1.0")
+ assert repo.query_profile_masks("foo3/bar","1.0")
+ assert ! repo.query_profile_masks("foo4/bar","1.0")
+ end
+
+ def test_profile_masks_bad
+ assert_raise TypeError do
+ repo.query_profile_masks(42,"1.0")
+ end
+ assert_raise TypeError do
+ repo.query_profile_masks("foo/bar",[])
+ end
+
+ assert_raise ArgumentError do
+ repo.query_profile_masks
+ end
+ assert_raise ArgumentError do
+ repo.query_profile_masks("foo/bar")
+ end
+ assert_raise ArgumentError do
+ repo.query_profile_masks("foo/bar","1.0","baz")
+ end
+ end
+ end
+
class TestCase_RepositoryInfo < Test::Unit::TestCase
include RepositoryTestCase
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
index 8c582ee..a8e1275 100755
--- a/ruby/repository_TEST_setup.sh
+++ b/ruby/repository_TEST_setup.sh
@@ -47,10 +47,41 @@ cat <<END > profiles/profiles.desc || exit 1
x86 testprofile stable
END
-cat <<END > profiles/testprofile/make.defaults
+cat <<END > profiles/package.mask || exit 1
+foo1/bar
+foo2/bar
+END
+
+cat <<END > profiles/testprofile/make.defaults || exit 1
ARCH=test
USERLAND=test
KERNEL=test
+USE="test1 test2 -test5"
+END
+
+cat <<END > profiles/testprofile/package.mask || exit 1
+foo1/bar
+foo3/bar
+END
+
+cat <<END > profiles/testprofile/package.use || exit 1
+foo/bar -test2 test3
+END
+
+cat <<END > profiles/testprofile/use.mask || exit 1
+test4
+END
+
+cat <<END > profiles/testprofile/package.use.mask || exit 1
+foo/bar -test4 test5
+END
+
+cat <<END > profiles/testprofile/use.force || exit 1
+test6
+END
+
+cat <<END > profiles/testprofile/package.use.force || exit 1
+foo/bar test7
END
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1