Changeset 3702 for lang/perl/Archer
- Timestamp:
- 12/28/07 11:23:43 (11 months ago)
- Files:
-
- 1 modified
-
lang/perl/Archer/lib/Archer/Shell.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Archer/lib/Archer/Shell.pm
r3701 r3702 9 9 my ( $class, $args ) = @_; 10 10 11 return bless { %$args}, $class;11 return bless {%$args}, $class; 12 12 } 13 13 14 14 sub run_loop { 15 my ( $self, ) = @_;15 my ( $self, ) = @_; 16 16 17 17 my $term = Term::ReadLine->new('Archer'); 18 18 19 my $HISTFILE = ($ENV{HOME} || ((getpwuid($<))[7])) . "/.archer_shell_history"; 19 my $HISTFILE = ( $ENV{HOME} || ( ( getpwuid($<) )[7] ) ) 20 . "/.archer_shell_history"; 20 21 my $HISTSIZE = 256; 21 22 22 23 # this won't work with Term::ReadLine::Perl 23 24 # If there is Term::ReadLine::Gnu, be sure to do : export "PERL_RL=Gnu o=0" 24 eval { $term->stifle_history( $HISTSIZE ); }; 25 26 if ( @! ) { 27 $self->{ context }->log( 'debug' => "You will need Term::ReadLine::Gnu" ); 28 } else { 25 eval { $term->stifle_history($HISTSIZE); }; 26 27 if (@!) { 28 $self->{context} 29 ->log( 'debug' => "You will need Term::ReadLine::Gnu" ); 30 } 31 else { 29 32 if ( -f $HISTFILE ) { 30 $term->ReadHistory( $HISTFILE ) 31 or $self->{ context }->log( 'warn' => "cannot read history file: $!" ); 32 } 33 } 34 35 while ( defined( my $line = $term->readline( 'archer> ' ) ) ) { 33 $term->ReadHistory($HISTFILE) 34 or $self->{context} 35 ->log( 'warn' => "cannot read history file: $!" ); 36 } 37 } 38 39 while ( defined( my $line = $term->readline('archer> ') ) ) { 36 40 next if $line =~ /^\s*$/; 37 $self->catch_run( $line);41 $self->catch_run($line); 38 42 } 39 43 40 44 print "\n"; 41 45 42 eval { $term->WriteHistory( $HISTFILE ); }; 43 if ( @! ) { 44 $self->{context}->log( 'debug' => "perlsh: cannot write history file: $!" ); 46 eval { $term->WriteHistory($HISTFILE); }; 47 if (@!) { 48 $self->{context} 49 ->log( 'debug' => "perlsh: cannot write history file: $!" ); 45 50 } 46 51 … … 50 55 my ( $self, $cmd ) = @_; 51 56 52 $self->{ parallel } 53 = $self->{ context }->{ config }->{ global }->{ parallel } 57 $self->{parallel} = $self->{context}->{config}->{global}->{parallel} 54 58 || 'Archer::Parallel::ForkManager'; 55 $self->{ parallel}->use or die $@;59 $self->{parallel}->use or die $@; 56 60 57 61 if ( $cmd =~ /^on/ ) { 58 62 if ( $cmd =~ /^on\s(.*)\sdo\s(.*)$/ ) { 59 63 $self->process_host( $1, $2 ); 60 } else { 64 } 65 else { 61 66 print "[WARNING] error in your syntax, see help\n"; 62 67 } 63 } elsif ( $cmd =~ /^with/ ) { 68 } 69 elsif ( $cmd =~ /^with/ ) { 64 70 if ( $cmd =~ /^with\s(.*)\sdo\s(.*)$/ ) { 65 71 $self->process_role( $1, $2 ); 66 } else { 72 } 73 else { 67 74 print "[WARNING] error in your syntax, see help\n"; 68 75 } 69 } elsif ( $cmd =~ /^help/ ) { 76 } 77 elsif ( $cmd =~ /^help/ ) { 70 78 $self->help(); 71 } elsif ( $cmd =~ /^(quit|exit)/ ) { 79 } 80 elsif ( $cmd =~ /^(quit|exit)/ ) { 72 81 print "bye bye\n"; 73 82 exit; 74 } elsif ( $cmd =~ /^!/ ) { 83 } 84 elsif ( $cmd =~ /^!/ ) { 75 85 if ( $cmd =~ /^!(\w+)\s?(on|with)?\s?(.*)?$/ ) { 76 86 my $task = $1; 77 87 my $action = $2; 78 88 my $machines = $3; 79 if ( defined $action80 && defined $machines81 && length( $machines) < 1 )89 if ( defined $action 90 && defined $machines 91 && length($machines) < 1 ) 82 92 { 83 93 return print "[WARNING] error in your syntax, see help\n"; 84 94 } 85 95 my $executed = 0; 86 for 87 my $plugin ( @{ $self->{ config }->{ tasks }->{ process } } ) 88 { 89 next if $plugin->{ name } ne $task; 96 for my $plugin ( @{ $self->{config}->{tasks}->{process} } ) { 97 next if $plugin->{name} ne $task; 90 98 $executed = 1; 91 99 if ( defined $action ) { 92 100 if ( $action eq "on" ) { 93 101 my @hosts = split " ", $machines; 94 for my $host ( @hosts) {102 for my $host (@hosts) { 95 103 $self->process_task( $plugin, $host ); 96 104 } 97 } else { 105 } 106 else { 98 107 my @roles = split " ", $machines; 99 for my $role ( @roles ) { 100 for my $host ( 101 @{ $self->{ servers }->{ $role } } ) 102 { 108 for my $role (@roles) { 109 for my $host ( @{ $self->{servers}->{$role} } ) { 103 110 $self->process_task( $plugin, $host ); 104 111 } 105 112 } 106 113 } 107 } else { 114 } 115 else { 108 116 for my $host ( 109 @{ $self->{ servers } 110 ->{ $plugin->{ config }->{ role } } 111 } ) 117 @{ $self->{servers}->{ $plugin->{config}->{role} } } ) 112 118 { 113 119 $self->process_task( $plugin, $host ); … … 118 124 print "[WARNING] unable to find the requested task: $task\n"; 119 125 } 120 } else { 126 } 127 else { 121 128 print "[WARNING] error in your syntax\n"; 122 129 } 123 } else { 124 $self->process_command( $cmd ); 130 } 131 else { 132 $self->process_command($cmd); 125 133 } 126 134 } … … 132 140 133 141 # check if hosts are in our config. 134 for my $host ( @hosts) {135 for my $role ( keys %{ $self->{ servers} } ) {136 @hosts = grep ( /$host/, @{ $self->{ servers }->{ $role} } );137 } 138 } 139 140 if ( @hosts) {142 for my $host (@hosts) { 143 for my $role ( keys %{ $self->{servers} } ) { 144 @hosts = grep ( /$host/, @{ $self->{servers}->{$role} } ); 145 } 146 } 147 148 if (@hosts) { 141 149 $self->process_command( $cmd, \@hosts ); 142 150 } … … 149 157 my @hosts = (); 150 158 my @inexistant = (); 151 for my $role ( @roles) {152 if ( !defined $self->{ servers }->{ $role} ) {159 for my $role (@roles) { 160 if ( !defined $self->{servers}->{$role} ) { 153 161 push( @inexistant, $role ); 154 162 next; 155 163 } 156 for my $host ( @{ $self->{ servers }->{ $role} } ) {164 for my $host ( @{ $self->{servers}->{$role} } ) { 157 165 push @hosts, $host; 158 166 } 159 167 } 160 if ( @inexistant) {168 if (@inexistant) { 161 169 print "[WARNING] inexisting role(s) for " 162 170 . join( ' ', @inexistant ) . "\n"; … … 201 209 my $class = "Archer::Plugin::$plugin->{module}"; 202 210 $class->use or die $@; 203 $class->new( { config => $plugin->{ config }, 204 project => $self->{ context }->{ project }, 205 server => $host 206 } )->run( $self->{ context } ); 211 $class->new( 212 { config => $plugin->{config}, 213 project => $self->{context}->{project}, 214 server => $host 215 } 216 )->run( $self->{context} ); 207 217 } 208 218 … … 220 230 221 231 sub help { 222 my ( $self) = @_;232 my ($self) = @_; 223 233 my $help = <<HELP; 224 234 To quit, just type quit, exit, or press ctrl-D.
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)