[Bio] / FigKernelScripts / WebAppBackend.pl Repository:
ViewVC logotype

View of /FigKernelScripts/WebAppBackend.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Fri Jan 23 16:54:46 2009 UTC (10 years, 9 months ago) by jared
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, HEAD
Changes since 1.1: +2 -2 lines
make user and org commands case insensitive

# -*- perl -*-
########################################################################
# Copyright (c) 2003-2008 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
########################################################################

use Carp;
use Data::Dumper;
use Time::HiRes qw(gettimeofday);
use Time::Local;

use WebApplicationDBHandle;

my($user);

# usage: WebAppBackend [-echo] [-time] [command]

$echo       = 0;
$time_cmds  = 0;
while ((@ARGV > 0) && ($ARGV[0] =~ /^-/))
{
    $arg = shift @ARGV;
    if ($arg =~ /^-time/i) { $time_cmds = 1 }
    if ($arg =~ /^-echo/i) { $echo      = 1 }
    { 
	$url = shift(@ARGV);
    }
}

# get the db connection
my ($db, $error) = WebApplicationDBHandle->new();
if ($error) {
    print "Error connecting to the DB: $error\n";
    exit;
}

my($t1,$t2);
if (@ARGV > 0)  { $req = join( " ", @ARGV ); }
while ( (defined($req) && $req) || ((@ARGV == 0) && ($req = &get_req)) )
{
    if ($time_cmds)
    {
	$t1 = gettimeofday;
    }

    if ($req =~ /^\s*h\s*$/ || $req =~ /^\s*help\s*$/)
    {
     &help;
    }
    elsif ($req =~ /^\s*User\s*/i)
    {
	my $params = {};
	while ($req =~ m/(\S+)=(\S+)/g) { $params->{$1} = $2; }
	my @users = $db->User->get_objects($params);
	print "\n".dump_object(@users)."\n\n";
    }
    elsif ($req =~ /^\s*Organization\s*/i)
    {
	my $params = {};
	while ($req =~ m/(\S+)=(\S+)/g) { $params->{$1} = $2; }
	my @users = $db->Organization->get_objects($params);
	print "\n".dump_object(@users)."\n\n";
    }
    else
    {
	print "invalid command\n";
    }
    print "\n";
    $req = "";

    if ($time_cmds)
    {
	$t2 = gettimeofday;
	print $t2-$t1," seconds to execute command\n\n";
    }
}
sub padded {
    my($x,$n) = @_;

    if (length($x) < $n)
    {
	return $x . (" " x ($n - length($x)));
    }
    return $x;
}

sub get_req {
    my($x);

    print "?? ";
    $x = <STDIN>;
    while (defined($x) && ($x =~ /^h$/i) )
    { 
	&help;
	print "?? ";
	$x = <STDIN>;
    }
    
    if ((! defined($x)) || ($x =~ /^\s*[qQxX]/))
    {
	return "";
    }
    else
    {
        if ($echo)
	{
	    print ">> $x\n";
	}
	return $x;
    }
}

sub dump_object {
    my ($objects) = @_;

    unless (ref($objects) eq "ARRAY") {
	$objects = [ $objects ];
    }
    foreach my $object (@$objects) {
	foreach my $key (sort(keys(%$object))) {
	    if ($key !~ /^_/) {
		print "\n$key\t".$object->{$key};
	    }
	}
	print "\n";
    }
}

sub help {
    print <<END;
    help               displays this message
    quit               exits this program
    User               shows all users, add parameters to specify a user
    Organization       shows all organizations, add parameters to specify an organization
END
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3