# # Copyright (c) 2002-2004 Eric Wallengren # This file is part of the Continuous Automated Build and Integration # Environment (CABIE) # # CABIE is distributed under the terms of the GNU General Public # License version 2 or any later version. See the file COPYING for copying # permission or http://www.gnu.org. # # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR # IMPLIED, without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. ANY USE IS AT YOUR OWN RISK. # # Permission to modify the code and to distribute modified code is granted, # provided the above notices are retained, and a notice that the code was # modified is included with the above copyright notice. # #!/usr/local/bin/perl BEGIN{push @INC, "lib";} use RPCStd; use Getopt::Std; my $prog; my $server; my $port; my %Args; my @cmdbuffer; getopts('s:p:f:ih?', \%Args); $cs = $Args{s}; $cp = $Args{p}; $h = $Args{h}; $i = $Args{i}; $f = $Args{f}; if (!defined($h)) { $h = $Args{'?'}; } $en = $ENV{"BLDSERVER"}; ($es,$ep) = split(/:/, $en); if (defined($h)) { usage(); } if (defined($es)) { $server = $es; } if (defined($ep)) { $port = $ep; } if (defined($cs)) { $server = $cs; } if (defined($cp)) { $port = $cp; } if (defined($f)) { if (-f "$f") { open (IN, "<$f"); @cmdbuffer = ; close(IN); } } if ($server =~ /^$/ || $port =~ /^$/) { usage(); } if (defined($i)) { do_loop(); } if (@ARGV == 0) { print "\nTry commands as an argument\n"; usage(); } #---------------------------------------------------------------------- # Client stuff sub client_start() { $connx = RPCStd->connect($server, $port) || error("can't connect", $server, $port); @answer = $connx->rpc("@ARGV"); print @answer; } sub usage { print "\nbuild -s server -p port [-i interactive mode] command ". "[options]\n"; exit 1; } sub do_loop { my %Opts; my $cnt = 1; my $bRecord = 0; my $bPlayback = 0; my $oldserver = ""; my $oldport = 0; if (@cmdbuffer > 0) { $bPlayback = 1; } my @empty; $connx = RPCStd->connect($server, $port) || error("can't connect", $server, $port); print "\nEntering interactive mode, Type 'quit' to exit\n"; while ($command !~ /^[Qq][Uu][Ii][Tt]$/) { if ($bPlayback) { if ($bRecord) { print "Cannot replay while in record mode\n"; $command = ""; } else { foreach $one (@cmdbuffer) { chomp $one; ($server, $port, $command) = split(/:/, $one); if ($oldserver !~ /^$server$/ || $oldport != $oldport) { $connx = RPCStd->connect($server, $port) || error("can't connect", $server, $port); } $oldserver = $server; $oldport = $port; @answer = $connx->rpc("$command"); print @answer; } } $bPlayback = 0; } else { print "\n[$server:$port] $cnt >> "; $command = ; chomp $command; @command = @empty; push @command, $command; } if ($bRecord) { if ($command !~ /^stop/) { push @cmdbuffer, "$server:$port:$command"; } } if ($command !~ /^quit$/ ) { # # See if we're making a local system call # if ($command =~ /^!/) { $command =~ s/^!//g; system("$command"); } elsif ($command =~ /\*/) { @commands = split(/\*[ +]/, $command); foreach $entry (@commands) { print "\n"; @answer = $connx->rpc("$entry"); print @answer; } } elsif ($command =~ /^connect /) { @_ = split(/ /, $command); $oserver = $server; $oport = $port; shift; @ARGV = @_; getopts('s:p:', \%Opts); $s = $Opts{s}; $p = $Opts{p}; if (defined($s)) { $server = $s; } if (defined($p)) { $port = $p; } $connx = RPCStd->connect($server, $port) || error("can't connect", $server, $port); } elsif ($command =~ /^save /) { @_ = split(/ /, $command); shift; @ARGV = @_; getopts('f:', \%Opts); $f = $Opts{f}; if (!defined($f)) { print "No file specified\n"; } else { open (OUT, ">$f"); foreach $one (@cmdbuffer) { print OUT "$one\n"; } } } elsif ($command =~ /^record$/) { @cmdbuffer = @empty; $bRecord = 1; } elsif ($command =~ /^stop$/) { $bRecord = 0; } elsif ($command =~ /^replay$/) { if (@cmdbuffer == 0) { print "No commands to replay\n"; } else { $bPlayback = 1; } } else { @answer = $connx->rpc("$command"); print @answer; } $cnt++; } else { exit(0); } } } sub error { my $msg = shift; my $server = shift; my $port = shift; print "\nCan't connect to $server on port $port\n"; exit 1; } client_start(); exit(0);