Changeset 889 for dasscm/trunk/usr


Ignore:
Timestamp:
Jun 26, 2010, 12:19:34 AM (14 years ago)
Author:
joergs
Message:

perltidy

File:
1 edited

Legend:

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

    r888 r889  
    1111use File::Basename;
    1212use File::Compare;
    13 # used system("cp -a"), because File::Copy does not keep permissions
     13
     14# used system("cp -a"), because File::Copy does not keep permissions
    1415#use File::Copy;
    1516use File::Find;
     
    4041my $config      = get_config($config_file);
    4142
    42 
    43 
    4443my %COMMANDS = (
    45     '--help' => 'help',
    46     'help' => 'help',
    47     'login' => 'login',
    48     'init' => 'init',
    49     'ls' => 'ls',
    50     'update' => 'update',
    51     'up' => 'update',
    52     'add' => 'add',
    53     'commit' => 'commit',
    54     'checkin' => 'commit',
    55     'ci' => 'commit',
    56     'revert' => 'revert',
    57     'blame' => 'blame',
    58     'diff' => 'diff',
    59     'status' => 'status',
    60     'st' => 'status',
    61     'check' => 'check',
    62     'permissions' => 'permissions',
    63     'cleanup' => 'cleanup',
    64     'complete' => 'complete',
    65     'complete_path' => 'complete_path',
     44    '--help'            => 'help',
     45    'help'              => 'help',
     46    'login'             => 'login',
     47    'init'              => 'init',
     48    'ls'                => 'ls',
     49    'update'            => 'update',
     50    'up'                => 'update',
     51    'add'               => 'add',
     52    'commit'            => 'commit',
     53    'checkin'           => 'commit',
     54    'ci'                => 'commit',
     55    'revert'            => 'revert',
     56    'blame'             => 'blame',
     57    'diff'              => 'diff',
     58    'status'            => 'status',
     59    'st'                => 'status',
     60    'check'             => 'check',
     61    'permissions'       => 'permissions',
     62    'cleanup'           => 'cleanup',
     63    'complete'          => 'complete',
     64    'complete_path'     => 'complete_path',
    6665    'complete_repopath' => 'complete_repopath',
    6766);
     
    7372#           PATH
    7473#           REPOPATH
    75 # require: 
     74# require:
    7675#           WRITE commands that require write access (and therefore a login)
    7776my %COMMAND_DEFINITIONS = (
    7877    'help' => {
    79         'desc' => [],
    80         'params' => [ "CMD" ],
     78        'desc'     => [],
     79        'params'   => ["CMD"],
    8180        'function' => \&help,
    8281    },
    8382    'login' => {
    84         'desc' => [],
    85         'params' => [ "USER" ],
     83        'desc'     => [],
     84        'params'   => ["USER"],
    8685        'function' => \&login
    8786    },
    8887    'init' => {
    89         'desc' => [ "initialize local subversion checkout.", "This is the first thing to do (after configuring $config_file)" ],
    90         'params' => [],
     88        'desc' => [
     89            "initialize local subversion checkout.",
     90            "This is the first thing to do (after configuring $config_file)"
     91        ],
     92        'params'   => [],
    9193        'function' => \&init
    9294    },
    9395    'ls' => {
    94         'desc' => [],
    95         'params' => [ "REPOPATH" ],
     96        'desc'     => [],
     97        'params'   => ["REPOPATH"],
    9698        'function' => \&ls
    9799    },
    98100    'update' => {
    99         'desc' => [],
    100         'params' => [ "PATH" ],
     101        'desc'     => [],
     102        'params'   => ["PATH"],
    101103        'function' => \&update
    102104    },
    103105    'add' => {
    104         'desc' => [],
    105         'params' => [ "PATH" ],
    106         'require' => [ "WRITE" ],
     106        'desc'     => [],
     107        'params'   => ["PATH"],
     108        'require'  => ["WRITE"],
    107109        'function' => \&add
    108110    },
    109111    'commit' => {
    110         'desc' => [],
    111         'params' => [ "REPOPATH" ],
    112         'require' => [ "WRITE" ],
     112        'desc'     => [],
     113        'params'   => ["REPOPATH"],
     114        'require'  => ["WRITE"],
    113115        'function' => \&commit
    114116    },
    115117    'revert' => {
    116         'desc' => [ "revert local changes back to version from repository" ],
    117         'params' => [ "REPOPATH" ],
     118        'desc'     => ["revert local changes back to version from repository"],
     119        'params'   => ["REPOPATH"],
    118120        'function' => \&revert
    119121    },
    120122    'blame' => {
    121         'desc' => [],
    122         'params' => [ "PATH" ],
     123        'desc'     => [],
     124        'params'   => ["PATH"],
    123125        'function' => \&blame
    124126    },
    125127    'diff' => {
    126         'desc' => [],
    127         'params' => [ "PATH" ],
     128        'desc'     => [],
     129        'params'   => ["PATH"],
    128130        'function' => \&diff
    129131    },
    130132    'status' => {
    131         'desc' => [],
    132         'params' => [ "PATH" ],
     133        'desc'     => [],
     134        'params'   => ["PATH"],
    133135        'function' => \&status
    134136    },
    135137    'check' => {
    136         'desc' => [ "perform Nagios NRPE conform check" ],
    137         'params' => [],
     138        'desc'     => ["perform Nagios NRPE conform check"],
     139        'params'   => [],
    138140        'function' => \&check
    139141    },
    140142    'permissions' => {
    141         'desc' => [],
    142         'params' => [],
     143        'desc'     => [],
     144        'params'   => [],
    143145        'function' => \&permissions
    144146    },
    145147    'cleanup' => {
    146         'desc' => [],
    147         'params' => [],
     148        'desc'     => [],
     149        'params'   => [],
    148150        'function' => \&cleanup
    149151    },
    150152    'complete' => {
    151         'desc' => [ "internally, used for bash completion" ],
    152         'params' => [ "CMD" ],
     153        'desc'     => ["internally, used for bash completion"],
     154        'params'   => ["CMD"],
    153155        'function' => \&complete
    154156    },
    155157    'complete_path' => {
    156         'desc' => [ "internally, used for bash completion" ],
    157         'params' => [],
     158        'desc'     => ["internally, used for bash completion"],
     159        'params'   => [],
    158160        'function' => \&complete_path
    159161    },
    160162    'complete_repopath' => {
    161         'desc' => [ "internally, used for bash completion" ],
    162         'params' => [],
     163        'desc'     => ["internally, used for bash completion"],
     164        'params'   => [],
    163165        'function' => \&complete_repopath
    164166    },
    165167);
    166 
    167168
    168169# configuration file
     
    208209    print "\n";
    209210    print "Available subcommands:\n";
    210     foreach my $i (sort keys(%COMMAND_DEFINITIONS)) {
    211         print "    ", $i, " ", join( " ", get_command_possible_params($i) ), "\n";
     211    foreach my $i ( sort keys(%COMMAND_DEFINITIONS) ) {
     212        print "    ", $i, " ", join( " ", get_command_possible_params($i) ),
     213          "\n";
    212214        foreach my $line ( get_command_desc($i) ) {
    213             print " "x20, $line, "\n";
     215            print " " x 20, $line, "\n";
    214216        }
    215217    }
     
    356358        if ( "$USER" eq "root" ) {
    357359            if (    ( not $DASSCM_USERNAME )
    358                 and ( get_command_requires_write( $command ) ) )
     360                and ( get_command_requires_write($command) ) )
    359361            {
    360362
     
    394396{
    395397    my $command_abbrivation = $_[0];
    396     if( defined($COMMANDS{$command_abbrivation}) ) {
     398    if ( defined( $COMMANDS{$command_abbrivation} ) ) {
    397399        return $COMMANDS{$command_abbrivation};
    398400    }
     
    402404sub get_command_desc( $ )
    403405{
    404     my $command = get_command_uniform_name($_[0]);
    405     my @desc = ();
    406     if( $command && defined($COMMAND_DEFINITIONS{$command}{'desc'}) ) {
    407         @desc = @{$COMMAND_DEFINITIONS{$command}{'desc'}};
     406    my $command = get_command_uniform_name( $_[0] );
     407    my @desc    = ();
     408    if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'desc'} ) ) {
     409        @desc = @{ $COMMAND_DEFINITIONS{$command}{'desc'} };
    408410    }
    409411    return @desc;
     
    412414sub get_command_function( $ )
    413415{
    414     my $command = get_command_uniform_name($_[0]);
     416    my $command = get_command_uniform_name( $_[0] );
    415417    my $func;
    416     if( $command && defined($COMMAND_DEFINITIONS{$command}{'function'}) ) {
     418    if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'function'} ) ) {
    417419        $func = $COMMAND_DEFINITIONS{$command}{'function'};
    418420    }
     
    422424sub get_command_possible_params( $ )
    423425{
    424     my $command = get_command_uniform_name($_[0]);
    425     my @params = ();
    426     if( $command && defined($COMMAND_DEFINITIONS{$command}{'params'}) ) {
    427         @params = @{$COMMAND_DEFINITIONS{$command}{'params'}};
     426    my $command = get_command_uniform_name( $_[0] );
     427    my @params  = ();
     428    if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'params'} ) ) {
     429        @params = @{ $COMMAND_DEFINITIONS{$command}{'params'} };
    428430    }
    429431    return @params;
     
    432434sub get_command_requirements( $ )
    433435{
    434     my $command = get_command_uniform_name($_[0]);
     436    my $command      = get_command_uniform_name( $_[0] );
    435437    my @requirements = ();
    436     if( $command && defined($COMMAND_DEFINITIONS{$command}{'require'}) ) {
    437         @requirements = @{$COMMAND_DEFINITIONS{$command}{'require'}};
     438    if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'require'} ) ) {
     439        @requirements = @{ $COMMAND_DEFINITIONS{$command}{'require'} };
    438440    }
    439441    return @requirements;
     
    442444sub get_command_requires_write( $ )
    443445{
    444     return grep( /^WRITE$/, get_command_requirements($_[0]) );
    445 }
    446 
     446    return grep( /^WRITE$/, get_command_requirements( $_[0] ) );
     447}
    447448
    448449#
     
    493494    }
    494495
    495     # file must be readable. 
    496     # The only exceptions are, 
     496    # file must be readable.
     497    # The only exceptions are,
    497498    # - if the file parameter is to be completed or
    498499    # - if a file should be reverted
     
    553554
    554555    #copy( $filename_prod, $filename_repo )
    555     ( my $rc, my @result ) = run_command( "cp -a \"$filename_prod\" \"$filename_repo\"" );
    556     if( $rc != 0 ) {
     556    ( my $rc, my @result ) =
     557      run_command("cp -a \"$filename_prod\" \"$filename_repo\"");
     558    if ( $rc != 0 ) {
    557559        error( "failed to copy $filename_prod to repository: ", @result );
    558560    }
     
    561563    return $rc == 0;
    562564}
    563 
    564 
    565565
    566566sub copy_file_from_repository_to_system( $ )
     
    576576    ) = get_filenames($filename);
    577577
    578     ( my $rc, my @result ) = run_command( "cp -a \"$filename_repo\" \"$filename_prod\"" );
    579     if( $rc != 0 ) {
     578    ( my $rc, my @result ) =
     579      run_command("cp -a \"$filename_repo\" \"$filename_prod\"");
     580    if ( $rc != 0 ) {
    580581        error( "failed to copy $filename_repo to $filename_prod: ", @result );
    581582    }
     
    584585    return $rc == 0;
    585586}
    586 
    587 
    588587
    589588#
     
    955954}
    956955
    957 
    958956#
    959957# use globbing to get lsit of files
     
    969967
    970968    # get files
    971     my @files = glob( $path );
     969    my @files = glob($path);
    972970
    973971    # if only one result is available
     
    975973    # add another result entry
    976974    # (otherwise complete will stop here and continue with the next parameter)
    977     if( $#files == 0 ) {
     975    if ( $#files == 0 ) {
    978976        my $path = $files[0];
    979         if( -d $path ) {
     977        if ( -d $path ) {
    980978            push( @files, $path . "/" );
    981979        }
     
    984982    return @files;
    985983}
    986 
    987984
    988985#####################################################################
     
    11081105
    11091106    mkpath($dirname_repo);
    1110     copy_file_to_repository( $filename_prod );
     1107    copy_file_to_repository($filename_prod);
    11111108
    11121109    # already checked in?
     
    12811278    # cleanup repository
    12821279    cleanup();
     1280
    12831281    #svn_update();
    12841282
     
    13041302                    mkpath("$real_path");
    13051303                } else {
    1306                     copy_file_from_repository_to_system( $real_path );
     1304                    copy_file_from_repository_to_system($real_path);
    13071305                }
    13081306            }
     
    13151313            # copy files one by one from local repository to system
    13161314            for my $real_file ( keys(%changedfiles) ) {
    1317                 copy_file_from_repository_to_system( $real_file );
     1315                copy_file_from_repository_to_system($real_file);
    13181316            }
    13191317
     
    15561554
    15571555    my $number_arguments = @_;
    1558     my @input = @_;
    1559 
    1560    
     1556    my @input            = @_;
     1557
    15611558    if ( $number_arguments <= 1 ) {
    15621559
     
    15651562        foreach my $i ( keys %COMMANDS ) {
    15661563            $_ = $i;
    1567             if( m/^$input/ ) {
     1564            if (m/^$input/) {
    15681565                my $command = get_command_uniform_name($i);
    15691566                print $command, "\n";
     
    15731570
    15741571        # complete dasscm parameter
    1575         my $command = get_command_uniform_name($input[0]);
    1576         my @params = get_command_possible_params($input[0]);
    1577         if( $verbose ) { print "params: ", Dumper(@params); }
    1578         if( defined($params[$number_arguments-2]) && $params[$number_arguments-2] ) { 
    1579             my $param = $params[$number_arguments-2];
    1580             if( $param eq "PATH" ) {
    1581                 complete_path( $input[$number_arguments-1] );
     1572        my $command = get_command_uniform_name( $input[0] );
     1573        my @params  = get_command_possible_params( $input[0] );
     1574        if ($verbose) { print "params: ", Dumper(@params); }
     1575        if ( defined( $params[ $number_arguments - 2 ] )
     1576            && $params[ $number_arguments - 2 ] )
     1577        {
     1578            my $param = $params[ $number_arguments - 2 ];
     1579            if ( $param eq "PATH" ) {
     1580                complete_path( $input[ $number_arguments - 1 ] );
    15821581            } elsif ( $param eq "REPOPATH" ) {
    1583                 complete_repopath( $input[$number_arguments-1] );
     1582                complete_repopath( $input[ $number_arguments - 1 ] );
    15841583            } else {
    15851584                print "param: $param\n";
     
    15891588    }
    15901589}
    1591 
    15921590
    15931591sub complete_path(@)
     
    16041602    ) = get_filenames( $_[0] );
    16051603
    1606     my @files = get_complete_path_globbing( $filename_prod );
     1604    my @files = get_complete_path_globbing($filename_prod);
    16071605
    16081606    if (@files) {
     
    16111609    }
    16121610}
    1613 
    1614 
    16151611
    16161612sub complete_repopath(@)
     
    16271623    ) = get_filenames( $_[0] );
    16281624
    1629     my @files = get_complete_path_globbing( $filename_repo );
    1630    
     1625    my @files = get_complete_path_globbing($filename_repo);
     1626
    16311627    if (@files) {
     1628
    16321629        # remove DASSCM_REPO path again
    1633         print join( "\n", map( { s|^${DASSCM_REPO}|/|; $_} @files ) );
     1630        print join(
     1631            "\n",
     1632            map( {
     1633                    s|^${DASSCM_REPO}|/|;
     1634                      $_
     1635                } @files )
     1636        );
    16341637        print "\n";
    16351638    }
    16361639
    16371640}
    1638 
    1639 
    16401641
    16411642#####################################################################
     
    16501651
    16511652    # get subcommand and remove it from @ARGV
    1652     $command = get_command_uniform_name($ARGV[0]);
     1653    $command = get_command_uniform_name( $ARGV[0] );
    16531654    shift @ARGV;
    16541655
     
    16961697    #
    16971698
    1698     if( get_command_function( $command ) ) {
    1699         &{get_command_function( $command )}( @ARGV );
     1699    if ( get_command_function($command) ) {
     1700        &{ get_command_function($command) }(@ARGV);
    17001701    } else {
    17011702        print "unknown command: $command\n\n";
Note: See TracChangeset for help on using the changeset viewer.