X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Frm_runner.rb;h=2df8410c5ea9d6d3d65d2565ec9cc00552d7b1f0;hp=039ae61f7d489c9a0a7807608b959fd912f3c99c;hb=f819b178c5c1cb8adda0182c610e5c52fad8bea7;hpb=a6ae98f0423603445b621a8eaa17443c8d590b45 diff --git a/lib/rm/rm_runner.rb b/lib/rm/rm_runner.rb index 039ae61..2df8410 100644 --- a/lib/rm/rm_runner.rb +++ b/lib/rm/rm_runner.rb @@ -1,32 +1,37 @@ +require 'common/errors' +require 'common/runner' + class RmRunner include Runner - def run(plugin, targets) + def run(plugin, *targets) targets.each do |target| - # Why think too hard? An account has an @, a domain doesn't. - if target.include?('@') then - begin - account_description = plugin.describe_account(target) - plugin.delete_account(target) - puts "Removed account: #{target} (#{account_description})" - rescue StandardError => e - puts "There was an error removing the account: #{e.to_s}" - Kernel.exit(ExitCodes::DATABASE_ERROR) - end - else - begin - # TODO: Delete all accounts first. - domain_description = plugin.describe_domain(target) - plugin.delete_domain(target) - puts "Removed domain: #{target} (#{domain_description})" - rescue StandardError => e - puts "There was an error removing the domain: #{e.to_s}" - Kernel.exit(ExitCodes::DATABASE_ERROR) - end - end + remove_target(plugin, target) end - - # TODO: remove from postfixadmin as well. 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) + + begin + plugin.delete(target) + msg = "Removed #{target.class.to_s().downcase()} #{target}" + + # 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 + msg += '.' + + report(plugin, msg) + rescue NonexistentDomainError, NonexistentUserError => e + report(plugin, "#{target.class.to_s()} #{e.to_s} not found.") + end + end end