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

Annotation of /Clearinghouse/upload_subsystem.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download) (as text)

1 : olson 1.1 #
2 :     # Upload a subsystem to the clearinghouse.
3 :     #
4 :    
5 : olson 1.3 use strict;
6 :    
7 : olson 1.4
8 : olson 1.1 use SOAP::Lite;
9 :     use LWP::UserAgent;
10 :     use HTTP::Request::Common;
11 : olson 1.4 use Getopt::Long;
12 : olson 1.1
13 :     use FIG;
14 : olson 1.4 use Clearinghouse::utils;
15 : olson 1.1
16 : olson 1.4 my $usage = "upload_subsystem [-t type] subsystem-package [subsystem-pacakge...]";
17 : olson 1.1
18 : olson 1.3 #my $url = "http://clearinghouse.theseed.org/clearinghouse_services.cgi";
19 :     my $url = "http://localhost/FIG/clearinghouse_services.cgi";
20 : olson 1.1
21 : olson 1.4 my @valid_types = qw(SUBSYSTEM 1-SUBSYSTEM);
22 :    
23 :     my $upload_type = 'SUBSYSTEM';
24 :     my $verbose;
25 :     my $who = 'olson@mcs.anl.gov';
26 :    
27 :     my $optresult = GetOptions("type|t=s" => \$upload_type,
28 :     "who|w=s" => \$who,
29 :     "verbose|v" => \$verbose);
30 :    
31 :     if (!$optresult)
32 :     {
33 :     die "$usage\n";
34 :     }
35 :    
36 :     grep { $_ eq $upload_type } @valid_types or die "Invalid type $upload_type. Valid types: @valid_types\n";
37 :    
38 :     print "Uploading to clearinghouse $url\n" if $verbose;
39 :    
40 : olson 1.1 my $proxy = SOAP::Lite-> uri('http://www.soaplite.com/Scripts')
41 :     -> proxy($url);
42 :    
43 :     my $ua = new LWP::UserAgent;
44 :    
45 :     for my $pkg (@ARGV)
46 :     {
47 : olson 1.3 my %meta;
48 : olson 1.4
49 :     eval {
50 :     %meta = valiate_subsystem($pkg);
51 :     };
52 :    
53 :     if ($@)
54 : olson 1.3 {
55 : olson 1.4 die "Error validating subsystem:\n$@\n";
56 :     exit;
57 : olson 1.3 }
58 : olson 1.1
59 :     #
60 :     # Validate a bit.
61 :     #
62 :    
63 : olson 1.3 my $name = $meta{name};
64 :     my $version = $meta{version};
65 :     my $curator = $meta{curator};
66 :    
67 : olson 1.1 $name ne '' or die "Invalid name in package $pkg\n";
68 :     $version =~ /^\d+$/ or die "Invalid version '$version' in package $pkg\n";
69 :     $curator ne '' or die "Invalid curator in package $pkg\n";
70 :    
71 :     print "Uploading $name: version=$version curator=$curator\n";
72 :    
73 :     #
74 :     # Ready to upload now.
75 :     #
76 :    
77 :     my $res = $proxy->get_upload_url();
78 :     $res->fault and die "Failure getting upload url: ", $res->faultcode, " ", $res->faultstring;
79 :    
80 :     my($url, $id) = @{$res->result};
81 :    
82 :     my $size = -s $pkg;
83 :    
84 :     $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
85 :    
86 :     my $req = POST($url,
87 :     Content_Type => 'form-data',
88 :     Content => [file_id => $id,
89 :     file_size=> $size,
90 :     file => [$pkg]]);
91 :    
92 :     my $resp = $ua->request($req);
93 :     if (!$resp->is_success) {
94 : olson 1.3 die "Failed to upload $pkg";
95 : olson 1.1 }
96 :    
97 :     #step 3 - finish up, this makes the entry in the DB
98 :     # now finish the deposit
99 :    
100 :     my $metadata = "name\t$name\n";
101 :     $metadata .= "curator\t$curator\n";
102 :     $metadata .= "version\t$version\n";
103 :    
104 : olson 1.3 my $description = "Subsystem $name uploaded on " . localtime;
105 : olson 1.1 my $source = &FIG::get_local_hostname();
106 :    
107 : olson 1.2 my $uresp = $proxy->finish_upload([$id], $upload_type, $who, $metadata, $description, $source);
108 : olson 1.1 #check this response sometime
109 :     }
110 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3