[Bio] / Clearinghouse / upload_subsystem.pl Repository:
ViewVC logotype

View of /Clearinghouse/upload_subsystem.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Tue May 3 20:18:57 2005 UTC (14 years, 5 months ago) by olson
Branch: MAIN
CVS Tags: myrast_33, HEAD
Changes since 1.3: +31 -21 lines
Add validation on subsystems.

Move validation code into utils::validate_package($package_file, $package_type).

#
# Upload a subsystem to the clearinghouse.
#

use strict;


use SOAP::Lite;
use LWP::UserAgent;
use HTTP::Request::Common;
use Getopt::Long;

use FIG;
use Clearinghouse::utils;

my $usage = "upload_subsystem [-t type]  subsystem-package [subsystem-pacakge...]";

#my $url = "http://clearinghouse.theseed.org/clearinghouse_services.cgi";
my $url = "http://localhost/FIG/clearinghouse_services.cgi";

my @valid_types = qw(SUBSYSTEM 1-SUBSYSTEM);

my $upload_type = 'SUBSYSTEM';
my $verbose;
my $who = 'olson@mcs.anl.gov';

my $optresult = GetOptions("type|t=s" => \$upload_type,
			   "who|w=s" => \$who,
			   "verbose|v" => \$verbose);

if (!$optresult)
{
    die "$usage\n";
}

grep { $_ eq $upload_type } @valid_types or die "Invalid type $upload_type. Valid types: @valid_types\n";

print "Uploading to clearinghouse $url\n" if $verbose;

my $proxy = SOAP::Lite-> uri('http://www.soaplite.com/Scripts')
	-> proxy($url);

my $ua = new LWP::UserAgent;

for my $pkg (@ARGV)
{
    my %meta;

    eval {
	%meta = valiate_subsystem($pkg);
    };

    if ($@)
    {
	die "Error validating subsystem:\n$@\n";
	exit;
    }

    #
    # Validate a bit.
    #

    my $name = $meta{name};
    my $version = $meta{version};
    my $curator = $meta{curator};

    $name ne '' or die "Invalid name in package $pkg\n";
    $version =~ /^\d+$/ or die "Invalid version '$version' in package $pkg\n";
    $curator ne '' or die "Invalid curator in package $pkg\n";

    print "Uploading $name: version=$version curator=$curator\n";

    #
    # Ready to upload now.
    #

    my $res = $proxy->get_upload_url();
    $res->fault and die "Failure getting upload url: ", $res->faultcode, " ", $res->faultstring;

    my($url, $id) = @{$res->result};

    my $size = -s $pkg;

    $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;

    my $req = POST($url,
		   Content_Type => 'form-data',
		   Content => [file_id => $id,
			       file_size=> $size,
			       file => [$pkg]]);

    my $resp = $ua->request($req);
    if (!$resp->is_success) {
	die "Failed to upload $pkg";
    }

    #step 3 - finish up, this makes the entry in the DB
    # now finish the deposit

    my $metadata = "name\t$name\n";
    $metadata .= "curator\t$curator\n";
    $metadata .= "version\t$version\n";

    my $description = "Subsystem $name uploaded on " . localtime;
    my $source = &FIG::get_local_hostname();
    
    my $uresp = $proxy->finish_upload([$id], $upload_type, $who, $metadata, $description, $source);  
    #check this response sometime
}
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3