X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fprune%2Fprune_dummy_runner.rb;h=f90c9d06c50f774eb61e41d3970770cc4b1893d9;hp=4274bef8f08db79990e9e98cc42e15d2c129619e;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=4e7ef12d3d47aa7ec68419de46c51269c40eb158 diff --git a/lib/prune/prune_dummy_runner.rb b/lib/prune/prune_dummy_runner.rb index 4274bef..f90c9d0 100644 --- a/lib/prune/prune_dummy_runner.rb +++ b/lib/prune/prune_dummy_runner.rb @@ -1,32 +1,44 @@ require 'common/runner' - -# This is always needed, regardless of which plugin is running. require 'prune/plugins/postfixadmin' +require 'rm/rm_dummy_runner' +# Dummy implementation of a {PruneRunner}. Its run() method will +# tell you what would have been pruned, but will not actually perform +# the operation. +# class PruneDummyRunner include Runner - def run(plugin) + + # Pretend to prune unused domains and users. Some "what if" + # information will be output to stdout. + # + # The prune mode is the main application of the "dummy" runners, + # since it performs some computation outside of the plugins + # themselves. This lets the user know which users and domains would + # be removed and can help prevent mistakes or even find bugs in the + # prune code, if it looks like something will be removed that + # shouldn't be! + # + # @param cfg [Configuration] the configuration options to pass to + # the *plugin* we're runnning. + # + # @param plugin [Class] plugin class that will do the pruning. + # + def run(cfg, plugin) # We don't want to check the PostfixAdmin database against itself. return if plugin.class == PostfixadminPrune - pfa = PostfixadminPrune.new() + pfa = PostfixadminPrune.new(cfg) db_users = pfa.list_users() db_domains = pfa.list_domains() - leftover_users = plugin.get_leftover_accounts(db_users) - leftover_domains = plugin.get_leftover_domains(db_domains) - - leftover_users.each do |user| - user_description = plugin.describe_account(user) - report(plugin, "Would remove user: #{user} (#{user_description})") - end + leftovers = plugin.get_leftover_users(db_users) + leftovers += plugin.get_leftover_domains(db_domains) - leftover_domains.each do |domain| - domain_description = plugin.describe_domain(domain) - report(plugin, "Would remove domain: #{domain} (#{domain_description})") - end + rm_dummy_runner = RmDummyRunner.new() + rm_dummy_runner.run(cfg, plugin, *leftovers) end end