[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 08 Dec 2003 15:06:42 -0000


raeburn		Mon Dec  8 10:06:42 2003 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  Replaced use of Apache::File for opening of files with open() to allow use of loncommon.pm outside Apache, i.e., in standalone mode in scripts owned by www, run from cron, as required for automated enrollment updates.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.157 loncom/interface/loncommon.pm:1.158
--- loncom/interface/loncommon.pm:1.157	Mon Dec  1 09:36:22 2003
+++ loncom/interface/loncommon.pm	Mon Dec  8 10:06:42 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.157 2003/12/01 14:36:22 matthew Exp $
+# $Id: loncommon.pm,v 1.158 2003/12/08 15:06:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -102,32 +102,34 @@
     unless ($readit) {
 # ------------------------------------------------------------------- languages
     {
-	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
-				 '/language.tab');
-	if ($fh) {
-	    while (<$fh>) {
-		next if /^\#/;
-		chomp;
-		my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_));
-		$language{$key}=$val.' - '.$enc;
-		if ($sup) {
-		    $supported_language{$key}=$sup;
-		}
-	    }
-	}
+        my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+                                   '/language.tab';
+        if ( open(my $fh,"<$langtabfile") ) {
+            while (<$fh>) {
+                next if /^\#/;
+                chomp;
+                my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_));
+                $language{$key}=$val.' - '.$enc;
+                if ($sup) {
+                    $supported_language{$key}=$sup;
+                }
+            }
+            close($fh);
+        }
     }
 # ------------------------------------------------------------------ copyrights
     {
-	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
-				  '/copyright.tab');
-	if ($fh) {
-	    while (<$fh>) {
-		next if /^\#/;
-		chomp;
-		my ($key,$val)=(split(/\s+/,$_,2));
-		$cprtag{$key}=$val;
-	    }
-	}
+        my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
+                                  '/copyright.tab';
+        if ( open (my $fh,"<$copyrightfile") ) {
+            while (<$fh>) {
+                next if /^\#/;
+                chomp;
+                my ($key,$val)=(split(/\s+/,$_,2));
+                $cprtag{$key}=$val;
+            }
+            close($fh);
+        }
     }
 
 # -------------------------------------------------------------- domain designs
@@ -138,15 +140,16 @@
     while ($filename=readdir(DIR)) {
 	my ($domain)=($filename=~/^(\w+)\./);
     {
-	my $fh=Apache::File->new($designdir.'/'.$filename);
-	if ($fh) {
-	    while (<$fh>) {
-		next if /^\#/;
-		chomp;
-		my ($key,$val)=(split(/\=/,$_));
-		if ($val) { $designhash{$domain.'.'.$key}=$val; }
-	    }
-	}
+        my $designfile = $designdir.'/'.$filename;
+        if ( open (my $fh,"<$designfile") ) {
+            while (<$fh>) {
+                next if /^\#/;
+                chomp;
+                my ($key,$val)=(split(/\=/,$_));
+                if ($val) { $designhash{$domain.'.'.$key}=$val; }
+            }
+            close($fh);
+        }
     }
 
     }
@@ -155,32 +158,35 @@
 
 # ------------------------------------------------------------- file categories
     {
-	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
-				  '/filecategories.tab');
-	if ($fh) {
-	    while (<$fh>) {
-		next if /^\#/;
-		chomp;
-		my ($extension,$category)=(split(/\s+/,$_,2));
-		push @{$category_extensions{lc($category)}},$extension;
-	    }
-	}
+        my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+                                  '/filecategories.tab';
+        if ( open (my $fh,"<$categoryfile") ) {
+            while (<$fh>) {
+                next if /^\#/;
+                chomp;
+                my ($extension,$category)=(split(/\s+/,$_,2));
+                push @{$category_extensions{lc($category)}},$extension;
+            }
+            close($fh);
+        }
+
     }
 # ------------------------------------------------------------------ file types
     {
-	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
-	       '/filetypes.tab');
-	if ($fh) {
+        my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+               '/filetypes.tab';
+        if ( open (my $fh,"<$typesfile") ) {
             while (<$fh>) {
-		next if (/^\#/);
-		chomp;
-		my ($ending,$emb,$descr)=split(/\s+/,$_,3);
-		if ($descr ne '') { 
-		    $fe{$ending}=lc($emb);
-		    $fd{$ending}=$descr;
-		}
-	    }
-	}
+                next if (/^\#/);
+                chomp;
+                my ($ending,$emb,$descr)=split(/\s+/,$_,3);
+                if ($descr ne '') {
+                    $fe{$ending}=lc($emb);
+                    $fd{$ending}=$descr;
+                }
+            }
+            close($fh);
+        }
     }
     &Apache::lonnet::logthis(
               "<font color=yellow>INFO: Read file types</font>");
@@ -2390,9 +2396,12 @@
     my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
 	'_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$;
     {
-	my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
-				 '/tmp/'.$datatoken.'.tmp');
-	print $fh $ENV{'form.upfile'};
+        my $datafile = $r->dir_config('lonDaemons').
+                           '/tmp/'.$datatoken.'.tmp';
+        if ( open(my $fh,">$datafile") ) {
+            print $fh $ENV{'form.upfile'};
+            close($fh);
+        }
     }
     return $datatoken;
 }
@@ -2411,11 +2420,12 @@
     my $r=shift;
     my @studentdata=();
     {
-	my $fh;
-	if ($fh=Apache::File->new($r->dir_config('lonDaemons').
-				  '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) {
-	    @studentdata=<$fh>;
-	}
+        my $studentfile = $r->dir_config('lonDaemons').
+                              '/tmp/'.$ENV{'form.datatoken'}.'.tmp';
+        if ( open(my $fh,"<$studentfile") ) {
+            @studentdata=<$fh>;
+            close($fh);
+        }
     }
     $ENV{'form.upfile'}=join('',@studentdata);
 }