[Bio] / FigWebServices / cluster_stage.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/cluster_stage.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Sat Feb 26 04:25:27 2005 UTC revision 1.4, Mon Dec 5 19:12:11 2005 UTC
# Line 1  Line 1 
1    #
2    # Copyright (c) 2003-2006 University of Chicago and Fellowship
3    # for Interpretations of Genomes. All Rights Reserved.
4    #
5    # This file is part of the SEED Toolkit.
6    #
7    # The SEED Toolkit is free software. You can redistribute
8    # it and/or modify it under the terms of the SEED Toolkit
9    # Public License.
10    #
11    # You should have received a copy of the SEED Toolkit Public License
12    # along with this program; if not write to the University of Chicago
13    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14    # Genomes at veronika@thefig.info or download a copy from
15    # http://www.theseed.org/LICENSE.TXT.
16    #
17    
18  use strict;  use strict;
19    
20  #use Common::Errors;  #use Common::Errors;
# Line 29  Line 46 
46      exit;      exit;
47  }  }
48    
49    if (0)
50    {
51    warn "Environment:\n";
52    for my $k (sort keys(%ENV))
53    {
54        warn "$k=$ENV{$k}\n";
55    }
56    
57    warn "Params:\n";
58    for my $k ($cgi->param())
59    {
60        warn "$k=" . $cgi->param($k) . "\n";
61    }
62    }
63    
64  my $fig = new FIG;  my $fig = new FIG;
65  my $job_id = $cgi->param("job_id");  my $job_id = $cgi->param("job_id");
66  my $work_id = $cgi->param("work_id");  my $work_id = $cgi->param("work_id");
67    my $filename = $cgi->param("file");
68    
69  $job_id =~ /^\d+/ or fail "Invalid job_id\n";  $job_id =~ /^\d+/ or fail "Invalid job_id\n";
70  $work_id =~ /^\d+/ or fail "Invalid work_id\n";  $work_id =~ /^\d+/ or fail "Invalid work_id\n";
71    
72    #
73    # If filename has been give, we're uploading. Otherwise
74    # this is a download.
75    
76  my $c = new Cluster::Broker($fig);  my $c = new Cluster::Broker($fig);
77    
78    if ($filename ne "")
79    {
80        warn "Doing upload\n";
81        eval {
82            do_upload($c, $fig, $job_id, $work_id, $filename);
83        };
84        if ($@)
85        {
86            fail "upload failed: $@";
87        }
88    }
89    else
90    {
91        warn "Doing download\n";
92        do_download($c, $fig, $job_id, $work_id);
93    }
94    
95    sub do_upload
96    {
97        my($c, $fig, $job_id, $work_id, $filename) = @_;
98    
99        warn " UPLOAD: jobid=$job_id work_id=$work_id filename=$filename\n";
100    
101        #
102        # Determine location of output file.
103        #
104    
105        my $output_fh = $c->open_output_file($job_id, $work_id, $filename);
106    
107        #
108        # File is passed as the cgi parameter named "file".
109        #
110        my $fh = $cgi->upload('file');
111        warn "Got fh $fh\n";
112    
113        my($n, $buf);
114        while ($n = read($fh, $buf, 4096))
115        {
116            print $output_fh $buf;
117        }
118        close($fh);
119        close($output_fh);
120    
121        print $cgi->header(-type => "text/plain");
122        print "File uploaded OK\n";
123    }
124    
125    sub do_download
126    {
127        my($c, $fig, $job_id, $work_id) = @_;
128    
129  my ($fh, $size, $basename);  my ($fh, $size, $basename);
130    
131  my $ok = eval {  my $ok = eval {
# Line 60  Line 147 
147  }  }
148    
149  close($fh);  close($fh);
150    }
151    
152    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3