Changeset 916 for dasscm


Ignore:
Timestamp:
Jul 18, 2010, 9:20:40 PM (14 years ago)
Author:
joergs
Message:

added plugin support

Location:
dasscm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • dasscm/trunk/dasscm.spec

    r915 r916  
    1212Autoreqprov:    on
    1313Summary:        Dass Configuration Management
    14 Version:        1.0
     14Version:        1.1
    1515Release:        0
    1616Requires:       subversion perl
     
    5656install -m 640 etc/dasscm.conf $RPM_BUILD_ROOT/etc/
    5757mkdir -p $RPM_BUILD_ROOT/var/lib/dasscm/
     58mkdir -p $RPM_BUILD_ROOT/var/lib/dasscm/plugin-results/
    5859%if %(test -d /etc/bash_completion.d/ && echo 1 || echo 0)
    5960    %define use_bash_completion 1
     
    8081%defattr(-,root,root)
    8182%dir /var/lib/dasscm/
     83%dir /var/lib/dasscm/plugin-results/
    8284/usr/bin/dasscm
    8385/usr/bin/dasscm_remote_update.sh
  • dasscm/trunk/etc/dasscm.conf

    r882 r916  
    3737#
    3838DASSCM_PERMISSION_FILE="/etc/permissions.d/dasscm.permission_backup"
     39
     40#
     41# plugin definitions
     42#
     43DASSCM_PLUGIN_TEST_RPMLIST="type rpm && test /var/lib/rpm/Packages -nt /var/lib/dasscm/plugin-results/RPMLIST"
     44DASSCM_PLUGIN_CMD_RPMLIST="rpm -qa --last"
  • dasscm/trunk/usr/bin/dasscm

    r915 r916  
    6464    'complete_path'     => 'complete_path',
    6565    'complete_repopath' => 'complete_repopath',
     66    'plugins'           => 'plugins',
    6667);
    6768
     
    185186        'function' => \&complete_repopath
    186187    },
     188    'plugins' => {
     189        'desc'     => ["internal, perform plugins"],
     190        'params'   => [],
     191        'function' => \&perform_plugins
     192    },
     193
    187194);
    188195
     
    190197my $DASSCM_LOCAL_REPOSITORY_BASE;
    191198my $DASSCM_REPOSITORY_NAME;
     199my $DASSCM_PLUGIN_RESULTS_PATH;
    192200my $DASSCM_SVN_REPOSITORY;
    193201my $DASSCM_CHECKOUT_USERNAME;
     
    360368    if ( $command ne "init" ) {
    361369        if ( not -d $DASSCM_REPO ) {
    362             die
    363               "Can't access local repository DASSCM_REPO\n($DASSCM_REPO)\nCheck configuration and execute\n    dasscm init\n";
     370            fatalerror(
     371              "Can't access local repository DASSCM_REPO",
     372              "($DASSCM_REPO)",
     373              "Check configuration and execute",
     374              "dasscm init"
     375            );
    364376        }
    365377
     
    705717}
    706718
     719#
     720# en- or disable echo mode.
     721# used for reading passwords from STDIN
     722#
     723sub setEchoMode( $ )
     724{
     725    my $mode = shift;
     726    if( $mode ) {
     727        run_command( "stty echo" );
     728    } else {
     729        run_command( "stty -echo" );
     730    }
     731}
     732
     733
     734sub write_array_to_file( $@ )
     735{
     736    my $filename = shift;
     737    my @array = @_;
     738
     739    if ( ! -w dirname($filename) ) {
     740        warning( "failed to write to $filename", "directory does not exist" );
     741        return;
     742    }
     743
     744    # directory exists => write
     745    if( ! open( OUTFILE, ">$filename" ) ) {
     746        warning( "failed to open $filename: $!" );
     747        return;
     748    }
     749
     750    foreach my $line (@array) {
     751        print OUTFILE "$line";
     752    }
     753    close(OUTFILE);
     754
     755    return 1;
     756}
     757
     758
     759sub perform_plugins()
     760{
     761    check_env();
     762
     763    my @plugin_results = ();
     764
     765    # get all defined plugins.
     766    # Plugin definitions starting with DASSCM_PLUGIN_
     767    my @plugins = grep(/^DASSCM_PLUGIN_CMD_/,  keys( %{$config} ));
     768
     769    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 );
     773        if ($verbose) { print "Plugin $plugin_name: "; }
     774        if( $rc_test != 0 ) {
     775            if ($verbose) { print "skipped\n"; }
     776        } else {
     777            if ($verbose) { print "$config->{$plugin}\n"; }
     778            ( my $rc, my @result ) = run_command( $config->{$plugin} );
     779            if( $rc != 0 ) {
     780                warning( "failed to run plugin $plugin" );
     781            } else {
     782                my $plugin_result_file = $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name;
     783                write_array_to_file( $plugin_result_file, @result );
     784                push @plugin_results, $plugin_result_file;
     785            }
     786        }
     787    }
     788    return @plugin_results;
     789}
     790
     791
     792
    707793sub svn_check_credentials( $$;$$ )
    708794{
     
    10531139
    10541140    # hidden password input
    1055     print "Enter password stty for $input_username: ";
    1056     #ReadMode('noecho');
    1057     `stty -echo`;
     1141    print "Enter password for $input_username: ";
     1142    setEchoMode( 0 );
    10581143    my $input_password = <STDIN>;
    1059     #ReadMode('normal');
    1060     `stty echo`;
     1144    setEchoMode( 1 );
    10611145    chomp($input_password);
    10621146    print "\n";
     
    12181302    add_helper($DASSCM_PERMISSION_FILE);
    12191303
     1304    for my $file ( perform_plugins() ) {
     1305        add_helper($file);
     1306    }
     1307
     1308
    12201309    if ( $options{'message'} ) {
    12211310        $svnOptions .= " --message \"$options{'message'}\" ";
     
    12781367    # add permissions file
    12791368    add_helper($DASSCM_PERMISSION_FILE);
     1369
     1370    for my $file ( perform_plugins() ) {
     1371        add_helper($file);
     1372    }
     1373
     1374
    12801375
    12811376    if ( $options{'message'} ) {
     
    14331528    # check, if permissions have changed
    14341529    permissions();
     1530    perform_plugins();
    14351531
    14361532    # get modified files
     
    14791575    # check, if permissions have changed
    14801576    permissions();
     1577    perform_plugins();
    14811578
    14821579    # get modified files
     
    17371834$DASSCM_REPOSITORY_NAME       = $config->{'DASSCM_REPOSITORY_NAME'};
    17381835
     1836$DASSCM_PLUGIN_RESULTS_PATH = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/";
     1837
    17391838# TODO: check variables
    17401839$DASSCM_SVN_REPOSITORY =
Note: See TracChangeset for help on using the changeset viewer.