#!/usr/bin/perl

# Gets data from a test request

use Pod::Usage;
use Getopt::Long;
use SOAP::Lite;
use strict;

# Global options
our $opt_version;
our $opt_help;
our $opt_man;
our $opt_resource = 'http://www.osdl.org/WebService/TestSystem';
our $opt_server   = 'http://localhost:8081/';
our $opt_url      = "http://khack.osdl.org/stp";

# Handle commandline options
Getopt::Long::Configure ('bundling', 'no_ignore_case');
GetOptions(
           'version|V'    => \$opt_version,
           'help|h'       => \$opt_help,
           'man'          => \$opt_man,
	   'server|s=s'   => \$opt_server,
           'resource|r=s' => \$opt_resource,
           'url|u=s'      => \$opt_url,
           );

# Handle -V or --version
if ($opt_version) {
    print '$0: $Revision: 1.4 $', "\n";
    exit 0;
}

# Usage
pod2usage(-verbose => 2, -exitstatus => 0) if ($opt_man);
pod2usage(-verbose => 1, -exitstatus => 0) if ($opt_help);

exit main();



sub main {

    foreach my $id (@ARGV) {
	if ($id !~ /^\d+$/) {
	    warn "'$id' is not a valid id - must be digits only.  Skipping.\n";
	    next;
	}
	
	print `wget -r -l inf -nH -np --cut-dirs=1 -R '*\\?*' "$opt_url/$id"`;
    }

    return 0;
}


__END__

=head1 NAME

stp-trget - retrieves a given test run's data files.

=head1 SYNOPSIS

stp-trget ID [ ID [ ... ] ]

=head1 DESCRIPTION

B<stp-trget> will retrieve the data files for a given test request's test
run and store them into a subdir in the current directory named as the
test run's ID number.  Skips arguments that are not numeric, issuing a 
warning.

This script is essentially just a wrapper around wget that pulls the
data from a URL.

=head1 OPTIONS

=over 8

=item B<-V>, B<--version>

Displays the version number of the script and exits.

=item B<-h>, B<--help>

Displays a brief usage message

=item B<--man>

Displays the man page

=item B<u> I<url>, B<--url>=I<server_url>

The URL to retrieve data from.  Will look for [url]/[ID NUM]/
By default, it uses http://khack.osdl.org/stp/.

=back

=head1 PREREQUISITES

B<wget>,
B<Pod::Usage>,
B<Getopt::Long>

=head1 AUTHOR

Bryce Harrington E<lt>bryce@osdl.orgE<gt>

=head1 COPYRIGHT

Copyright (C) 2004 Open Source Development Labs
All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 REVISION

Revision: $Revision: 1.4 $

=cut



