[Bio] / RAST / rast.cgi Repository:
ViewVC logotype

View of /RAST/rast.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (download) (annotate)
Wed Apr 28 21:58:51 2010 UTC (9 years, 7 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_02212011, rast_rel_2014_0912, rast_rel_2010_0928, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2010_1206, rast_rel_2011_0119, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_02222011
Changes since 1.13: +1 -1 lines
New RAST genome upload support.

use strict;
use warnings;

use DBMaster;
use WebApplication;
use WebMenu;
use WebLayout;
use WebConfig;

#use IO::Handle;
#open(TICKLOG, ">/dev/pts/9") or open(TICKLOG, ">&STDERR");
#TICKLOG->autoflush(1);

use Time::HiRes 'gettimeofday';
my $start = gettimeofday;
my $time_last;
sub tick {
    my($w) = @_;
    my $now = gettimeofday;
    my $t = $now - $start;
    my $tms = int(($now - $time_last) * 1000);
    $time_last = $now;
    my ($package, $filename, $line) = caller;

    printf TICKLOG "$$ %-40s %5d %5d %.3f\n", $filename, $line, $tms, $t;
    TICKLOG->flush();
}

my $have_fcgi;
eval {
    require CGI::Fast;
    $have_fcgi = 1;
};


#
# If no CGI vars, assume we are invoked as a fastcgi service.
#
my $n_requests = 0;
if ($have_fcgi && $ENV{REQUEST_METHOD} eq '')
{
    #
    # Precompile modules. Find where we found one, and use that path
    # to walk for the rest.
    #
    
    my $mod_path = $INC{"WebComponent/Ajax.pm"};
    if ($mod_path && $mod_path =~ s,WebApplication/WebComponent/Ajax\.pm$,,)
    {
	local $SIG{__WARN__} = sub {};
	for my $what (qw(SeedViewer RAST WebApplication))
	{
	    for my $which (qw(WebPage WebComponent DataHandler))
	    {
		opendir(D, "$mod_path/$what/$which") or next;
		my @x = grep { /^[^.]/ } readdir(D);
		for my $mod (@x)
		{
		    $mod =~ s/\.pm$//;
		    my $fullmod = join("::", $what, $which, $mod);
		    eval " require $fullmod; ";
		}
		closedir(D);
	    }
	}
    }
    my $max_requests = 100;
    while ((my $cgi = new CGI::Fast()) &&
	   ($max_requests == 0 || $n_requests++ < $max_requests))
    {
	eval {
	    &main($cgi);
	};
	if ($@)
	{
	    if ($@ =~ /^cgi_exit/)
	    {
		# this is ok.
	    }
	    elsif (ref($@) ne 'ARRAY')
	    {
		warn "code died, cgi=$cgi returning error '$@'\n";
		print $cgi->header(-status => '500 error in body of cgi processing');
		print $@;
	    }
	}
    endloop:
    }

}
else
{
    my $cgi = new CGI();
    eval { &main($cgi); };

    if ($@ && $@ !~ /^cgi_exit/)
    {
	my $error = $@;
#	Warn("Script error: $error") if T(SeedViewer => 0);
	
	print CGI::header();
	print CGI::start_html();
	
	# print out the error
	print '<pre>'.$error.'</pre>';
	
	print CGI::end_html();
    }
}

sub main {
    my($cgi) = @_;

# read local WebConfig because we need it here
    &WebConfig::import_local_config('RAST');
    
    # choose a layout
    my $layout = WebLayout->new("$FIG_Config::fig/CGI/Html/RAST.tmpl");
    $layout->add_css(TMPL_URL_PATH.'/web_app_default.css');
    $layout->add_css(TMPL_URL_PATH.'/rast.css');
    
    # add site meter
    my $site_meter = $FIG_Config::site_meter;
    if ($site_meter) {
        $layout->add_javascript("http://s20.sitemeter.com/js/counter.js?site=s20nmpdr");
    }
    
    # create the menu
    my $menu = WebMenu->new();
    
    $menu->add_category('Home', 'rast.cgi', undef, [ 'login' ]);
    $menu->add_entry('Home', 'About RAST', 'http://www.nmpdr.org/FIG/wiki/view.cgi/Main/RAST', '_blank');
    $menu->add_entry('Home', 'RAST FAQ', 'http://www.nmpdr.org/FIG/wiki/view.cgi/Main/RASTFAQ', '_blank');
    $menu->add_entry('Home', 'SeedViewer', 'seedviewer.cgi');
    $menu->add_category('Your Jobs', 'rast.cgi?page=Jobs', undef, [ 'login' ]);
    $menu->add_entry('Your Jobs', 'Jobs Overview', 'rast.cgi?page=Jobs');
    $menu->add_entry('Your Jobs', 'Upload New Job', 'rast.cgi?page=Upload');
    $menu->add_entry('Your Jobs', 'Private Organism Preferences', '?page=PrivateOrganismPreferences');
    $menu->add_category('Import Control', 'rast.cgi?page=ControlCenter', undef, [ 'import' ]);
    
    # init the WebApplication
    my $WebApp = WebApplication->new( { id       => 'RAST',
					    menu     => $menu,
					    layout   => $layout,
					    cgi => $cgi,
					    default  => 'Home',
					} );
    
    $WebApp->page_title_prefix('RAST Server - ');
    
    $WebApp->run();
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3