aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2008-01-18 23:48:33 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2008-01-18 23:48:33 +0000
commit31d62bdfa5664f56557164ce9f78174ea10a61db (patch)
treed8c0b499b805e47824f3e8005586dfbe91df8e5f
parent6bb6418a5c51cbdf7a12e06204a864acbac03dbf (diff)
downloadpaludis-31d62bdfa5664f56557164ce9f78174ea10a61db.tar.gz
paludis-31d62bdfa5664f56557164ce9f78174ea10a61db.tar.xz
(ruby) Add match_package_in_set and example_match_package.
-rw-r--r--doc/api/index.html.part2
-rw-r--r--doc/api/ruby/Makefile.am1
-rw-r--r--doc/api/ruby/example_match_package.rb42
-rwxr-xr-xruby/package_id_TEST_setup.sh1
-rw-r--r--ruby/paludis_ruby.cc28
-rw-r--r--ruby/paludis_ruby_TEST.rb12
-rwxr-xr-xruby/paludis_ruby_TEST_setup.sh11
7 files changed, 93 insertions, 4 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index 8659124..e903ebc 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -130,7 +130,7 @@ how concepts map on to different language bindings.</p>
<tr>
<td>example_match_package</td>
<td><a href="cplusplus/example__match__package_8cc-example.html">C++</a></td>
- <td></td>
+ <td><a href="ruby/example_match_package.html">Ruby</a></td>
<td></td>
<td>How to use paludis::match_package and paludis::match_package_in_set</td>
</tr>
diff --git a/doc/api/ruby/Makefile.am b/doc/api/ruby/Makefile.am
index 12be425..3562baa 100644
--- a/doc/api/ruby/Makefile.am
+++ b/doc/api/ruby/Makefile.am
@@ -31,6 +31,7 @@ examples = \
example_dep_spec.rb \
example_dep_tree.rb \
example_mask.rb \
+ example_match_package.rb \
example_query.rb \
example_version_operator.rb \
example_version_spec.rb
diff --git a/doc/api/ruby/example_match_package.rb b/doc/api/ruby/example_match_package.rb
new file mode 100644
index 0000000..0c0d359
--- /dev/null
+++ b/doc/api/ruby/example_match_package.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=100 :
+
+=begin description
+This example demonstrates how to use contents. It displays details about
+the files installed by 'sys-apps/paludis'.
+=end
+
+require 'Paludis'
+require 'example_command_line'
+
+include Paludis
+
+exit_status = 0
+
+# We start with an Environment, respecting the user's '--environment' choice.
+env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
+
+# Fetch all installed packages
+ids = env.package_database.query(Query::SupportsInstalledAction.new, QueryOrder::OrderByVersion);
+
+# Fetch the 'system' and 'world' sets. Ordinarily we should check for
+# Nil here, but these two sets will always exist.
+system = env.set('system')
+world = env.set('world')
+
+# For each ID:
+ids.each do | id |
+ # Is it paludis?
+ if match_package(env, parse_user_package_dep_spec('sys-apps/paludis', []), id)
+ puts id.to_s.ljust(49) + ': paludis'
+ elsif match_package_in_set(env, system, id)
+ puts id.to_s.ljust(49) + ': system'
+ elsif match_package_in_set(env, world, id)
+ puts id.to_s.ljust(49) + ': world'
+ else
+ puts id.to_s.ljust(49) + ': nothing'
+ end
+end
+
+exit exit_status
+
diff --git a/ruby/package_id_TEST_setup.sh b/ruby/package_id_TEST_setup.sh
index 7147bea..45de07c 100755
--- a/ruby/package_id_TEST_setup.sh
+++ b/ruby/package_id_TEST_setup.sh
@@ -55,7 +55,6 @@ cd ..
mkdir -p installed/cat-one/pkg-{one,two}-1 || exit 1
-
echo "cat-one" > installed/cat-one/pkg-one-1/CATEGORY
touch installed/cat-one/pkg-one-1/CONTENTS
echo "0" > installed/cat-one/pkg-one-1/EAPI
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index fce50a1..1ebe0b5 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2006, 2007 Ciaran McCreesh
- * Copyright (c) 2006, 2007 Richard Brown
+ * Copyright (c) 2006, 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
@@ -101,6 +101,31 @@ namespace
}
/*
+ * Document-method: match_package_in_set
+ *
+ * call-seq:
+ * match_package_in_set(environment, set_spec_tree, package_id) -> true or false
+ *
+ * Return whether the specified PackageID matches the specified set.
+ *
+ */
+ VALUE paludis_match_package_in_set(VALUE, VALUE en, VALUE a, VALUE t)
+ {
+ try
+ {
+ tr1::shared_ptr<Environment> env = value_to_environment(en);
+ tr1::shared_ptr<const SetSpecTree::ConstItem> spec = value_to_dep_tree<SetSpecTree>(a);
+ tr1::shared_ptr<const PackageID> target = value_to_package_id(t);
+ return match_package_in_set(*env, *spec, *target) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ }
+
+ /*
* Document-method: version_spec_comparator
*
* call-seq:
@@ -454,6 +479,7 @@ void PALUDIS_VISIBLE paludis::ruby::init()
c_bad_version_operator_error = rb_define_class_under(c_paludis_module, "BadVersionOperatorError", rb_eRuntimeError);
rb_define_module_function(c_paludis_module, "match_package", RUBY_FUNC_CAST(&paludis_match_package), 3);
+ rb_define_module_function(c_paludis_module, "match_package_in_set", RUBY_FUNC_CAST(&paludis_match_package_in_set), 3);
rb_define_module_function(c_paludis_module, "version_spec_comparator", RUBY_FUNC_CAST(&paludis_version_spec_comparator), 3);
rb_define_const(c_paludis_module, "Version", INT2FIX(PALUDIS_VERSION));
diff --git a/ruby/paludis_ruby_TEST.rb b/ruby/paludis_ruby_TEST.rb
index bc3f403..128c99a 100644
--- a/ruby/paludis_ruby_TEST.rb
+++ b/ruby/paludis_ruby_TEST.rb
@@ -3,6 +3,7 @@
#
# Copyright (c) 2006, 2007 Ciaran McCreesh
+# Copyright (c) 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
@@ -36,7 +37,7 @@ module Paludis
class TestCase_Match < Test::Unit::TestCase
- def test_match
+ def test_match_package
env = EnvironmentMaker.instance.make_from_spec("")
spec_good = Paludis::parse_user_package_dep_spec('>=foo/bar-1', [])
spec_bad = Paludis::parse_user_package_dep_spec('>=foo/bar-2', [])
@@ -48,6 +49,15 @@ module Paludis
end
+ def test_match_package_in_set
+ env = EnvironmentMaker.instance.make_from_spec("")
+ world = env.set('world')
+ pid = env.package_database.query(Query::Matches.new(
+ Paludis::parse_user_package_dep_spec('=foo/bar-1.0::testrepo', [])), QueryOrder::RequireExactlyOne).first
+
+ assert Paludis::match_package_in_set(env, world, pid)
+ end
+
def test_type_errors
env = EnvironmentMaker.instance.make_from_spec("")
spec = Paludis::parse_user_package_dep_spec('>=foo/bar-1', [])
diff --git a/ruby/paludis_ruby_TEST_setup.sh b/ruby/paludis_ruby_TEST_setup.sh
index 5581fd1..4897c83 100755
--- a/ruby/paludis_ruby_TEST_setup.sh
+++ b/ruby/paludis_ruby_TEST_setup.sh
@@ -14,6 +14,13 @@ cache = /var/empty
profiles = \${location}/profiles/testprofile
END
+cat <<END > home/.paludis/repositories/installed.conf
+location = `pwd`/installed
+format = vdb
+names_cache = /var/empty
+provides_cache = /var/empty
+END
+
cat <<END > home/.paludis/keywords.conf
*/* test
~foo/bar-1 ~test
@@ -64,4 +71,8 @@ KEYWORDS="~test"
END
cd ..
+mkdir -p installed || exit 1
+
+echo "foo/bar" > installed/world
+