From 5bc497180d3d6198f723a0539f6fe5aa59985ec3 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 16 Jul 2010 10:44:19 +0000 Subject: [PATCH] Mit Konstruktion begonnen git-svn-id: http://svn.brehm-online.com/svn/my-stuff/postfix-maps/trunk@97 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- bin/checkout-postfix-mappings.pl | 44 +++++++ etc/config.yml | 12 ++ etc/log4perl.conf | 57 +++++++++ lib/FrBr/Postfix/App.pm | 199 +++++++++++++++++++++++++++++++ 4 files changed, 312 insertions(+) create mode 100755 bin/checkout-postfix-mappings.pl create mode 100644 etc/config.yml create mode 100644 etc/log4perl.conf create mode 100644 lib/FrBr/Postfix/App.pm diff --git a/bin/checkout-postfix-mappings.pl b/bin/checkout-postfix-mappings.pl new file mode 100755 index 0000000..7c2a17e --- /dev/null +++ b/bin/checkout-postfix-mappings.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +# $Id$ +# $URL$ + +use strict; +use warnings; + +use utf8; + +use Encode qw( decode_utf8 encode_utf8 ); +use Data::Dumper; + +$Data::Dumper::Indent = 1; +$Data::Dumper::Sortkeys = 1; + +# Own modules +use FindBin; +use lib "$FindBin::Bin/../lib"; + +#use FrBr::Postfix::App; +require FrBr::Postfix::App; + +use version; our $VERSION = qv("0.0.2"); + +my $opts = { + 'progname' => 'checkout-postfix-mappings', +}; + +my $app = FrBr::Postfix::App->new_with_options(%$opts); + +#print Dumper($app); + +$app->run(); + +exit($app->exit_code); +#exit 0; + + +#-------------------------------------------------------------------------------- + +__END__ + +# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab : diff --git a/etc/config.yml b/etc/config.yml new file mode 100644 index 0000000..6d3b939 --- /dev/null +++ b/etc/config.yml @@ -0,0 +1,12 @@ +# +# Zentrale Konfiguration des Postfix-Mapping-Checkout-Tools +# +# partielle lokale Änderungen können in einer 'config_local.yml' vorgenommen werden +# +# $Id: config.yml 512 2010-05-05 08:00:18Z fbrehm $ +# $URL: http://svn.technik.berlin.strato.de/svn-os/trunk/sd-mailversand/etc/config.yml $ +# +--- +# Produktionsstatus: Darf nur 'prod', 'test' oder 'dev' annehmen. +#production_state: prod +# diff --git a/etc/log4perl.conf b/etc/log4perl.conf new file mode 100644 index 0000000..a654870 --- /dev/null +++ b/etc/log4perl.conf @@ -0,0 +1,57 @@ +############################################################################## +# +# Log-Konfiguration für Log::Log4perl +# +# Diese Konfiguration kann von einer log4perl_local.conf überschrieben werden. +# (Kein Merging! - Siehe Log::Log4perl zu Details der Konfiguration) +# +# $Id$ +# $URL$ +# +############################################################################## + +# Root-Logger +log4perl.rootLogger = INFO, ScreenApp + +# Normaler Screen-Appender auf StdErr +log4perl.appender.ScreenApp = Log::Log4perl::Appender::Screen +log4perl.appender.ScreenApp.stderr = 1 +log4perl.appender.ScreenApp.utf8 = 1 +log4perl.appender.ScreenApp.layout = PatternLayout +log4perl.appender.ScreenApp.layout.ConversionPattern = [%d] [Backup] [%p] %m%n + +########################### +# Alternativ mit zwei Appendern + +# Root-Logger +#log4perl.rootLogger = DEBUG, ScreenApp, FileApp + +#layout_class = Log::Log4perl::Layout::PatternLayout +#layout_pattern = [%d] [Backup] [%p] %m%n + +# Filterdefinition für den Screen-Appender +#log4perl.filter.InfoFilter = Log::Log4perl::Filter::LevelRange +#log4perl.filter.InfoFilter.LevelMin = INFO +#log4perl.filter.InfoFilter.LevelMax = FATAL +#log4perl.filter.InfoFilter.AcceptOnMatch = true + +# Normaler Screen-Appender auf StdErr +#log4perl.appender.ScreenApp = Log::Log4perl::Appender::Screen +#log4perl.appender.ScreenApp.stderr = 1 +#log4perl.appender.ScreenApp.utf8 = 1 +#log4perl.appender.ScreenApp.Filter = InfoFilter +#log4perl.appender.ScreenApp.layout = ${layout_class} +#log4perl.appender.ScreenApp.layout.ConversionPattern = ${layout_pattern} + +# Und der File-Appender für alles +#log4perl.appender.FileApp = Log::Log4perl::Appender::File +#log4perl.appender.FileApp.filename = /var/www/irgendwo/log/debug.log +#log4perl.appender.FileApp.mode = append +#log4perl.appender.FileApp.umask = 0222 +#log4perl.appender.FileApp.utf8 = 1 +#log4perl.appender.FileApp.recreate = 1 +#log4perl.appender.FileApp.recreate_check_interval = 60 +#log4perl.appender.FileApp.recreate_check_signal = USR1 +#log4perl.appender.FileApp.layout = ${layout_class} +#log4perl.appender.FileApp.layout.ConversionPattern = ${layout_pattern} + diff --git a/lib/FrBr/Postfix/App.pm b/lib/FrBr/Postfix/App.pm new file mode 100644 index 0000000..b7ecee1 --- /dev/null +++ b/lib/FrBr/Postfix/App.pm @@ -0,0 +1,199 @@ +package FrBr::Postfix::App; + +# $Id$ +# $URL$ + +=head1 NAME + +FrBr::Postfix::App + +=head1 DESCRIPTION + +Basismodul fuer Postfix-Map-Auslagern-Anwendung + +=cut + +#--------------------------------------------------------------------------- + +use Moose; +use MooseX::StrictConstructor; + +use utf8; + +use MooseX::Types::Path::Class; +use Path::Class; + +extends 'FrBr::Common::MooseX::App'; + +with 'FrBr::Common::MooseX::Role::Config'; +with 'FrBr::Common::MooseX::Role::DbSchema'; + +#----------------------------------------- + +# Versionitis + +my $Revis = <<'ENDE'; + $Revision$ +ENDE +$Revis =~ s/^.*:\s*(\S+)\s*\$.*/$1/s; + +use version; our $VERSION = qv("0.9.1"); $VERSION .= " r" . $Revis; + +############################################################################ + +=head1 ATTRIBUTES + +Alle für dieses allgemeine Anwendungsobjekt definierten Attribute/Eigenschaften, +die nicht durch dazugehörige Rollen definiert werden. + +=cut + +#------------------------- + +=head2 postfix_dir + +Konfigurationsverzeichnis von Postfix, normalerweise '/etc/postfix' + +=cut + +has 'postfix_dir' => ( + is => 'rw', + isa => 'Path::Class::Dir', + traits => [ 'Getopt' ], + coerce => 1, + lazy => 1, + required => 1, + builder => '_build_postfixdir', + documentation => 'Stammverzeichnis der Anwendung', + cmd_aliases => [ 'postfix' ], +); + +#------ + +sub _build_postfixdir { + return dir->new( '/etc/postfix' ); +} + +########################################################################### + +=head1 METHODS + +Spezielle Methoden und Methodenmodifizierer dieser Anwendung + +=cut + +#--------------------------------- + +around BUILDARGS => sub { + + my $orig = shift; + my $class = shift; + + my %Args = @_; + + #warn "Bin in '" . __PACKAGE__ . "'\n"; + + return $class->$orig(%Args); + +}; + +#--------------------------------- + +sub BUILD { + + my $self = shift; + + #warn "Bin in '" . __PACKAGE__ . "::BUILD'\n"; + +} + +#--------------------------------------------------------------------------- + +after 'evaluate_config' => sub { + + my $self = shift; + + #return if $self->configuration_evaluated; + $self->debug( "Werte Backup-Konfigurationsdinge aus ..." ); + return unless $self->config and keys %{ $self->config }; + + my @ConfigKeys = qw( postfix_dir ); + + for my $key ( keys %{ $self->config } ) { + + my $val = $self->config->{$key}; + + for my $p ( @ConfigKeys ) { + my $f = $p; + my $r = $p; + $r =~ s/_/\[_-\]\?/g; + $r = "^$r\$"; + $self->debug( sprintf( "Regex 1: '%s'", $r ) ) if $self->verbose >= 4; + unless ( $self->used_cmd_params->{$f} ) { + if ( $key =~ /$r/i ) { + $self->debug( sprintf( "Gefunden: \$self->config->{%s} -> '%s'", $key, ( defined $val ? $val : '' ) ) ) if $self->verbose >= 2; + $self->$f($val); + } + } + } + + } + + unless ( $self->postfix_dir->is_absolute ) { + my $d = $self->postfix_dir; + $d = dir( $self->basedir, $self->postfix_dir )->absolute; + $self->postfix_dir($d); + $self->debug( sprintf( "Setze Postfix-Dir auf '%s' ...", $d ) ) if $self->verbose >= 2; + } + + +}; + +#--------------------------------------------------------------------------- + +after 'init_app' => sub { + + my $self = shift; + + return if $self->app_initialized; + + $self->debug( "Initialisiere ..." ); + + if ( $self->verbose >= 2 ) { + + my $tmp; + for my $f ( 'postfix_dir', ) { + $tmp = $self->$f(); + } + + } + +}; + +#--------------------------------- + +=head2 run( ) + +Die eigentliche Startroutine der Anwendung. + +=cut + +sub run { + + my $self = shift; + + $self->info( "Beginne Checkout der Mappings." ); + +} + +#--------------------------------- + +__PACKAGE__->meta->make_immutable; + +1; + +#------------------------------------------------------------------------------------------ + +__END__ + +# vim: noai: filetype=perl ts=4 sw=4 : expandtab -- 2.39.5