diff options
author | Andrew Gaffney <agaffney@gentoo.org> | 2007-12-24 01:30:35 +0000 |
---|---|---|
committer | Andrew Gaffney <agaffney@gentoo.org> | 2007-12-24 01:30:35 +0000 |
commit | 8e080c2d7e1d86fc5ef3bd4c48ac91f789db05dd (patch) | |
tree | 1be18c68020d6b1d78d499a7156fc1ecf2723b2d | |
parent | change var name from USERNAME to USER to match existing code (diff) | |
download | scire-8e080c2d7e1d86fc5ef3bd4c48ac91f789db05dd.tar.gz scire-8e080c2d7e1d86fc5ef3bd4c48ac91f789db05dd.tar.bz2 scire-8e080c2d7e1d86fc5ef3bd4c48ac91f789db05dd.zip |
ok, where to begin....
SCIRE_CONFIG_FILE is no longer a constant so it can be overriden via commandline
basic commandline parsing
helper function for sending/receiving and creating the connection
move my test code into run_test() function
temporary connection_command override for development
fix a few syntax errors
random other changes that I can't be bothered to think of
svn path=/branches/new-fu/; revision=256
-rwxr-xr-x | client/scireclient.pl | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/client/scireclient.pl b/client/scireclient.pl index e1f287c..3e03049 100755 --- a/client/scireclient.pl +++ b/client/scireclient.pl @@ -5,30 +5,32 @@ use warnings; use IPC::Open2; -use constant SCIRE_CONFIG_FILE => '/etc/scire.conf'; -#Constants to be defined in /etc/scire.conf +my $SCIRE_CONFIG_FILE = '../etc/scire.conf'; +my %conf; +my ($SERVER_STDOUT, $SERVER_STDIN); -my $conf; +parse_command_line(); read_config(); -#Read command line options. - # Build the connection command. # This will eventually be something like "ssh scire@${scireserver} /usr/bin/scireserver.pl" my $connection_command = "ssh "; -if (defined($conf{port})) { +if(defined($conf{port})) { $connection_command .= "-o Port=$conf{port} "; } $connection_command .= "$conf{user}\@$conf{host} $conf{server_script}"; -#my $servercmd = "../server/scireserver.pl"; +if(-d ".svn") { + # Overwrite $connection_command in the case of a dev environment for now + $connection_command = "../server/scireserver.pl"; +} if(! -d $conf{job_dir}) { print "WARNING! $conf{job_dir} does not exist...creating\n"; mkdir $conf{job_dir}, 0660; } -my $pid = open2(*server_stdout, *server_stdin, $connection_command); +run_main(); sub run_main { #ok folks so here's how this thang goes down. @@ -37,21 +39,65 @@ sub run_main { #3. Scan the jobs directory. If there are done/failed jobs, report them. Note jobs in running or queue. #4. Fetch the jobs list #5. ? - # -for(('PING', 'FOO', 'QUIT')) { - print "Sending: $_\n"; - print server_stdin "$_\n"; - my $response = <server_stdout>; - print "Got: ${response}"; + create_connection(); + run_test(); +} + +sub run_test { + for(('PING', 'FOO', 'QUIT')) { + send_command($_); + my $response = get_response(); + print "Got: ${response}"; + } +} + +sub parse_command_line { + # XXX: Anyone know how to use getopt? I've never bothered figuring it out :P + while($#ARGV > -1) { + my $foo = shift @ARGV; + if($foo eq "-f") { + $SCIRE_CONFIG_FILE = shift @ARGV; + } else { + print "Unrecognized command line option: ${foo}\n"; + } + } +} + +sub send_command { + my $cmd = shift; + my @args = @_; + my $tosend = "${cmd}"; + + for my $arg (@args) { + if($arg =~ /^[0-9]+$/) { + $tosend .= " ${arg}"; + } else { + $arg =~ s/"/\\"/g; + $tosend .= " \"${arg}\""; + } + } + print "Sending: ${tosend}\n"; + print SERVER_STDIN "${tosend}\n"; +} + +sub get_response { + # XXX: Add some logic for multi-line responses here + my $response = <SERVER_STDOUT>; + return $response; +} + +sub create_connection { + # XXX: We need to see what this function returns if the command returns non-zero + my $pid = open2(*SERVER_STDOUT, *SERVER_STDIN, $connection_command); } sub read_config { - my FH = open(SCIRE_CONFIG_FILE) or die("Couldn't open the config ".${\SCIRE_CONFIG_FILE}." : $!"); + open(FH, "< ${SCIRE_CONFIG_FILE}") or die("Couldn't open the config file ${SCIRE_CONFIG_FILE}: $!"); while (<FH>) { - chomp( my $line = $_); + chomp; next if /^\s*(?:#|$)/; my ($key,$val) = split /=/; $conf{lc($key)} = $val; } - close(FH) or die("Couldn't close the config ".${\SCIRE_CONFIG_FILE}." : $!"); + close(FH) or die("Couldn't close the config file ${SCIRE_CONFIG_FILE}: $!"); } |