]> Frank Brehm's Git Trees - my-stuff/postfix-maps.git/commitdiff
Testmodus und force dazu
authorFrank Brehm <frank@brehm-online.com>
Fri, 6 Aug 2010 09:26:28 +0000 (09:26 +0000)
committerFrank Brehm <frank@brehm-online.com>
Fri, 6 Aug 2010 09:26:28 +0000 (09:26 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/postfix-maps/trunk@111 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

lib/FrBr/Postfix/App.pm

index df21c2cc680399b99033c668369c8962a900e210..82284f082c6e45620d09369d9e22815905d54569 100644 (file)
@@ -69,6 +69,7 @@ has 'postfix_dir' => (
     required        => 1,
     builder         => '_build_postfixdir',
     documentation   => 'Stammverzeichnis der Anwendung',
+    cmd_flag        => 'postfix-dir',
     cmd_aliases     => [ 'postfix' ],
 );
 
@@ -95,6 +96,7 @@ has 'work_dir' => (
     required        => 1,
     builder         => '_build_workdir',
     documentation   => 'Arbeitsverzeichnis zum zeitweiligen Auschecken, absolut oder relativ zu postfix_dir',
+    cmd_flag        => 'work-dir',
     cmd_aliases     => [ 'work' ],
 );
 
@@ -152,6 +154,31 @@ sub _build_postfix_maps {
 
 #-----------------------------------------
 
+=head2 force_action
+
+Sollen die Map-Dateien geschrieben werden, auch wenn sie sich nicht geändert haben?
+
+=cut
+
+has 'force_action' => (
+    is              => 'rw',
+    isa             => 'Bool',
+    traits          => [ 'Getopt' ],
+    lazy            => 1,
+    builder         => '_build_force_action',
+    documentation   => 'Sollen die Map-Dateien geschrieben werden, auch wenn sie sich nicht geändert haben?',
+    cmd_flag        => 'force-action',
+    cmd_aliases     => [ 'f', 'force', ],
+);
+
+#------
+
+sub _build_force_action {
+    return 0;
+}
+
+#-----------------------------------------
+
 =head2 valid_maptypes
 
 HashRef mit allen gültigen Map-Typen
@@ -538,6 +565,7 @@ sub run {
     my $self = shift;
 
     $self->info( "Beginne Checkout der Mappings." );
+    $self->info( "Testmodus - keine scharfen Änderungen." ) if $self->testmode;
 
     # nur Root darf das Skript in der Produktionsversion ausführen
     if ( $self->production_state eq 'prod' and $> != 0 ) {
@@ -694,24 +722,32 @@ sub do_mapping {
     my $binary = $self->postfix_binary;
 
     $changed = 1 unless -f $map->{'mapfile'};
-    $changed = 1 if $self->_diff_files( $map->{'workfile'}, $map->{'mapfile'}, $map->{'text_type'} );
-    $self->debug( sprintf( "Mapping '%s' hat sich %s.", $mapname, ( $changed ? 'GEÄNDERT' : 'NICHT VERÄNDERT' ) ) );
+    if ( $self->force_action ) {
+        $changed = 1
+    }
+    else {
+        $changed = 1 if $self->_diff_files( $map->{'workfile'}, $map->{'mapfile'}, $map->{'text_type'} );
+        $self->debug( sprintf( "Mapping '%s' hat sich %s.", $mapname, ( $changed ? 'GEÄNDERT' : 'NICHT VERÄNDERT' ) ) );
+    }
 
     if ( $changed ) {
 
         $self->info( sprintf( "Aktualisiere Mapping '%s' in Datei '%s' ...", $mapname, $map->{'mapfile'} ) );
 
         $self->debug( sprintf( "Kopiere Datei '%s' nach '%s' ...", $map->{'workfile'}, $map->{'mapfile'} ) );
-        copy $map->{'workfile'}, $map->{'mapfile'};
+
+        copy $map->{'workfile'}, $map->{'mapfile'} unless $self->testmode;
 
         if ( $map->{'exec_map'} ) {
 
             my $cmd = $map->{'text_type'} eq 'aliases' ? $binary->{'postalias'} : $binary->{'postmap'};   
             my @Args = ( $cmd, $map->{'db_type'} . ":" . $map->{'mapfile'} );
             $self->debug( sprintf( "Führe Kommando aus: '%s'", join( " ", @Args ) ) );
-            unless ( system(@Args) == 0 ) {
-                $self->error( sprintf( "Fehler beim Ausführen von '%s'.", join( " ", @Args ) ) );
-                return undef;
+            unless ( $self->testmode ) {
+                unless ( system(@Args) == 0 ) {
+                    $self->error( sprintf( "Fehler beim Ausführen von '%s'.", join( " ", @Args ) ) );
+                    return undef;
+                }
             }
         }