aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-05 04:06:40 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-05 04:06:40 +0000
commitea238e640663c2beacf0bf26feceacb4061da619 (patch)
tree0efc17839a442a90f2c57a4d14dfd93af931e87f
parent8b455d3d0d801923abba2eeef3506f72ff383273 (diff)
downloadpaludis-ea238e640663c2beacf0bf26feceacb4061da619.tar.gz
paludis-ea238e640663c2beacf0bf26feceacb4061da619.tar.xz
WIP
-rwxr-xr-xruby/demos/find_unused_distfiles.rb107
-rw-r--r--ruby/metadata_key.cc15
-rw-r--r--ruby/package_id_TEST.rb3
3 files changed, 95 insertions, 30 deletions
diff --git a/ruby/demos/find_unused_distfiles.rb b/ruby/demos/find_unused_distfiles.rb
index 813d962..84e0cec 100755
--- a/ruby/demos/find_unused_distfiles.rb
+++ b/ruby/demos/find_unused_distfiles.rb
@@ -8,15 +8,22 @@ Paludis::Log.instance.log_level = Paludis::LogLevel::Warning
Paludis::Log.instance.program_name = $0
opts = GetoptLong.new(
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
- [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
- [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--size-limit', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--time-limit', '-t', GetoptLong::REQUIRED_ARGUMENT ])
-
-env_spec = ""
-size_limit = time_limit = nil
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
+ [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
+ [ '--log-level', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--environment', '-E', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--size-limit', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--time-limit', '-t', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--mirror-repository', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--mirror-distdir', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--write-cache-dir', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--master-repository-dir', GetoptLong::REQUIRED_ARGUMENT ])
+
+env_spec = nil
+size_limit = time_limit = nil
+mirror_repository = mirror_distdir = nil
+write_cache_dir = master_repository_dir = "/var/empty"
+
opts.each do | opt, arg |
case opt
when '--help'
@@ -31,6 +38,11 @@ opts.each do | opt, arg |
puts
puts " --size-limit limit Don't delete anything bigger than limit (number followed by one of g, m, k, b)"
puts " --time-limit limit Don't delete anything newer than limit (number followed by one of h, d, w, m, y)"
+ puts
+ puts " --mirror-repository In mirror mode, the location of the ebuild repository"
+ puts " --mirror-distdir In mirror mode, the location of the downloaded files"
+ puts " --write-cache-dir Use a subdirectory named for the repository name under the specified directory for repository write cache"
+ puts " --master-repository-dir Use the specified location for the master repository"
exit 0
when '--version'
@@ -84,22 +96,61 @@ opts.each do | opt, arg |
exit 1
end
+ when '--mirror-repository'
+ mirror_repository = arg
+ when '--mirror-distdir'
+ mirror_distdir = arg
+
+ when '--write-cache-dir'
+ write_cache_dir = arg
+ when '--master-repository-dir'
+ master_repository_dir = arg
+
end
end
-env = Paludis::EnvironmentMaker.instance.make_from_spec env_spec
+if mirror_repository.nil? ^ mirror_distdir.nil? then
+ puts "Must specify neither or both of --mirror-repository and --mirror-distdir"
+ exit 1
+end
+if mirror_repository && env_spec then
+ puts "Can't use --environment in mirror mode"
+ exit 1
+end
+
+if mirror_repository then
+ $env = Paludis::NoConfigEnvironment.new(mirror_repository, write_cache_dir, master_repository_dir)
+ relevant_packages = Paludis::Query::Repository.new(env.main_repository.name)
+ $banned_labels = { } # XXX
+else
+ $env = Paludis::EnvironmentMaker.instance.make_from_spec(env_spec || "")
+ relevant_packages = Paludis::Query::SupportsInstalledAction.new
+ $banned_labels = { }
+end
-def collect_filenames(env, parts, id, spec)
+def collect_filenames(parts, id, label, spec)
case spec
+
when Paludis::AllDepSpec
- spec.each { | item | collect_filenames(env, parts, id, item) }
+ new_label = label.dup
+ spec.each do | item |
+ collect_filenames(parts, id, new_label, item)
+ end
+
when Paludis::UseDepSpec
- spec.each { | item | collect_filenames(env, parts, id, item) } if
- env.query_use(spec.flag, id) ^ spec.inverse?
+ if $env.query_use(spec.flag, id) ^ spec.inverse? then
+ new_label = label.dup
+ spec.each do | item |
+ collect_filenames(parts, id, new_label, item)
+ end
+ end
+
when Paludis::FetchableURIDepSpec
- parts[spec.filename] = true
+ parts[spec.filename] = true unless banned_labels[label[0]]
+
when Paludis::URILabelsDepSpec
- # don't need to do anything
+ label[0] = spec.to_s # XXX
+
else
raise "Unexpected DepSpec class #{spec.class} in #{id}"
end
@@ -107,24 +158,20 @@ end
# 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.some_ids_might_support_action(Paludis::SupportsInstalledActionTest.new) or next
- repo.category_names.each do | cat |
- repo.package_names(cat).each do | pkg |
- repo.package_ids(pkg).each do | id |
- id.supports_action(Paludis::SupportsInstalledActionTest.new) or next
- collect_filenames(env, parts, id, id.fetches_key.value) if
- id.fetches_key && id.fetches_key.value
- end
- end
- end
+$env.package_database.query(relevant_packages, Paludis::QueryOrder::Whatever) do | id |
+ collect_filenames(parts, id, [id.fetches_key.initial_label], id.fetches_key.value) if
+ id.fetches_key && id.fetches_key.value
end
# figure out a list of places where distfiles can be found
distdirs = []
-env.package_database.repositories.each do | repo |
- key = repo['distdir'] or next
- distdirs << key.value unless distdirs.member? key.value
+if mirror_distdir then
+ distdirs << mirror_distdir
+else
+ $env.package_database.repositories.each do | repo |
+ key = repo['distdir'] or next
+ distdirs << key.value unless distdirs.member? key.value
+ end
end
# display each unused distfile
diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc
index 7557559..89e086a 100644
--- a/ruby/metadata_key.cc
+++ b/ruby/metadata_key.cc
@@ -342,6 +342,20 @@ namespace
}
};
+ /*
+ * call-seq:
+ * initial_label -> String
+ *
+ * Return a String that represents the initial label to use when
+ * deciding the behaviour of individual items in the heirarchy.
+ */
+ VALUE
+ metadata_fetchable_uri_spec_tree_key_initial_label(VALUE self)
+ {
+ tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const MetadataKey>, self_ptr);
+ return rb_str_new2(stringify(*(tr1::static_pointer_cast<const MetadataSpecTreeKey<FetchableURISpecTree> >(*self_ptr))->initial_label()).c_str());
+ }
VALUE
repository_mask_info_mask_file(VALUE self)
@@ -519,6 +533,7 @@ namespace
*/
c_metadata_fetchable_uri_spec_tree_key = rb_define_class_under(paludis_module(), "MetadataFetchableURISpecTreeKey", c_metadata_key);
rb_define_method(c_metadata_fetchable_uri_spec_tree_key, "value", RUBY_FUNC_CAST((&SpecTreeValue<FetchableURISpecTree>::fetch)), 0);
+ rb_define_method(c_metadata_fetchable_uri_spec_tree_key, "initial_label", RUBY_FUNC_CAST(&metadata_fetchable_uri_spec_tree_key_initial_label), 0);
/*
* Document-class: Paludis::MetadataSimpleURISpecTreeKey
diff --git a/ruby/package_id_TEST.rb b/ruby/package_id_TEST.rb
index 1647d39..465cfa5 100644
--- a/ruby/package_id_TEST.rb
+++ b/ruby/package_id_TEST.rb
@@ -266,6 +266,9 @@ module Paludis
def test_fetches_key
assert_kind_of MetadataFetchableURISpecTreeKey, pid_testrepo.fetches_key
assert_kind_of AllDepSpec, pid_testrepo.fetches_key.value
+ assert_respond_to pid_testrepo.fetches_key, :initial_label
+ assert_kind_of String, pid_testrepo.fetches_key.initial_label
+ assert_equal "URIMirrorsThenListedLabel", pid_testrepo.fetches_key.initial_label
end
end