bin/sup-tweak-labels in sup-0.7 vs bin/sup-tweak-labels in sup-0.8
- old
+ new
@@ -44,14 +44,16 @@
text <<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
Trollop::die "nothing to do: no labels to add or remove" if add_labels.empty? && remove_labels.empty?
@@ -69,41 +71,39 @@
index.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?
- query = "+(" + source_ids.map { |id| "source_id:#{id}" }.join(" ") + ")"
+ query = "+(" + source_ids.map { |id| "source_id:#{id}" }.join(" OR ") + ")"
if add_labels.empty?
## if all we're doing is removing labels, we can further restrict the
## query to only messages with those labels
query += " +(" + remove_labels.map { |l| "label:#{l}" }.join(" ") + ")"
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)
+ docs = Redwood::Index.run_query query
+ num_total = docs.size
- results = index.ferret.search query, :limit => :all
- num_total = results.total_hits
-
$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|
+ docs.each do |id|
num_scanned += 1
- id = hit.doc
m = index.build_message id
old_labels = m.labels.clone
m.labels += add_labels
m.labels -= remove_labels
m.labels = m.labels.uniq
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
if Time.now - last_info_time > 60
last_info_time = Time.now