aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 19:03:24 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-25 19:03:24 +0000
commitd47c6da31c673ba098e484c9ef0e3b094b9a62c8 (patch)
treedee9c1b931501a7851fbbbdf9a80cbde114f0375
parenta0331b77bf92d1069ab2e58e3c66809aa92e3d64 (diff)
downloadpaludis-d47c6da31c673ba098e484c9ef0e3b094b9a62c8.tar.gz
paludis-d47c6da31c673ba098e484c9ef0e3b094b9a62c8.tar.xz
More Ruby work
-rw-r--r--ruby/Makefile.am14
-rw-r--r--ruby/package_database.cc41
-rw-r--r--ruby/package_database_TEST.rb46
-rw-r--r--ruby/paludis_ruby.hh2
-rw-r--r--ruby/repository.cc191
-rw-r--r--ruby/repository_TEST.rb120
-rwxr-xr-xruby/repository_TEST_cleanup.sh14
-rwxr-xr-xruby/repository_TEST_setup.sh64
-rw-r--r--ruby/version_spec.cc7
9 files changed, 495 insertions, 4 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index d0d0dbf..439d31b 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -22,7 +22,8 @@ IF_RUBY_TESTS = \
version_spec_TEST.rb \
mask_reasons_TEST.rb \
dep_atom_TEST.rb \
- package_database_TEST.rb
+ package_database_TEST.rb \
+ repository_TEST.rb
IF_RUBY_SOURCES = \
paludis_ruby.cc paludis_ruby.hh \
@@ -32,11 +33,13 @@ IF_RUBY_SOURCES = \
mask_reasons.cc \
dep_atom.cc \
log.cc \
- package_database.cc
+ package_database.cc \
+ repository.cc
EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh \
- package_database_TEST_setup.sh package_database_TEST_cleanup.sh
+ package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
+ repository_TEST_setup.sh repository_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
PALUDIS_NO_GLOBAL_HOOKS="yes" \
@@ -58,6 +61,7 @@ OUR_OBJECTS = \
package_database.o \
package_database_entry.o \
version_spec.o \
+ repository.o \
paludis_ruby.o
TESTS = $(IF_RUBY_TESTS)
@@ -94,6 +98,9 @@ mask_reasons.o : mask_reasons.cc paludis_ruby.hh
log.o : log.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/log.cc
+repository.o : repository.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/repository.cc
+
.libs/Paludis.so : $(OUR_OBJECTS)
mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
@@ -115,6 +122,5 @@ Paludis.so : $(OUR_OBJECTS)
-o $@ \
$^
-
endif
diff --git a/ruby/package_database.cc b/ruby/package_database.cc
index 1201bf7..4d79316 100644
--- a/ruby/package_database.cc
+++ b/ruby/package_database.cc
@@ -87,6 +87,43 @@ namespace
}
}
+ VALUE
+ package_database_repositories(VALUE self)
+ {
+ try
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+
+ VALUE result(rb_ary_new());
+ for (PackageDatabase::RepositoryIterator r((*self_ptr)->begin_repositories()),
+ r_end((*self_ptr)->end_repositories()) ; r != r_end ; ++r)
+ rb_ary_push(result, create_repository(*r));
+
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ package_database_fetch_repository(VALUE self, VALUE name)
+ {
+ try
+ {
+ PackageDatabase::Pointer * self_ptr;
+ Data_Get_Struct(self, PackageDatabase::Pointer, self_ptr);
+
+ return create_repository((*self_ptr)->fetch_repository(RepositoryName(STR2CSTR(name))));
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_package_database()
{
c_package_database = rb_define_class_under(master_class(), "PackageDatabase", rb_cObject);
@@ -97,6 +134,10 @@ namespace
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);
+ 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);
c_package_database_install_state = rb_define_class_under(master_class(), "InstallState", rb_cObject);
for (InstallState l(static_cast<InstallState>(0)), l_end(last_install_state) ; l != l_end ;
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index 0943a63..dca941d 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -59,10 +59,56 @@ class Paludis
a = db.query("=foo/bar-1.0", InstallState::UninstalledOnly)
assert_equal a, [ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo") ]
+ a = db.query(PackageDepAtom.new("=foo/bar-1.0"), InstallState::Either)
+ assert_equal a, [ PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo") ]
+
a = db.query("foo/bar", InstallState::UninstalledOnly)
assert_equal a, [
PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo"),
PackageDatabaseEntry.new("foo/bar", "2.0", "testrepo") ]
+
+ a = db.query(">=foo/bar-27", InstallState::UninstalledOnly)
+ assert a.empty?
+
+ a = db.query("foo/bar", InstallState::InstalledOnly)
+ assert a.empty?
+ end
+
+ def test_package_database_query_bad
+ assert_raise TypeError do
+ db.query(123, InstallState::Either)
+ end
+ assert_raise TypeError do
+ db.query(PackageDepAtom.new("foo/bar"), "Either")
+ end
+ end
+ end
+
+ class TestCase_PackageDatabaseRepositories < Test::Unit::TestCase
+ def db
+ return DefaultEnvironment.instance.package_database
+ end
+
+ def test_repositories
+ assert_equal 3, db.repositories.length
+
+ a = db.repositories.find_all do | repo |
+ repo.name == "testrepo"
+ end
+ assert_equal 1, a.length
+
+ a = db.repositories.find_all do | repo |
+ repo.name == "foorepo"
+ end
+ assert a.empty?
+ end
+
+ def test_fetch_repository
+ assert_equal "testrepo", db.fetch_repository("testrepo").name
+
+ assert_raise RuntimeError do
+ db.fetch_repository("barrepo")
+ end
end
end
end
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 50b1c9c..7e48a8c 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -45,6 +45,8 @@ namespace paludis
VALUE create_mask_reasons(const MaskReasons &);
VALUE create_package_database(PackageDatabase::Pointer);
VALUE create_package_database_entry(const PackageDatabaseEntry &);
+ VALUE create_repository(Repository::ConstPointer);
+ VALUE create_version_spec(const VersionSpec &);
VersionSpec value_to_version_spec(VALUE v);
PackageDepAtom::Pointer value_to_package_dep_atom(VALUE v);
diff --git a/ruby/repository.cc b/ruby/repository.cc
new file mode 100644
index 0000000..6d46e7a
--- /dev/null
+++ b/ruby/repository.cc
@@ -0,0 +1,191 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/stringify.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_repository;
+
+ VALUE
+ repository_name(VALUE self)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return rb_str_new2(stringify((*self_ptr)->name()).c_str());
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ repository_has_category_named(VALUE self, VALUE cat)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return (*self_ptr)->has_category_named(CategoryNamePart(STR2CSTR(cat))) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ repository_has_package_named(VALUE self, VALUE name)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return (*self_ptr)->has_package_named(QualifiedPackageName(STR2CSTR(name))) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ repository_has_version(VALUE self, VALUE name, VALUE version)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return (*self_ptr)->has_version(QualifiedPackageName(STR2CSTR(name)),
+ value_to_version_spec(version)) ? Qtrue : Qfalse;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ repository_category_names(VALUE self)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ VALUE result(rb_ary_new());
+ CategoryNamePartCollection::ConstPointer c((*self_ptr)->category_names());
+ for (CategoryNamePartCollection::Iterator i(c->begin()), i_end(c->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);
+ }
+ }
+
+ VALUE
+ repository_package_names(VALUE self, VALUE cat)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ CategoryNamePart category(STR2CSTR(cat));
+
+ VALUE result(rb_ary_new());
+ QualifiedPackageNameCollection::ConstPointer c((*self_ptr)->package_names(category));
+ for (QualifiedPackageNameCollection::Iterator i(c->begin()), i_end(c->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);
+ }
+ }
+
+ VALUE
+ repository_version_specs(VALUE self, VALUE qpn)
+ {
+ try
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ QualifiedPackageName q(STR2CSTR(qpn));
+
+ VALUE result(rb_ary_new());
+ VersionSpecCollection::ConstPointer c((*self_ptr)->version_specs(q));
+ for (VersionSpecCollection::Iterator i(c->begin()), i_end(c->end()) ; i != i_end ; ++i)
+ rb_ary_push(result, create_version_spec(*i));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_repository()
+ {
+ c_repository = rb_define_class_under(master_class(), "Repository", rb_cObject);
+ rb_funcall(c_repository, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_repository, "name", RUBY_FUNC_CAST(&repository_name), 0);
+
+ rb_define_method(c_repository, "has_category_named?", RUBY_FUNC_CAST(&repository_has_category_named), 1);
+ rb_define_method(c_repository, "has_package_named?", RUBY_FUNC_CAST(&repository_has_package_named), 1);
+ rb_define_method(c_repository, "has_version?", RUBY_FUNC_CAST(&repository_has_version), 2);
+
+ rb_define_method(c_repository, "category_names", RUBY_FUNC_CAST(&repository_category_names), 0);
+ rb_define_method(c_repository, "package_names", RUBY_FUNC_CAST(&repository_package_names), 1);
+ rb_define_method(c_repository, "version_specs", RUBY_FUNC_CAST(&repository_version_specs), 1);
+ }
+}
+
+VALUE
+paludis::ruby::create_repository(Repository::ConstPointer m)
+{
+ Repository::ConstPointer * m_ptr(0);
+ try
+ {
+ m_ptr = new Repository::ConstPointer(m);
+ return Data_Wrap_Struct(c_repository, 0, &Common<Repository::ConstPointer>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_repository PALUDIS_ATTRIBUTE((used))
+ (&do_register_repository);
+
+
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
new file mode 100644
index 0000000..8e41263
--- /dev/null
+++ b/ruby/repository_TEST.rb
@@ -0,0 +1,120 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/repository_TEST_dir/home";
+
+require 'test/unit'
+require 'Paludis'
+
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+
+class Paludis
+ class TestCase_Repository < Test::Unit::TestCase
+ def test_no_create
+ assert_raise NoMethodError do
+ p = Repository.new
+ end
+ end
+ end
+
+ module RepositoryTestCase
+ def repo
+ db.fetch_repository "testrepo"
+ end
+
+ def db
+ DefaultEnvironment.instance.package_database
+ end
+ end
+
+ class TestCase_RepositoryHasVersion < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_has_version
+ assert repo.has_version?("foo/bar", "1.0")
+ assert repo.has_version?("foo/bar", "2.0")
+
+ assert repo.has_version?("foo/bar", VersionSpec.new("1.0"))
+ assert repo.has_version?("foo/bar", VersionSpec.new("2.0"))
+
+ assert ! repo.has_version?("foo/barbar", "1.0")
+ assert ! repo.has_version?("foo/bar", "3.0")
+
+ assert ! repo.has_version?("foo/barbar", VersionSpec.new("1.0"))
+ assert ! repo.has_version?("foo/bar", VersionSpec.new("3.0"))
+ end
+ end
+
+ class TestCase_RepositoryHasCategoryNamed < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_has_category_named
+ assert repo.has_category_named?("foo")
+ assert ! repo.has_category_named?("bar")
+ end
+ end
+
+ class TestCase_RepositoryHasPackageNamed < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_has_package_named
+ assert repo.has_package_named?("foo/bar")
+ assert ! repo.has_package_named?("bar/bar")
+ assert ! repo.has_package_named?("foo/foo")
+ end
+ end
+
+ class TestCase_RepositoryVersionSpecs < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_version_specs
+ a = repo.version_specs "foo/bar"
+ assert_equal 2, a.length
+ assert_equal VersionSpec.new("1.0"), a[0]
+ assert_equal VersionSpec.new("2.0"), a[1]
+
+ b = repo.version_specs "bar/baz"
+ assert b.empty?
+ end
+ end
+
+ class TestCase_RepositoryCategoryNames < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_category_names
+ a = repo.category_names
+ assert_equal 1, a.length
+ assert_equal "foo", a[0]
+ end
+ end
+
+ class TestCase_RepositoryPackageNames < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_package_names
+ a = repo.package_names "foo"
+ assert_equal 1, a.length
+ assert_equal "foo/bar", a[0]
+
+ assert repo.package_names("bar").empty?
+ end
+ end
+end
+
diff --git a/ruby/repository_TEST_cleanup.sh b/ruby/repository_TEST_cleanup.sh
new file mode 100755
index 0000000..4ba9e47
--- /dev/null
+++ b/ruby/repository_TEST_cleanup.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d repository_TEST_dir ] ; then
+ rm -fr repository_TEST_dir
+else
+ true
+fi
+
+
+
+
+
+
diff --git a/ruby/repository_TEST_setup.sh b/ruby/repository_TEST_setup.sh
new file mode 100755
index 0000000..53c0b46
--- /dev/null
+++ b/ruby/repository_TEST_setup.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir repository_TEST_dir || exit 1
+cd repository_TEST_dir || exit 1
+
+mkdir -p home/.paludis/repositories
+
+cat <<END > home/.paludis/repositories/testrepo.conf
+location = `pwd`/testrepo
+format = portage
+cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+cat <<END > home/.paludis/keywords.conf
+* test
+~foo/bar-1 ~test
+END
+
+cat <<END > home/.paludis/use.conf
+* enabled
+~foo/bar-1 sometimes_enabled
+END
+
+cat <<END > home/.paludis/licenses.conf
+* *
+END
+
+mkdir -p testrepo/{eclass,distfiles,profiles/testprofile,foo/bar/files} || exit 1
+cd testrepo || exit 1
+echo "testrepo" > profiles/repo_name || exit 1
+cat <<END > profiles/categories || exit 1
+foo
+END
+cat <<END > profiles/testprofile/make.defaults
+ARCH=test
+USERLAND=test
+KERNEL=test
+END
+
+cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="test"
+END
+
+cat <<"END" > foo/bar/bar-2.0.ebuild || exit 1
+DESCRIPTION="Test package"
+HOMEPAGE="http://paludis.berlios.de/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="~test"
+END
+cd ..
+
+
+
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
index 24f6b39..96f400d 100644
--- a/ruby/version_spec.cc
+++ b/ruby/version_spec.cc
@@ -78,6 +78,13 @@ paludis::ruby::value_to_version_spec(VALUE v)
}
}
+VALUE
+paludis::ruby::create_version_spec(const VersionSpec & v)
+{
+ VersionSpec * vv(new VersionSpec(v));
+ return Data_Wrap_Struct(c_version_spec, 0, &Common<VersionSpec>::free, vv);
+}
+
RegisterRubyClass::Register paludis_ruby_register_version_spec PALUDIS_ATTRIBUTE((used))
(&do_register_version_spec);