aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-18 19:27:16 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-18 19:27:16 +0000
commit6589621aa628c347bf13b037a4323ebc4f7b4b6d (patch)
tree2fbd704f45f45cb3c5db6fc3955ae44619d70cab
parent54d27be260d8b3c868459ddfa596c58774927026 (diff)
downloadpaludis-6589621aa628c347bf13b037a4323ebc4f7b4b6d.tar.gz
paludis-6589621aa628c347bf13b037a4323ebc4f7b4b6d.tar.xz
Add a demo Ruby app that finds unused distfiles
-rw-r--r--ruby/demos/Makefile.am6
-rw-r--r--ruby/demos/find_unused_distfiles.rb93
-rw-r--r--ruby/repository.cc102
-rw-r--r--ruby/repository_TEST.rb9
-rw-r--r--ruby/version_metadata_TEST.rb4
-rwxr-xr-xruby/version_metadata_TEST_setup.sh3
6 files changed, 212 insertions, 5 deletions
diff --git a/ruby/demos/Makefile.am b/ruby/demos/Makefile.am
index 9756583..a5d0c9a 100644
--- a/ruby/demos/Makefile.am
+++ b/ruby/demos/Makefile.am
@@ -15,7 +15,8 @@ CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda *.o *.so
MAINTAINERCLEANFILES = Makefile.in
IF_RUBY_DEMOS = \
- version_spec_distributions.rb
+ version_spec_distributions.rb \
+ find_unused_distfiles.rb
EXTRA_DIST = $(IF_RUBY_DEMOS)
@@ -31,7 +32,8 @@ TESTS_ENVIRONMENT = env \
if ENABLE_RUBY
-noinst_DATA = $(IF_RUBY_DEMOS)
+rubydemosdir = $(datadir)/paludis/ruby/demos/
+rubydemos_DATA = $(IF_RUBY_DEMOS)
endif
diff --git a/ruby/demos/find_unused_distfiles.rb b/ruby/demos/find_unused_distfiles.rb
new file mode 100644
index 0000000..f7f7714
--- /dev/null
+++ b/ruby/demos/find_unused_distfiles.rb
@@ -0,0 +1,93 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+require 'Paludis'
+require 'getoptlong'
+
+Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+
+opts = GetoptLong.new(
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
+ [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
+ [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--config-suffix', '-c', GetoptLong::REQUIRED_ARGUMENT ])
+
+config_suffix = ""
+opts.each do | opt, arg |
+ case opt
+ when '--help'
+ puts "Usage: " + $0 + " [options]"
+ puts
+ puts "Options:"
+ puts " --help Display a help message"
+ puts " --version Display program version"
+ puts
+ puts " --log-level level Set log level (debug, qa, warning, silent)"
+ puts " --config-suffix suffix Set configuration suffix)"
+ exit 0
+
+ when '--version'
+ puts $0.to_s.split(/\//).last + " " + Paludis::Version
+ exit 0
+
+ when '--log-level'
+ case arg
+ when 'debug'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Debug
+ when 'qa'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Qa
+ when 'warning'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
+ when 'silent'
+ Paludis::Log.instance.log_level = Paludis::LogLevel::Silent
+ else
+ puts "Bad --log-level value " + arg
+ exit 1
+ end
+
+ when '--config-suffix'
+ config_suffix = arg
+
+ end
+end
+
+Paludis::DefaultConfig::config_suffix = config_suffix
+env = Paludis::DefaultEnvironment.instance
+
+# build up a list of all src_uri things that're used by installed packages
+parts = Hash.new
+env.package_database.repositories.each do | repo |
+ repo.installed_interface or next
+ repo.category_names.each do | cat |
+ repo.package_names(cat).each do | pkg |
+ repo.version_specs(pkg).each do | ver |
+ src_uri = repo.version_metadata(pkg, ver).src_uri
+ src_uri or next
+ src_uri.split(/\s+/).each do | part |
+ part =~ %r~/~ or next
+ parts[part.sub(%r~^.*/~, "")] = true
+ end
+ end
+ end
+ end
+end
+
+# figure out a list of places where distfiles can be found
+distdirs = []
+env.package_database.repositories.each do | repo |
+ repo.info(false).sections.each do | info_section |
+ info_section.kvs.each do | key, value |
+ key == "distdir" or next
+ distdirs << value unless distdirs.member? value
+ end
+ end
+end
+
+# display each unused distfile
+distdirs.each do | dir |
+ Dir.new(dir).sort.each do | file |
+ File.new(dir + "/" + file).stat.file? or next
+ puts dir + "/" + file unless parts[file]
+ end
+end
+
diff --git a/ruby/repository.cc b/ruby/repository.cc
index 2f74606..50fc765 100644
--- a/ruby/repository.cc
+++ b/ruby/repository.cc
@@ -30,6 +30,8 @@ using namespace paludis::ruby;
namespace
{
static VALUE c_repository;
+ static VALUE c_repository_info;
+ static VALUE c_repository_info_section;
VALUE
repository_name(VALUE self)
@@ -169,6 +171,69 @@ namespace
}
}
+ template <typename T_, T_ * RepositoryCapabilities::* m_>
+ struct Interface
+ {
+ static VALUE fetch(VALUE self)
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+ return ((**self_ptr).*m_) ? self : Qnil;
+ }
+ };
+
+ VALUE
+ repository_info(VALUE self, VALUE verbose)
+ {
+ Repository::ConstPointer * self_ptr;
+ Data_Get_Struct(self, Repository::ConstPointer, self_ptr);
+
+ RepositoryInfo::ConstPointer * p = new RepositoryInfo::ConstPointer((*self_ptr)->info(Qfalse == verbose));
+ return Data_Wrap_Struct(c_repository_info, 0, &Common<RepositoryInfo::ConstPointer>::free, p);
+ }
+
+ VALUE
+ repository_info_sections(VALUE self)
+ {
+ try
+ {
+ RepositoryInfo::ConstPointer * self_ptr;
+ Data_Get_Struct(self, RepositoryInfo::ConstPointer, self_ptr);
+
+ VALUE result(rb_ary_new());
+ for (RepositoryInfo::SectionIterator i((*self_ptr)->begin_sections()),
+ i_end((*self_ptr)->end_sections()) ; i != i_end ; ++i)
+ {
+ RepositoryInfoSection::ConstPointer * s(new RepositoryInfoSection::ConstPointer(*i));
+ rb_ary_push(result, Data_Wrap_Struct(c_repository_info_section, 0, &Common<RepositoryInfo::ConstPointer>::free, s));
+ }
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ repository_info_section_kvs(VALUE self)
+ {
+ try
+ {
+ RepositoryInfoSection::ConstPointer * self_ptr;
+ Data_Get_Struct(self, RepositoryInfoSection::ConstPointer, self_ptr);
+
+ VALUE result(rb_hash_new());
+ for (RepositoryInfoSection::KeyValueIterator i((*self_ptr)->begin_kvs()),
+ i_end((*self_ptr)->end_kvs()) ; i != i_end ; ++i)
+ rb_hash_aset(result, rb_str_new2(i->first.c_str()), rb_str_new2(i->second.c_str()));
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
void do_register_repository()
{
@@ -185,6 +250,43 @@ namespace
rb_define_method(c_repository, "version_specs", RUBY_FUNC_CAST(&repository_version_specs), 1);
rb_define_method(c_repository, "version_metadata", RUBY_FUNC_CAST(&repository_version_metadata), 2);
+
+ rb_define_method(c_repository, "installable_interface", RUBY_FUNC_CAST((&Interface<RepositoryInstallableInterface,
+ &Repository::installable_interface>::fetch)), 0);
+ rb_define_method(c_repository, "installed_interface", RUBY_FUNC_CAST((&Interface<RepositoryInstalledInterface,
+ &Repository::installed_interface>::fetch)), 0);
+ rb_define_method(c_repository, "mask_interface", RUBY_FUNC_CAST((&Interface<RepositoryMaskInterface,
+ &Repository::mask_interface>::fetch)), 0);
+ rb_define_method(c_repository, "news_interface", RUBY_FUNC_CAST((&Interface<RepositoryNewsInterface,
+ &Repository::news_interface>::fetch)), 0);
+ rb_define_method(c_repository, "sets_interface", RUBY_FUNC_CAST((&Interface<RepositorySetsInterface,
+ &Repository::sets_interface>::fetch)), 0);
+ rb_define_method(c_repository, "syncable_interface", RUBY_FUNC_CAST((&Interface<RepositorySyncableInterface,
+ &Repository::syncable_interface>::fetch)), 0);
+ rb_define_method(c_repository, "uninstallable_interface", RUBY_FUNC_CAST((&Interface<RepositoryUninstallableInterface,
+ &Repository::uninstallable_interface>::fetch)), 0);
+ rb_define_method(c_repository, "use_interface", RUBY_FUNC_CAST((&Interface<RepositoryUseInterface,
+ &Repository::use_interface>::fetch)), 0);
+ rb_define_method(c_repository, "world_interface", RUBY_FUNC_CAST((&Interface<RepositoryWorldInterface,
+ &Repository::world_interface>::fetch)), 0);
+ rb_define_method(c_repository, "mirrors_interface", RUBY_FUNC_CAST((&Interface<RepositoryMirrorsInterface,
+ &Repository::mirrors_interface>::fetch)), 0);
+ rb_define_method(c_repository, "environment_variable_interface", RUBY_FUNC_CAST((&Interface<RepositoryEnvironmentVariableInterface,
+ &Repository::environment_variable_interface>::fetch)), 0);
+ rb_define_method(c_repository, "provides_interface", RUBY_FUNC_CAST((&Interface<RepositoryProvidesInterface,
+ &Repository::provides_interface>::fetch)), 0);
+ rb_define_method(c_repository, "virtuals_interface", RUBY_FUNC_CAST((&Interface<RepositoryVirtualsInterface,
+ &Repository::virtuals_interface>::fetch)), 0);
+
+ rb_define_method(c_repository, "info", RUBY_FUNC_CAST(&repository_info), 1);
+
+ c_repository_info = rb_define_class_under(master_class(), "RepositoryInfo", rb_cObject);
+ rb_funcall(c_repository_info, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_repository_info, "sections", RUBY_FUNC_CAST(&repository_info_sections), 0);
+
+ c_repository_info_section = rb_define_class_under(master_class(), "RepositoryInfoSection", rb_cObject);
+ rb_funcall(c_repository_info_section, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_repository_info_section, "kvs", RUBY_FUNC_CAST(&repository_info_section_kvs), 0);
}
}
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 8e41263..7bb954c 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -116,5 +116,14 @@ class Paludis
assert repo.package_names("bar").empty?
end
end
+
+ class TestCase_RepositoryInterfaces < Test::Unit::TestCase
+ include RepositoryTestCase
+
+ def test_interfaces
+ assert_equal repo.name, repo.installable_interface.name
+ assert_nil repo.installed_interface
+ end
+ end
end
diff --git a/ruby/version_metadata_TEST.rb b/ruby/version_metadata_TEST.rb
index e6ef5fe..a8ae7d4 100644
--- a/ruby/version_metadata_TEST.rb
+++ b/ruby/version_metadata_TEST.rb
@@ -63,8 +63,8 @@ class Paludis
def test_ebuild_members
assert_equal "", vmd("1.0").provide_string
- assert_equal "", vmd("1.0").src_uri
- assert_equal "", vmd("1.0").restrict_string
+ assert_equal "http://example.com/bar-1.0.tar.bz2", vmd("1.0").src_uri
+ assert_equal "monkey", vmd("1.0").restrict_string
assert_equal "test", vmd("1.0").keywords.gsub(%r/\s/, "")
assert_equal "", vmd("1.0").iuse.gsub(%r/\s/, "")
end
diff --git a/ruby/version_metadata_TEST_setup.sh b/ruby/version_metadata_TEST_setup.sh
index a87aac4..5ad102f 100755
--- a/ruby/version_metadata_TEST_setup.sh
+++ b/ruby/version_metadata_TEST_setup.sh
@@ -22,11 +22,12 @@ END
cat <<"END" > foo/bar/bar-1.0.ebuild || exit 1
DESCRIPTION="Test package"
HOMEPAGE="http://paludis.berlios.de/"
-SRC_URI=""
+SRC_URI="http://example.com/${P}.tar.bz2"
SLOT="0"
IUSE=""
LICENSE="GPL-2"
KEYWORDS="test"
+RESTRICT="monkey"
END
cd ..