Changeset 889 for dasscm/trunk
- Timestamp:
- Jun 26, 2010, 12:19:34 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dasscm/trunk/usr/bin/dasscm
r888 r889 11 11 use File::Basename; 12 12 use 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 14 15 #use File::Copy; 15 16 use File::Find; … … 40 41 my $config = get_config($config_file); 41 42 42 43 44 43 my %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', 66 65 'complete_repopath' => 'complete_repopath', 67 66 ); … … 73 72 # PATH 74 73 # REPOPATH 75 # require: 74 # require: 76 75 # WRITE commands that require write access (and therefore a login) 77 76 my %COMMAND_DEFINITIONS = ( 78 77 'help' => { 79 'desc' => [],80 'params' => [ "CMD"],78 'desc' => [], 79 'params' => ["CMD"], 81 80 'function' => \&help, 82 81 }, 83 82 'login' => { 84 'desc' => [],85 'params' => [ "USER"],83 'desc' => [], 84 'params' => ["USER"], 86 85 'function' => \&login 87 86 }, 88 87 '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' => [], 91 93 'function' => \&init 92 94 }, 93 95 'ls' => { 94 'desc' => [],95 'params' => [ "REPOPATH"],96 'desc' => [], 97 'params' => ["REPOPATH"], 96 98 'function' => \&ls 97 99 }, 98 100 'update' => { 99 'desc' => [],100 'params' => [ "PATH"],101 'desc' => [], 102 'params' => ["PATH"], 101 103 'function' => \&update 102 104 }, 103 105 'add' => { 104 'desc' => [],105 'params' => [ "PATH"],106 'require' => [ "WRITE"],106 'desc' => [], 107 'params' => ["PATH"], 108 'require' => ["WRITE"], 107 109 'function' => \&add 108 110 }, 109 111 'commit' => { 110 'desc' => [],111 'params' => [ "REPOPATH"],112 'require' => [ "WRITE"],112 'desc' => [], 113 'params' => ["REPOPATH"], 114 'require' => ["WRITE"], 113 115 'function' => \&commit 114 116 }, 115 117 '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"], 118 120 'function' => \&revert 119 121 }, 120 122 'blame' => { 121 'desc' => [],122 'params' => [ "PATH"],123 'desc' => [], 124 'params' => ["PATH"], 123 125 'function' => \&blame 124 126 }, 125 127 'diff' => { 126 'desc' => [],127 'params' => [ "PATH"],128 'desc' => [], 129 'params' => ["PATH"], 128 130 'function' => \&diff 129 131 }, 130 132 'status' => { 131 'desc' => [],132 'params' => [ "PATH"],133 'desc' => [], 134 'params' => ["PATH"], 133 135 'function' => \&status 134 136 }, 135 137 'check' => { 136 'desc' => [ "perform Nagios NRPE conform check"],137 'params' => [],138 'desc' => ["perform Nagios NRPE conform check"], 139 'params' => [], 138 140 'function' => \&check 139 141 }, 140 142 'permissions' => { 141 'desc' => [],142 'params' => [],143 'desc' => [], 144 'params' => [], 143 145 'function' => \&permissions 144 146 }, 145 147 'cleanup' => { 146 'desc' => [],147 'params' => [],148 'desc' => [], 149 'params' => [], 148 150 'function' => \&cleanup 149 151 }, 150 152 'complete' => { 151 'desc' => [ "internally, used for bash completion"],152 'params' => [ "CMD"],153 'desc' => ["internally, used for bash completion"], 154 'params' => ["CMD"], 153 155 'function' => \&complete 154 156 }, 155 157 'complete_path' => { 156 'desc' => [ "internally, used for bash completion"],157 'params' => [],158 'desc' => ["internally, used for bash completion"], 159 'params' => [], 158 160 'function' => \&complete_path 159 161 }, 160 162 'complete_repopath' => { 161 'desc' => [ "internally, used for bash completion"],162 'params' => [],163 'desc' => ["internally, used for bash completion"], 164 'params' => [], 163 165 'function' => \&complete_repopath 164 166 }, 165 167 ); 166 167 168 168 169 # configuration file … … 208 209 print "\n"; 209 210 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"; 212 214 foreach my $line ( get_command_desc($i) ) { 213 print " " x20, $line, "\n";215 print " " x 20, $line, "\n"; 214 216 } 215 217 } … … 356 358 if ( "$USER" eq "root" ) { 357 359 if ( ( not $DASSCM_USERNAME ) 358 and ( get_command_requires_write( $command) ) )360 and ( get_command_requires_write($command) ) ) 359 361 { 360 362 … … 394 396 { 395 397 my $command_abbrivation = $_[0]; 396 if ( defined($COMMANDS{$command_abbrivation}) ) {398 if ( defined( $COMMANDS{$command_abbrivation} ) ) { 397 399 return $COMMANDS{$command_abbrivation}; 398 400 } … … 402 404 sub get_command_desc( $ ) 403 405 { 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'} }; 408 410 } 409 411 return @desc; … … 412 414 sub get_command_function( $ ) 413 415 { 414 my $command = get_command_uniform_name( $_[0]);416 my $command = get_command_uniform_name( $_[0] ); 415 417 my $func; 416 if ( $command && defined($COMMAND_DEFINITIONS{$command}{'function'}) ) {418 if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'function'} ) ) { 417 419 $func = $COMMAND_DEFINITIONS{$command}{'function'}; 418 420 } … … 422 424 sub get_command_possible_params( $ ) 423 425 { 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'} }; 428 430 } 429 431 return @params; … … 432 434 sub get_command_requirements( $ ) 433 435 { 434 my $command = get_command_uniform_name($_[0]);436 my $command = get_command_uniform_name( $_[0] ); 435 437 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'} }; 438 440 } 439 441 return @requirements; … … 442 444 sub get_command_requires_write( $ ) 443 445 { 444 return grep( /^WRITE$/, get_command_requirements($_[0]) ); 445 } 446 446 return grep( /^WRITE$/, get_command_requirements( $_[0] ) ); 447 } 447 448 448 449 # … … 493 494 } 494 495 495 # file must be readable. 496 # The only exceptions are, 496 # file must be readable. 497 # The only exceptions are, 497 498 # - if the file parameter is to be completed or 498 499 # - if a file should be reverted … … 553 554 554 555 #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 ) { 557 559 error( "failed to copy $filename_prod to repository: ", @result ); 558 560 } … … 561 563 return $rc == 0; 562 564 } 563 564 565 565 566 566 sub copy_file_from_repository_to_system( $ ) … … 576 576 ) = get_filenames($filename); 577 577 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 ) { 580 581 error( "failed to copy $filename_repo to $filename_prod: ", @result ); 581 582 } … … 584 585 return $rc == 0; 585 586 } 586 587 588 587 589 588 # … … 955 954 } 956 955 957 958 956 # 959 957 # use globbing to get lsit of files … … 969 967 970 968 # get files 971 my @files = glob( $path);969 my @files = glob($path); 972 970 973 971 # if only one result is available … … 975 973 # add another result entry 976 974 # (otherwise complete will stop here and continue with the next parameter) 977 if ( $#files == 0 ) {975 if ( $#files == 0 ) { 978 976 my $path = $files[0]; 979 if ( -d $path ) {977 if ( -d $path ) { 980 978 push( @files, $path . "/" ); 981 979 } … … 984 982 return @files; 985 983 } 986 987 984 988 985 ##################################################################### … … 1108 1105 1109 1106 mkpath($dirname_repo); 1110 copy_file_to_repository( $filename_prod);1107 copy_file_to_repository($filename_prod); 1111 1108 1112 1109 # already checked in? … … 1281 1278 # cleanup repository 1282 1279 cleanup(); 1280 1283 1281 #svn_update(); 1284 1282 … … 1304 1302 mkpath("$real_path"); 1305 1303 } else { 1306 copy_file_from_repository_to_system( $real_path);1304 copy_file_from_repository_to_system($real_path); 1307 1305 } 1308 1306 } … … 1315 1313 # copy files one by one from local repository to system 1316 1314 for my $real_file ( keys(%changedfiles) ) { 1317 copy_file_from_repository_to_system( $real_file);1315 copy_file_from_repository_to_system($real_file); 1318 1316 } 1319 1317 … … 1556 1554 1557 1555 my $number_arguments = @_; 1558 my @input = @_; 1559 1560 1556 my @input = @_; 1557 1561 1558 if ( $number_arguments <= 1 ) { 1562 1559 … … 1565 1562 foreach my $i ( keys %COMMANDS ) { 1566 1563 $_ = $i; 1567 if ( m/^$input/) {1564 if (m/^$input/) { 1568 1565 my $command = get_command_uniform_name($i); 1569 1566 print $command, "\n"; … … 1573 1570 1574 1571 # 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 ] ); 1582 1581 } elsif ( $param eq "REPOPATH" ) { 1583 complete_repopath( $input[ $number_arguments-1] );1582 complete_repopath( $input[ $number_arguments - 1 ] ); 1584 1583 } else { 1585 1584 print "param: $param\n"; … … 1589 1588 } 1590 1589 } 1591 1592 1590 1593 1591 sub complete_path(@) … … 1604 1602 ) = get_filenames( $_[0] ); 1605 1603 1606 my @files = get_complete_path_globbing( $filename_prod);1604 my @files = get_complete_path_globbing($filename_prod); 1607 1605 1608 1606 if (@files) { … … 1611 1609 } 1612 1610 } 1613 1614 1615 1611 1616 1612 sub complete_repopath(@) … … 1627 1623 ) = get_filenames( $_[0] ); 1628 1624 1629 my @files = get_complete_path_globbing( $filename_repo);1630 1625 my @files = get_complete_path_globbing($filename_repo); 1626 1631 1627 if (@files) { 1628 1632 1629 # 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 ); 1634 1637 print "\n"; 1635 1638 } 1636 1639 1637 1640 } 1638 1639 1640 1641 1641 1642 ##################################################################### … … 1650 1651 1651 1652 # get subcommand and remove it from @ARGV 1652 $command = get_command_uniform_name( $ARGV[0]);1653 $command = get_command_uniform_name( $ARGV[0] ); 1653 1654 shift @ARGV; 1654 1655 … … 1696 1697 # 1697 1698 1698 if ( get_command_function( $command) ) {1699 &{ get_command_function( $command )}( @ARGV);1699 if ( get_command_function($command) ) { 1700 &{ get_command_function($command) }(@ARGV); 1700 1701 } else { 1701 1702 print "unknown command: $command\n\n";
Note:
See TracChangeset
for help on using the changeset viewer.