Changeset 918 for dasscm


Ignore:
Timestamp:
Jul 26, 2010, 6:16:32 PM (14 years ago)
Author:
joergs
Message:

make plugin support work, permissions are now also handeld by plugin, dasscm permissions outputs only to STDOUT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dasscm/trunk/usr/bin/dasscm

    r916 r918  
    162162    'permissions' => {
    163163        'desc' =>
    164           ["internal, used to update information about file permissions"],
     164          ["internal, print permissions for all files in the repository"],
    165165        'params'   => [],
    166166        'function' => \&permissions
     
    201201my $DASSCM_CHECKOUT_USERNAME;
    202202my $DASSCM_CHECKOUT_PASSWORD;
    203 my $DASSCM_PERMISSION_FILE;
     203my @DASSCM_ADDITIONAL_FILES;
    204204
    205205# current directory at program start
     
    369369        if ( not -d $DASSCM_REPO ) {
    370370            fatalerror(
    371               "Can't access local repository DASSCM_REPO",
    372               "($DASSCM_REPO)",
    373               "Check configuration and execute",
    374               "dasscm init"
     371                "Can't access local repository DASSCM_REPO",
     372                "($DASSCM_REPO)",
     373                "Check configuration and execute",
     374                "dasscm init"
    375375            );
    376376        }
     
    724724{
    725725    my $mode = shift;
    726     if( $mode ) {
    727         run_command( "stty echo" );
     726    if ($mode) {
     727        run_command("stty echo");
    728728    } else {
    729         run_command( "stty -echo" );
    730     }
    731 }
    732 
     729        run_command("stty -echo");
     730    }
     731}
    733732
    734733sub write_array_to_file( $@ )
    735734{
    736735    my $filename = shift;
    737     my @array = @_;
    738 
    739     if ( ! -w dirname($filename) ) {
     736    my @array    = @_;
     737
     738    if ( !-w dirname($filename) ) {
    740739        warning( "failed to write to $filename", "directory does not exist" );
    741740        return;
     
    743742
    744743    # directory exists => write
    745     if( ! open( OUTFILE, ">$filename" ) ) {
    746         warning( "failed to open $filename: $!" );
     744    if ( !open( OUTFILE, ">$filename" ) ) {
     745        warning("failed to open $filename: $!");
    747746        return;
    748747    }
     
    756755}
    757756
    758 
    759757sub perform_plugins()
    760758{
     
    765763    # get all defined plugins.
    766764    # Plugin definitions starting with DASSCM_PLUGIN_
    767     my @plugins = grep(/^DASSCM_PLUGIN_CMD_/,  keys( %{$config} ));
     765    my @plugins = grep( /^DASSCM_PLUGIN_CMD_/, keys( %{$config} ) );
    768766
    769767    for my $plugin (@plugins) {
    770         my $plugin_name = substr( $plugin, length( "DASSCM_PLUGIN_CMD_" ) );
    771         my $plugin_test = $config->{'DASSCM_PLUGIN_TEST_' . $plugin_name};
    772         ( my $rc_test, my @result_test ) = run_command( $plugin_test );
     768        my $plugin_name = substr( $plugin, length("DASSCM_PLUGIN_CMD_") );
     769        my $plugin_test = $config->{ 'DASSCM_PLUGIN_TEST_' . $plugin_name };
     770        ( my $rc_test, my @result_test ) = run_command($plugin_test);
    773771        if ($verbose) { print "Plugin $plugin_name: "; }
    774         if( $rc_test != 0 ) {
     772        if ( $rc_test != 0 ) {
    775773            if ($verbose) { print "skipped\n"; }
    776774        } else {
    777775            if ($verbose) { print "$config->{$plugin}\n"; }
    778776            ( my $rc, my @result ) = run_command( $config->{$plugin} );
    779             if( $rc != 0 ) {
    780                 warning( "failed to run plugin $plugin" );
     777            if ( $rc != 0 ) {
     778                warning("failed to run plugin $plugin");
    781779            } else {
    782                 my $plugin_result_file = $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name;
     780                my $plugin_result_file =
     781                  $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name;
    783782                write_array_to_file( $plugin_result_file, @result );
    784783                push @plugin_results, $plugin_result_file;
     
    788787    return @plugin_results;
    789788}
    790 
    791 
    792789
    793790sub svn_check_credentials( $$;$$ )
     
    10701067}
    10711068
     1069sub print_files_hash( $ )
     1070{
     1071    my $href_files = shift;
     1072
     1073    my @files = @{ $href_files->{files} };
     1074    my @links = @{ $href_files->{links} };
     1075
     1076    if (@files) {
     1077        my $number = $#files + 1;
     1078        print "files to check-in ($number): \n";
     1079        print join( "\n", @files );
     1080        print "\n";
     1081    }
     1082
     1083    # TODO: check in links and also link target? At least warn about link target
     1084    if (@links) {
     1085        my $number = $#links + 1;
     1086        print "\n";
     1087        print "ignoring links ($number):\n";
     1088        print join( "\n", @links );
     1089        print "\n";
     1090    }
     1091
     1092}
     1093
    10721094#
    10731095# use globbing to get lsit of files
     
    11401162    # hidden password input
    11411163    print "Enter password for $input_username: ";
    1142     setEchoMode( 0 );
     1164    setEchoMode(0);
    11431165    my $input_password = <STDIN>;
    1144     setEchoMode( 1 );
     1166    setEchoMode(1);
    11451167    chomp($input_password);
    11461168    print "\n";
     
    11831205
    11841206    # update complete repository
    1185     # and create permission file
    11861207    my $retcode = run_interactive(
    1187         "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; mkdir -p `dirname $DASSCM_PERMISSION_FILE`; touch $DASSCM_PERMISSION_FILE"
     1208        "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY"
    11881209    );
    11891210}
     
    12501271}
    12511272
     1273sub add_helper_multi(@)
     1274{
     1275
     1276    # get all regular files and links
     1277    my $href_files = get_files(@_);
     1278
     1279    #print Dumper( $href_files );
     1280
     1281    my @files = @{ $href_files->{files} };
     1282    my @links = @{ $href_files->{links} };
     1283
     1284    # copy files one by one to local repository
     1285    for my $file (@files) {
     1286
     1287        # add file
     1288        add_helper($file);
     1289    }
     1290
     1291    return $href_files;
     1292}
     1293
    12521294#
    12531295# adding new files (or directories)
     
    12631305    svn_update();
    12641306
    1265     # get all regular files and links
    1266     my $href_files = get_files(@_);
    1267 
    1268     #print Dumper( $href_files );
    1269 
    1270     my @files = @{ $href_files->{files} };
    1271     my @links = @{ $href_files->{links} };
    1272 
    1273     if (@files) {
    1274         my $number = $#files + 1;
    1275         print "files to check-in ($number): \n";
    1276         print join( "\n", @files );
    1277         print "\n";
    1278     }
    1279 
    1280     # TODO: check in links and also link target? At least warn about link target
    1281     if (@links) {
    1282         my $number = $#links + 1;
    1283         print "\n";
    1284         print "ignoring links ($number):\n";
    1285         print join( "\n", @links );
    1286         print "\n";
    1287     }
    1288 
    1289     # TODO: confirm
    1290 
    1291     # copy files one by one to local repository
    1292     for my $file (@files) {
    1293 
    1294         # add file
    1295         add_helper($file);
    1296     }
    1297 
    1298     # create new permissions file
    1299     permissions();
    1300 
    1301     # add permissions file
    1302     add_helper($DASSCM_PERMISSION_FILE);
    1303 
    1304     for my $file ( perform_plugins() ) {
    1305         add_helper($file);
    1306     }
    1307 
     1307    # add files to repository, print information about added files
     1308    print_files_hash( add_helper_multi(@_) );
     1309
     1310    # perform plugins and add additional files, like plugin results
     1311    perform_plugins();
     1312    add_helper_multi(@DASSCM_ADDITIONAL_FILES);
    13081313
    13091314    if ( $options{'message'} ) {
     
    13621367    }
    13631368
    1364     # create new permissions file
    1365     permissions();
    1366 
    1367     # add permissions file
    1368     add_helper($DASSCM_PERMISSION_FILE);
    1369 
    1370     for my $file ( perform_plugins() ) {
    1371         add_helper($file);
    1372     }
    1373 
    1374 
     1369    perform_plugins();
     1370    add_helper_multi(@DASSCM_ADDITIONAL_FILES);
    13751371
    13761372    if ( $options{'message'} ) {
     
    15261522    #svn_update( $filename_prod );
    15271523
    1528     # check, if permissions have changed
    1529     permissions();
     1524    # perform plugins (required to see changes in plugin results)
    15301525    perform_plugins();
    15311526
     
    15731568    my $return_string = "OK: no modified files";
    15741569
    1575     # check, if permissions have changed
    1576     permissions();
     1570    # perform plugins (required to see changes in plugin results)
    15771571    perform_plugins();
    15781572
     
    16251619    if (@files) {
    16261620
    1627         # generieren der Permissions
    1628         my @permissions = generatePermissionList(@files);
    1629         my $OUTFILE;
    1630         my $tofile = 0;    # Status für schreiben in File
    1631 
    1632         if ( -w dirname($DASSCM_PERMISSION_FILE) ) {
    1633 
    1634             # Verzeichnis existiert => schreiben
    1635             open( OUTFILE, ">$DASSCM_PERMISSION_FILE" )
    1636               || die("failed to write to $DASSCM_PERMISSION_FILE: $!");
    1637             $tofile = 1;    # Merken, daß in File geschrieben wird
    1638             print OUTFILE "#\n";
    1639             print OUTFILE "# created by dasscm permissions\n";
    1640             print OUTFILE
    1641               "# It is intended to be used for restoring permissions\n";
    1642             print OUTFILE "#\n";
    1643         } else {
    1644 
    1645             if ( $command eq "permission" ) {
    1646 
    1647                 # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout
    1648                 # Alias Filehandle für stdout erzeugen
    1649                 $return_code = $RETURN_WARN;
    1650                 *OUTFILE     = *STDOUT;
    1651             } else {
    1652 
    1653                 # TODO: improve this. Check for diff?
    1654                 $return_code = $RETURN_CRIT;
    1655                 return $return_code;
    1656             }
    1657         }
    1658 
    1659         foreach my $line (@permissions) {
    1660             print OUTFILE "$line\n";
    1661         }
    1662 
    1663         if ($tofile) {
    1664             close(OUTFILE);
    1665         }
     1621        print "#\n";
     1622        print "# created by dasscm permissions\n";
     1623        print "# It is intended to be used for restoring permissions\n";
     1624        print "#\n";
     1625
     1626        # generate and print permissions
     1627        foreach my $line ( generatePermissionList(@files) ) {
     1628            print "$line\n";
     1629        }
     1630
    16661631    }
    16671632
     
    18341799$DASSCM_REPOSITORY_NAME       = $config->{'DASSCM_REPOSITORY_NAME'};
    18351800
    1836 $DASSCM_PLUGIN_RESULTS_PATH = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/";
     1801$DASSCM_PLUGIN_RESULTS_PATH =
     1802  $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/";
     1803
     1804# get list of additional directories and files, seperated by blank (" ")
     1805# these files are always stored in subversion
     1806if ( $config->{'DASSCM_ADDITIONAL_FILES'} ) {
     1807    @DASSCM_ADDITIONAL_FILES = split / /, $config->{'DASSCM_ADDITIONAL_FILES'};
     1808} else {
     1809    @DASSCM_ADDITIONAL_FILES = ( $DASSCM_PLUGIN_RESULTS_PATH );
     1810}
    18371811
    18381812# TODO: check variables
     
    18561830}
    18571831
    1858 $DASSCM_PERMISSION_FILE = $config->{'DASSCM_PERMISSION_FILE'}
    1859   || "/etc/permissions.d/dasscm.permission_backup";
    18601832
    18611833# check for command options
Note: See TracChangeset for help on using the changeset viewer.