From c6cab6b71770d14dad1115db90a00b990c44a58d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 19 Mar 2013 14:38:35 -0400 Subject: [PATCH] Factor out common code that can be used to mv (rename) accounts. Separate Plugin/RmPlugin modules. --- lib/{mailshears => common}/configuration.rb | 0 lib/{mailshears => common}/errors.rb | 0 lib/{mailshears => common}/exit_codes.rb | 0 lib/{mailshears => common}/filesystem.rb | 0 lib/{mailshears => common}/mailstore.rb | 0 lib/{mailshears => common}/plugin.rb | 21 ---------------- lib/mailshears.rb | 11 +++++---- lib/mailshears/plugins/agendav.rb | 4 +++ lib/mailshears/plugins/davical.rb | 4 +++ lib/mailshears/plugins/dovecot_mailstore.rb | 10 ++++---- lib/mailshears/plugins/roundcube_db.rb | 4 +++ lib/mailshears/rm_plugin.rb | 27 +++++++++++++++++++++ 12 files changed, 50 insertions(+), 31 deletions(-) rename lib/{mailshears => common}/configuration.rb (100%) rename lib/{mailshears => common}/errors.rb (100%) rename lib/{mailshears => common}/exit_codes.rb (100%) rename lib/{mailshears => common}/filesystem.rb (100%) rename lib/{mailshears => common}/mailstore.rb (100%) rename lib/{mailshears => common}/plugin.rb (59%) create mode 100644 lib/mailshears/rm_plugin.rb diff --git a/lib/mailshears/configuration.rb b/lib/common/configuration.rb similarity index 100% rename from lib/mailshears/configuration.rb rename to lib/common/configuration.rb diff --git a/lib/mailshears/errors.rb b/lib/common/errors.rb similarity index 100% rename from lib/mailshears/errors.rb rename to lib/common/errors.rb diff --git a/lib/mailshears/exit_codes.rb b/lib/common/exit_codes.rb similarity index 100% rename from lib/mailshears/exit_codes.rb rename to lib/common/exit_codes.rb diff --git a/lib/mailshears/filesystem.rb b/lib/common/filesystem.rb similarity index 100% rename from lib/mailshears/filesystem.rb rename to lib/common/filesystem.rb diff --git a/lib/mailshears/mailstore.rb b/lib/common/mailstore.rb similarity index 100% rename from lib/mailshears/mailstore.rb rename to lib/common/mailstore.rb diff --git a/lib/mailshears/plugin.rb b/lib/common/plugin.rb similarity index 59% rename from lib/mailshears/plugin.rb rename to lib/common/plugin.rb index 2e868c2..0687989 100644 --- a/lib/mailshears/plugin.rb +++ b/lib/common/plugin.rb @@ -28,25 +28,4 @@ module Plugin raise NotImplementedError end - def delete_domain(domain) - # Delete the given domain. - raise NotImplementedError - end - - def delete_account(account) - # Delete the given account. - raise NotImplementedError - end - - def get_leftover_domains(db_domains) - # Given a list of domains, determine which domains belonging to - # this plugin are not contained in the given list. - raise NotImplementedError - end - - def get_leftover_accounts(db_accounts) - # Given a list of accounts, determine which accounts belonging to - # this plugin are not contained in the given list. - raise NotImplementedError - end end diff --git a/lib/mailshears.rb b/lib/mailshears.rb index 287ee2b..cb8e43c 100644 --- a/lib/mailshears.rb +++ b/lib/mailshears.rb @@ -1,9 +1,10 @@ -# Load the rest of the code we'll use. +# Load the rest of the code we'll use. This loads what we'll need in +# the executables; the library files are supposed to require what they +# need. -# And the necessary classes. -require 'mailshears/configuration' -require 'mailshears/errors' -require 'mailshears/exit_codes' +require 'common/configuration' +require 'common/errors' +require 'common/exit_codes' require 'mailshears/postfixadmin_db' cfg = Configuration.new() diff --git a/lib/mailshears/plugins/agendav.rb b/lib/mailshears/plugins/agendav.rb index 9746f1c..3578302 100644 --- a/lib/mailshears/plugins/agendav.rb +++ b/lib/mailshears/plugins/agendav.rb @@ -1,8 +1,12 @@ require 'pg' +require 'common/plugin' +require 'mailshears/rm_plugin' + class AgendavDb include Plugin + include RmPlugin def initialize() cfg = Configuration.new() diff --git a/lib/mailshears/plugins/davical.rb b/lib/mailshears/plugins/davical.rb index 0c63ee2..2091529 100644 --- a/lib/mailshears/plugins/davical.rb +++ b/lib/mailshears/plugins/davical.rb @@ -1,11 +1,15 @@ require 'pg' +require 'common/plugin' +require 'mailshears/rm_plugin' + class DavicalDb # # DAViCal only supports Postgres, so even if we ever are # database-agnostic, this plugin can't be. # include Plugin + include RmPlugin def initialize() cfg = Configuration.new() diff --git a/lib/mailshears/plugins/dovecot_mailstore.rb b/lib/mailshears/plugins/dovecot_mailstore.rb index cf4711c..635d6ef 100644 --- a/lib/mailshears/plugins/dovecot_mailstore.rb +++ b/lib/mailshears/plugins/dovecot_mailstore.rb @@ -1,15 +1,15 @@ # Needed for rm_rf. require 'fileutils' -require 'mailshears/configuration' -require 'mailshears/errors' -require 'mailshears/filesystem' -require 'mailshears/mailstore' -require 'mailshears/plugin' +require 'common/filesystem' +require 'common/mailstore' +require 'common/plugin' +require 'mailshears/rm_plugin' class DovecotMailstore < Mailstore include Plugin + include RmPlugin def initialize cfg = Configuration.new() diff --git a/lib/mailshears/plugins/roundcube_db.rb b/lib/mailshears/plugins/roundcube_db.rb index 7d1a037..a930189 100644 --- a/lib/mailshears/plugins/roundcube_db.rb +++ b/lib/mailshears/plugins/roundcube_db.rb @@ -1,8 +1,12 @@ require 'pg' +require 'common/plugin' +require 'mailshears/rm_plugin' + class RoundcubeDb include Plugin + include RmPlugin def initialize() cfg = Configuration.new() diff --git a/lib/mailshears/rm_plugin.rb b/lib/mailshears/rm_plugin.rb new file mode 100644 index 0000000..0c155a1 --- /dev/null +++ b/lib/mailshears/rm_plugin.rb @@ -0,0 +1,27 @@ +module RmPlugin + # + # Plugins for the removal of accounts. + # + + def delete_domain(domain) + # Delete the given domain. + raise NotImplementedError + end + + def delete_account(account) + # Delete the given account. + raise NotImplementedError + end + + def get_leftover_domains(db_domains) + # Given a list of domains, determine which domains belonging to + # this plugin are not contained in the given list. + raise NotImplementedError + end + + def get_leftover_accounts(db_accounts) + # Given a list of accounts, determine which accounts belonging to + # this plugin are not contained in the given list. + raise NotImplementedError + end +end -- 2.44.2