X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Frm_runner.rb;h=a19004a7a5440fcd23bb22173d3e5fe4d963ed76;hp=71421547e7e88e02247070680dce940f890c30f2;hb=a731b98f97194b8882c42d3c2b27de75f60d6b05;hpb=c5a1271a37bed990f2fd8caa8fcde23a6e107b46 diff --git a/lib/rm/rm_runner.rb b/lib/rm/rm_runner.rb index 7142154..a19004a 100644 --- a/lib/rm/rm_runner.rb +++ b/lib/rm/rm_runner.rb @@ -4,39 +4,34 @@ require 'common/runner' class RmRunner include Runner - def run(plugin, *targets) + def run(cfg, plugin, *targets) targets.each do |target| - # Why think too hard? An user has an @, a domain doesn't. - if target.include?('@') then - begin - user_description = plugin.describe_user(target) - plugin.delete_user(target) - report(plugin, "Removed user: #{target} (#{user_description})") + remove_target(plugin, target) + end + end + + private; + + def remove_target(plugin, target) + # Wrap the "remove this thing" operation so that it can be reused + # in the prine plugin. + target_description = plugin.describe(target) - rescue NonexistentUserError => e - report(plugin, "User not found: #{e.to_s}") - rescue StandardError => e - report(plugin, "There was an error removing the user: #{e.to_s}") - Kernel.exit(ExitCodes::DATABASE_ERROR) - end - else - begin - domain_description = plugin.describe_domain(target) - plugin.delete_domain(target) - report(plugin, "Removed domain: #{target} (#{domain_description})") + begin + plugin.delete(target) + msg = "Removed #{target.class.to_s().downcase()} #{target}" - rescue NonexistentUserError => e - # Can happen in the usernames.each... block. - report(plugin, "User not found: #{e.to_s}") - rescue NonexistentDomainError => e - report(plugin, "Domain not found: #{e.to_s}") - rescue StandardError => e - report(plugin, "There was an error removing the domain: #{e.to_s}") - Kernel.exit(ExitCodes::DATABASE_ERROR) - end + # Only append the extra description if it's useful. + if not target_description.nil? and + not target_description.empty? and + not target_description == target.to_s() then + msg += " (#{target_description})" end - end + msg += '.' + report(plugin, msg) + rescue NonexistentDomainError, NonexistentUserError => e + report(plugin, "#{target.class.to_s()} #{e.to_s} not found.") + end end - end