[LON-CAPA-cvs] cvs: loncom /configuration Configuration.pm

harris41 lon-capa-cvs@mail.lon-capa.org
Fri, 03 May 2002 23:57:19 -0000


harris41		Fri May  3 19:57:19 2002 EDT

  Added files:                 
    /loncom/configuration	Configuration.pm 
  Log:
  Relating to BUG 129
  Modularizing the reading of PerlSetVar from configuration files.
  
  This is expected to become part of the following scripts:
  
  lonc
  loncron
  lond
  lonsql
  test_weblayer.pl
  loncaparestoreconfigurations
  make_domain_coordinator.pl
  make_rpm.pl
  postinstall.pl.... duplicate functionality as doc/loncapafiles/updatequery.piml
  updatequery.piml
  sqltest.pl ... read access.conf
  clusterstatus.pl
  metadata_keywords.pl
  ping.pl
  loncontrol
  lonnet.c
  lonnet.pm
  searchcat.pl
  
  
  

Index: loncom/configuration/Configuration.pm
+++ loncom/configuration/Configuration.pm
# The LearningOnline Network with CAPA
# Configuration file reader
#
# $Id: Configuration.pm,v 1.1 2002/05/03 23:57:19 harris41 Exp $
#
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# YEAR=2002
# 05/03 Scott Harrison
#
###

package LONCAPA::Configuration;

$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);

use strict;

my $confdir='/etc/httpd/conf/';

# ------------------------------------ read_conf: read LON-CAPA server configuration, especially PerlSetVar values
sub read_conf {
    my (@conf_files)=@_;
    my %perlvar;
    foreach my $filename (@conf_files) {
	open(CONFIG,'<'.$confdir.$filename) or die("Can't read access.conf");
	while (my $configline=<CONFIG>) {
	    if ($configline =~ /^[^\#]*PerlSetVar/) {
		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
		chomp($varvalue);
		$perlvar{$varname}=$varvalue;
	    }
	}
	close(CONFIG);
    }
    my $perlvarref=\%perlvar;
    return ($perlvarref);
}

__END__

=pod

=head1 NAME

B<LONCAPA::Configuration> - configuration file reader

=head1 SYNOPSIS

 use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;

 LONCAPA::Configuration::read_conf('access.conf','loncapa.conf');

In the future, standard invocation of the command will be:

 LONCAPA::Configuration::read_conf('loncapa.conf');

F<access.conf> is slowly becoming deprecated.  (We are currently
trying to support backwards compatibility.)

=head1 DESCRIPTION

Many different parts of the LON-CAPA software need to read in the machine-specific
configuration information.  These included scripts controlling the TCP/IP layer
(e.g. F<lonc> and F<lond>), testing scripts (e.g. test_weblayer.pl and sqltest.pl),
and utility scripts (e.g. clusterstatus.pl and metadata_keywords.pl).

The following methods are available:

=over 4

=item $perlvarref = LONCAPA::Configuration::read_conf( @filename_list );

On a typical LON-CAPA server, the filename list argument will consist of
just one element, "loncapa.conf".

If there are multiple elements within the filename list, then these
filenames are processed consecutively.

A hash reference is returned and consists of those values which
have been initialized from the configuration filenames indicated
in the arguments.

If multiple file names define the same hash key, then priority is
given toward the last file name processed.

=back

=head1 AUTHORS

Scott Harrison

This library is free software; you can redistribute it and/or
modify it under the same terms as LON-CAPA itself.

=cut