aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-05 16:55:02 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-05 16:55:02 +0000
commitd128bfa4d68531ad52ff3ef5a5f732c347e3cef9 (patch)
tree14901287876a6c5f660a4905a69562f15b8588e3
parentd9d97370db8ca8d9dbaeb2752a7e28f12280c93e (diff)
downloadpaludis-d128bfa4d68531ad52ff3ef5a5f732c347e3cef9.tar.gz
paludis-d128bfa4d68531ad52ff3ef5a5f732c347e3cef9.tar.xz
Update db->query in ruby.
-rw-r--r--paludis/package_database.cc28
-rw-r--r--paludis/package_database.hh8
-rw-r--r--ruby/demos/qualudis.rb10
-rw-r--r--ruby/package_database.cc58
-rw-r--r--ruby/package_database_TEST.rb29
5 files changed, 111 insertions, 22 deletions
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 9bb4e4c..d76bcac 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -455,3 +455,31 @@ paludis::operator<< (std::ostream & o, const InstallState & s)
return o;
}
+std::ostream &
+paludis::operator<< (std::ostream & o, const QueryOrder & s)
+{
+ do
+ {
+ switch (s)
+ {
+ case qo_order_by_version:
+ o << "order_by_version";
+ continue;
+
+ case qo_group_by_slot:
+ o << "group_by_slot";
+ continue;
+
+ case qo_whatever:
+ o << "whatever";
+ continue;
+
+ case last_query_order:
+ ;
+ }
+
+ throw InternalError(PALUDIS_HERE, "Bad QueryOrder");
+ } while (false);
+
+ return o;
+}
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index 40d385f..c1ffebb 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -325,6 +325,14 @@ namespace paludis
*/
std::ostream &
operator<< (std::ostream &, const InstallState &) PALUDIS_VISIBLE;
+
+ /**
+ * Write a QueryOrder to a stream.
+ *
+ * \ingroup grppackagedatabase
+ */
+ std::ostream &
+ operator<< (std::ostream &, const QueryOrder &) PALUDIS_VISIBLE;
}
#endif
diff --git a/ruby/demos/qualudis.rb b/ruby/demos/qualudis.rb
index 931cf04..f3a0251 100644
--- a/ruby/demos/qualudis.rb
+++ b/ruby/demos/qualudis.rb
@@ -3,6 +3,8 @@
#
require 'Paludis'
require 'getoptlong'
+require 'Pathname'
+
include Paludis
include Paludis::QA
@@ -430,16 +432,16 @@ end
unless ARGV.empty?
ARGV.each do |dir|
if dir.include? '/'
- full_dir = dir
+ full_dir = Pathname.new(dir)
else
- full_dir = "#{Dir.getwd}/#{dir}"
+ full_dir = Pathname.getwd + dir
end
- if File.directory? full_dir
+ if full_dir.directory?
do_check(full_dir)
else
$stderr.puts "#{full_dir} is not a directory"
end
end
else
- do_check(Dir.getwd)
+ do_check(Pathname.getwd)
end
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index 8f58b77..ae8645a 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -31,6 +31,7 @@ namespace
{
static VALUE c_package_database;
static VALUE c_package_database_install_state;
+ static VALUE c_package_database_query_order;
/*
* call-seq:
@@ -77,27 +78,45 @@ namespace
/*
* call-seq:
- * query(atom, install_state) -> Array
+ * query(atom, install_state, query_order) -> Array
*
* Query the repositoty. Returns an array of PackageDatabaseEntry
*/
VALUE
- package_database_query(VALUE self, VALUE atom, VALUE state)
+ package_database_query(int argc, VALUE *argv, VALUE self)
{
try
{
- PackageDatabase::Pointer * self_ptr;
- Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+ if (2 == argc || 3 == argc)
+ {
+ QueryOrder qo;
+ PackageDepAtom::ConstPointer pda(value_to_package_dep_atom(argv[0]));
+ InstallState is = static_cast<InstallState>(NUM2INT(argv[1]));
+ if (2 ==argc)
+ {
+ qo = qo_order_by_version;
+ rb_warn("Calling query with two arguments has been deprecated");
+ }
+ else
+ qo = static_cast<QueryOrder>(NUM2INT(argv[2]));
- PackageDatabaseEntryCollection::ConstPointer items((*self_ptr)->query(
- *value_to_package_dep_atom(atom),
- static_cast<InstallState>(NUM2INT(state))));
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
- VALUE result(rb_ary_new());
- for (PackageDatabaseEntryCollection::Iterator i(items->begin()),
- i_end(items->end()) ; i != i_end ; ++i)
- rb_ary_push(result, package_database_entry_to_value(*i));
- return result;
+ PackageDatabaseEntryCollection::ConstPointer items((*self_ptr)->query(
+ *pda, is, qo
+ ));
+
+ VALUE result(rb_ary_new());
+ for (PackageDatabaseEntryCollection::Iterator i(items->begin()),
+ i_end(items->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, package_database_entry_to_value(*i));
+ return result;
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "query expects three arguments, but got %d",argc);
+ }
}
catch (const std::exception & e)
{
@@ -190,13 +209,14 @@ namespace
rb_define_method(c_package_database, "fetch_unique_qualified_package_name",
RUBY_FUNC_CAST(&package_database_fetch_unique_qualified_package_name), 1);
rb_define_method(c_package_database, "query",
- RUBY_FUNC_CAST(&package_database_query), 2);
+ RUBY_FUNC_CAST(&package_database_query), -1);
rb_define_method(c_package_database, "repositories",
RUBY_FUNC_CAST(&package_database_repositories), 0);
rb_define_method(c_package_database, "fetch_repository",
RUBY_FUNC_CAST(&package_database_fetch_repository), 1);
rb_define_method(c_package_database, "more_important_than",
RUBY_FUNC_CAST(&package_database_more_important_than), 2);
+
/*
* Document-module: Paludis::InstallState
*
@@ -208,6 +228,18 @@ namespace
rb_define_const(c_package_database_install_state, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
// cc_enum_special<paludis/package_database.hh, InstallState, c_package_database_install_state>
+
+ /*
+ * Document-module: Paludis::QueryOrder
+ *
+ * How to order query results.
+ */
+ c_package_database_query_order = rb_define_class_under(paludis_module(), "QueryOrder", rb_cObject);
+ for (QueryOrder l(static_cast<QueryOrder>(0)), l_end(last_query_order) ; l != l_end ;
+ l = static_cast<QueryOrder>(static_cast<int>(l) + 1))
+ rb_define_const(c_package_database_query_order, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+
+ // cc_enum_special<paludis/package_database.hh, QueryOrder, c_package_database_query_order>
}
}
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index 183ffe0..9e1cfd3 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -64,22 +64,41 @@ module Paludis
return DefaultEnvironment.instance.package_database
end
+ def test_arg_count
+ assert_raise ArgumentError do
+ db.query(1);
+ end
+
+ #outputs a deprecation warning
+ assert_nothing_raised do
+ db.query(PackageDepAtom.new("=foo/bar-1.0"), InstallState::Any)
+ end
+
+ assert_nothing_raised do
+ db.query(PackageDepAtom.new("=foo/bar-1.0"), InstallState::Any, QueryOrder::Whatever)
+ end
+
+ assert_raise ArgumentError do
+ db.query(1,2,3,4);
+ end
+ end
+
def test_package_database_query
- a = db.query("=foo/bar-1.0", InstallState::InstallableOnly)
+ a = db.query("=foo/bar-1.0", InstallState::InstallableOnly, QueryOrder::Whatever)
assert_equal a, [ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo") ]
- a = db.query(PackageDepAtom.new("=foo/bar-1.0"), InstallState::Any)
+ a = db.query(PackageDepAtom.new("=foo/bar-1.0"), InstallState::Any, QueryOrder::Whatever)
assert_equal a, [ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo") ]
- a = db.query("foo/bar", InstallState::InstallableOnly)
+ a = db.query("foo/bar", InstallState::InstallableOnly, QueryOrder::OrderByVersion)
assert_equal a, [
PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo"),
PackageDatabaseEntry.new("foo/bar", "2.0", "testrepo") ]
- a = db.query(">=foo/bar-27", InstallState::InstallableOnly)
+ a = db.query(">=foo/bar-27", InstallState::InstallableOnly, QueryOrder::Whatever)
assert a.empty?
- a = db.query("foo/bar", InstallState::InstalledOnly)
+ a = db.query("foo/bar", InstallState::InstalledOnly, QueryOrder::Whatever)
assert a.empty?
end