X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bin%2Fsup-tweak-labels;h=8ae5c26f9054c841ad612bdaf29c79f300cab753;hb=e501453dd439a94bc2f09a644fa8be39e4634d0a;hp=0beb77e2c57858f03d7b33e59c23ca5dadd8d5e9;hpb=dd8dc5e703b9880d10427a1c70b4f7adcdfa2479;p=sup diff --git a/bin/sup-tweak-labels b/bin/sup-tweak-labels old mode 100644 new mode 100755 index 0beb77e..8ae5c26 --- a/bin/sup-tweak-labels +++ b/bin/sup-tweak-labels @@ -2,6 +2,7 @@ require 'rubygems' require 'trollop' +require 'enumerator' require "sup" class Float @@ -46,10 +47,12 @@ EOS Other options: EOS opt :verbose, "Print message ids as they're processed." + opt :very_verbose, "Print message names and subjects as they're processed." opt :all_sources, "Scan over all sources.", :short => :none opt :dry_run, "Don't actually modify the index. Probably only useful with --verbose.", :short => "-n" opt :version, "Show version information", :short => :none end +opts[:verbose] = true if opts[:very_verbose] add_labels = (opts[:add] || "").split(",").map { |l| l.intern }.uniq remove_labels = (opts[:remove] || "").split(",").map { |l| l.intern }.uniq @@ -63,10 +66,10 @@ begin source_ids = if opts[:all_sources] - index.sources + Redwood::SourceManager.sources else ARGV.map do |uri| - index.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?" + Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?" end end.map { |s| s.id } Trollop::die "nothing to do: no sources" if source_ids.empty? @@ -79,19 +82,17 @@ begin end query += ' ' + opts[:query] if opts[:query] - qobj, opts = Redwood::Index.parse_user_query_string query - query = Redwood::Index.build_query opts.merge(:qobj => qobj) - - results = index.ferret.search query, :limit => :all - num_total = results.total_hits + parsed_query = index.parse_query query + parsed_query.merge! :load_spam => true, :load_deleted => true, :load_killed => true + ids = Enumerable::Enumerator.new(index, :each_id, parsed_query).map + num_total = ids.size $stderr.puts "Found #{num_total} documents across #{source_ids.length} sources. Scanning..." num_changed = num_scanned = 0 last_info_time = start_time = Time.now - results.hits.each do |hit| + ids.each do |id| num_scanned += 1 - id = hit.doc m = index.build_message id old_labels = m.labels.clone @@ -102,7 +103,9 @@ begin unless m.labels.sort_by { |s| s.to_s } == old_labels.sort_by { |s| s.to_s } num_changed += 1 + puts "From #{m.from}, subject: #{m.subj}" if opts[:very_verbose] puts "#{m.id}: {#{old_labels.join ','}} => {#{m.labels.join ','}}" if opts[:verbose] + puts if opts[:very_verbose] index.sync_message m unless opts[:dry_run] end @@ -118,7 +121,7 @@ begin unless num_changed == 0 $stderr.puts "Optimizing index..." - index.ferret.optimize unless opts[:dry_run] + index.optimize unless opts[:dry_run] end rescue Exception => e