File:  [LON-CAPA] / loncom / interface / lontest.pm
Revision 1.22: download - view: text, annotated - select for diffs
Mon Nov 24 17:18:01 2008 UTC (15 years, 5 months ago) by jms
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_99_1, version_2_8_99_0, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
POD comments added/altered

    1: # The LearningOnline Network with CAPA
    2: # A debugging harness.
    3: #
    4: # $Id: lontest.pm,v 1.22 2008/11/24 17:18:01 jms Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: 
   30: 
   31: package Apache::lontest;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use GDBM_File;
   36: use Apache::loncommon;
   37: use Apache::lonnet;
   38: 
   39: sub section
   40: {
   41:     my ($name) = @_;
   42:     return $1 if $name =~ m/\A([^.]*)\./;
   43:     return '';
   44: }
   45: 
   46: sub print_hash {
   47:     my ($r,$hash)=@_;
   48:     my $i=0;
   49:     my $interval = 20; # change this to change how many keys/table
   50:     my $prevSection = ''; # keeps track of the section we're in.
   51: 
   52:     foreach my $envkey (sort(keys(%{$hash}))) {
   53: 	if (not ($i % $interval)) {
   54: 	    $r->print('</table>') unless $i eq 0;
   55: 	    $r->print('<table border="0">');
   56: 	}
   57: 	my $sec = section($envkey);
   58: 	
   59: 	if ($prevSection ne $sec) { # new section, print header 
   60: 	    $r->print('<tr><td colspan="2">');
   61: 	    $r->print("<br /><br /><h2 style='color: #008800'><u>$sec</u></h2>");
   62: 	    $r->print('</td></tr>');
   63: 	    $prevSection = $sec;
   64: 	}
   65: 
   66: 	my $envVal = $hash->{$envkey};
   67: 	$envVal =~ s/(.{50})/$1\<wbr\>/g;
   68: 	$envkey =~ s/(.{30})/$1\<wbr\>/g;
   69: 	 
   70: 	$r->print("<tr><td valign='top'><b>$envkey</b></td>");
   71: 	$r->print("<td valign='top'>$envVal</td></tr>\n");
   72: 	$i++;
   73:     }
   74: 
   75:     $r->print('</table></font><h1>Total Number of Elements: '.$i.'</h1>');
   76: }
   77: sub handler {
   78:     my $r = shift;
   79:     &Apache::loncommon::content_type($r,'text/html');
   80:     $r->send_http_header;
   81:     return OK if $r->header_only;
   82: 
   83:     $r->print(&Apache::loncommon::start_page("List Environment",undef,
   84: 					     {'function' => 'admin'}));
   85: 
   86:     $r->print("<hr /><h1>Debugging</h1><hr />\n");
   87:     $r->print("<font face='Courier'>");
   88:     $r->print("<hr /><h2>ENV</h2><hr />\n");
   89:     &print_hash($r,\%ENV);
   90:     $r->print("<hr /><h2>env</h2><hr />\n");
   91:     &print_hash($r,\%env);
   92: # ------------------------------------------------ If in a course, print hashes
   93:     if ($env{'request.course.id'}) {
   94: 
   95: 	my %parmhash;
   96: 	my %symbhash;
   97: 	my %hash;
   98: 
   99: 	my $fn=$env{'request.course.fn'};
  100: 
  101: 	if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
  102: 	    $r->print('<h2>Big Hash</h2>');
  103: 	    foreach (sort keys %hash) {
  104: 		$r->print("\n<br />".$_.': '.$hash{$_});
  105: 	    }
  106: 	    untie %hash;
  107: 	} else {
  108: 	    $r->print('<h2>Count not tie big hash</h2>');
  109: 	}
  110: 	if (tie(%parmhash,'GDBM_File',
  111: 		$env{'request.course.fn'}.'_parms.db',
  112: 		&GDBM_READER(),0640)) {
  113: 	    $r->print('<h2>Parm Hash</h2>');
  114: 	    foreach (sort keys %parmhash) {
  115: 	        $r->print("\n<br />".$_.': '.$parmhash{$_});
  116: 	    }
  117: 	    untie %parmhash;
  118: 	} else {
  119:             $r->print('<h2>Could not tie parmhash</h2>');
  120: 	}
  121: 	if (tie(%symbhash,'GDBM_File',"$fn\_symb.db",&GDBM_READER(),0640)) {
  122:             $r->print('<h2>Symb Hash</h2>');
  123:             foreach (sort keys %symbhash) {
  124: 		$r->print("\n<br />".$_.': '.$symbhash{$_});
  125:             }
  126:             untie %symbhash;
  127: 	} else {
  128:             $r->print('<h2>Could not tie symbhash</h2>');
  129: 	}
  130: 	if (-e $fn.'.state') {
  131: 	    $r->print('<h2>State</h2>');
  132: 	    my @conditions=();
  133: 	    {
  134: 		my $fh=Apache::File->new($fn.'.state');
  135: 		@conditions=<$fh>;
  136: 	    }
  137: 	    foreach (@conditions) {
  138: 		$r->print('<tt>'.$_.'</tt><br />');
  139: 	    }
  140: 	}
  141:     }
  142:  
  143: # ------------------------------------------------------------------- End Debug
  144:      $r->print(&Apache::loncommon::end_page());    
  145:      return OK;
  146:  }
  147: 
  148: 
  149: 1;
  150: __END__
  151: 
  152: =pod
  153: 
  154: =head1 NAME
  155: 
  156: Apache::lontest;
  157: 
  158: =head1 SYNOPSIS
  159: 
  160: Used for debugging and testing the LONCAPA
  161: system.
  162: 
  163: This is part of the LearningOnline Network with CAPA project
  164: described at http://www.lon-capa.org.
  165: 
  166: =head1 HANDLER SUBROUTINE
  167: 
  168: handler()
  169: 
  170: =head1 OTHER SUBROUTINES
  171: 
  172: =over
  173: 
  174: =item  section() : 
  175: 
  176: section takes one env var name as input, and returns
  177: what section the given env var is in, which is the part
  178: of the env var before the first period.
  179: Returns the section, or blank string for 'no section',
  180: which is normal for the standard env vars like REQUEST_URI.
  181: 
  182: =item  print_hash()
  183: 
  184: =back
  185: 
  186: =cut
  187: 
  188: 
  189: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>