[LON-CAPA-cvs] cvs: loncom / lond /interface lonspreadsheet.pm /lonnet/perl lonnet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 13 Jan 2003 21:52:11 -0000


matthew		Mon Jan 13 16:52:11 2003 EDT

  Modified files:              
    /loncom	lond 
    /loncom/interface	lonspreadsheet.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Added new lond command: dumpcurrent.
  Added lonnet::dumpcurrent
  Modified spreadsheet.pm to use dumpcurrent to retrieve user data.
  Some logging information is active, some is not.  More testing required.
  
  
Index: loncom/lond
diff -u loncom/lond:1.104 loncom/lond:1.105
--- loncom/lond:1.104	Wed Dec 18 15:43:29 2002
+++ loncom/lond	Mon Jan 13 16:52:11 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.104 2002/12/18 20:43:29 matthew Exp $
+# $Id: lond,v 1.105 2003/01/13 21:52:11 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1223,6 +1223,48 @@
                               print $client "$qresult\n";
                            } else {
                               print $client "error:$!\n";
+                           }
+                       } else {
+                           print $client "error:$!\n";
+                       }
+# ----------------------------------------------------------------- dumpcurrent
+                   } elsif ($userinput =~ /^dumpcurrent/) {
+                       my ($cmd,$udom,$uname,$namespace)
+                          =split(/:/,$userinput);
+                       $namespace=~s/\//\_/g;
+                       $namespace=~s/\W//g;
+                       my $qresult='';
+                       my $proname=propath($udom,$uname);
+                       if (tie(%hash,'GDBM_File',
+                               "$proname/$namespace.db",
+                               &GDBM_READER(),0640)) {
+                           # Structure of %data:
+                           # $data{$symb}->{$parameter}=$value;
+                           # $data{$symb}->{'v.'.$parameter}=$version;
+                           # since $parameter will be unescaped, we do not
+                           # have to worry about silly parameter names...
+                           my %data = ();
+                           while (my ($key,$value) = each(%hash)) {
+                              my ($v,$symb,$param) = split(/:/,$key);
+                              next if ($v eq 'version' || $symb eq 'keys');
+                              next if (exists($data{$symb}) && 
+                                       exists($data{$symb}->{$param}) &&
+                                       $data{$symb}->{'v.'.$param} > $v);
+                              #&logthis("v = ".$v." p = ".$param." s = ".$symb);
+                              $data{$symb}->{$param}=$value;
+                              $data{$symb}->{'v.'.$param}=$value;
+                           }
+                           if (untie(%hash)) {
+                             while (my ($symb,$param_hash) = each(%data)) {
+                               while(my ($param,$value) = each (%$param_hash)){
+                                 next if ($param =~ /^v\./);
+                                 $qresult.=$symb.':'.$param.'='.$value.'&';
+                               }
+                             }
+                             chop($qresult);
+                             print $client "$qresult\n";
+                           } else {
+                             print $client "error:$!\n";
                            }
                        } else {
                            print $client "error:$!\n";
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.161 loncom/interface/lonspreadsheet.pm:1.162
--- loncom/interface/lonspreadsheet.pm:1.161	Mon Jan 13 09:58:28 2003
+++ loncom/interface/lonspreadsheet.pm	Mon Jan 13 16:52:11 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.161 2003/01/13 14:58:28 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.162 2003/01/13 21:52:11 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2417,12 +2417,18 @@
     my %formulas=&getformulas($sheet);
     $cachedassess=$sheet->{'uname'}.':'.$sheet->{'udom'};
     # Get ALL the student preformance data
-    my @tmp = &Apache::lonnet::dump($sheet->{'cid'},
-                                    $sheet->{'udom'},
-                                    $sheet->{'uname'},
-                                    undef);
-    if ($tmp[0] !~ /^error:/) {
+    my @tmp = &Apache::lonnet::dumpcurrent($sheet->{'cid'},
+#    my @tmp = &Apache::lonnet::dump($sheet->{'cid'},
+                                           $sheet->{'udom'},
+                                           $sheet->{'uname'},
+                                           undef);
+    if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %cachedstores = @tmp;
+#        &Apache::lonnet::logthis("-------------------------------------");
+#        foreach (keys(%cachedstores)) {
+#            &Apache::lonnet::logthis("data for ".$_);
+#        }
+#        &Apache::lonnet::logthis("-------------------------------------");
     }
     undef @tmp;
     # 
@@ -2551,12 +2557,18 @@
         #
         # get data out of the dumped stores
         # 
-        my $version=$cachedstores{'version:'.$symb};
-        my $scope;
-        for ($scope=1;$scope<=$version;$scope++) {
-            foreach (split(/\:/,$cachedstores{$scope.':keys:'.$symb})) {
-                $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
-            } 
+#        my $version=$cachedstores{'version:'.$symb};
+#        my $scope;
+#        for ($scope=1;$scope<=$version;$scope++) {
+#            foreach (split(/\:/,$cachedstores{$scope.':keys:'.$symb})) {
+#                $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
+#            } 
+#        }
+        if (exists($cachedstores{$symb})) {
+            %returnhash = %{$cachedstores{$symb}};
+        } else {
+#            &Apache::lonnet::logthis("No data for ".$symb);
+            %returnhash = ();
         }
     } else {
         #
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.317 loncom/lonnet/perl/lonnet.pm:1.318
--- loncom/lonnet/perl/lonnet.pm:1.317	Fri Jan 10 16:13:00 2003
+++ loncom/lonnet/perl/lonnet.pm	Mon Jan 13 16:52:11 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.317 2003/01/10 21:13:00 www Exp $
+# $Id: lonnet.pm,v 1.318 2003/01/13 21:52:11 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1740,6 +1740,25 @@
    foreach (@pairs) {
       my ($key,$value)=split(/=/,$_);
       $returnhash{unescape($key)}=unescape($value);
+   }
+   return %returnhash;
+}
+
+# --------------------------------------------------------------- dumpcurrent
+sub dumpcurrent {
+   my ($namespace,$udomain,$uname)=@_;
+   if (!$udomain) { $udomain = $ENV{'user.domain'}; }
+   if (!$uname)   { $uname   = $ENV{'user.name'};   }
+   my $uhome = &homeserver($uname,$udomain);
+   my $rep=reply("dumpcurrent:$udomain:$uname:$namespace",$uhome);
+   &logthis("error = ".$rep) if ($rep =~ /^(error|no_such_host)/);
+   return if ($rep =~ /^(error:|no_such_host)/);
+   my @pairs=split(/\&/,$rep);
+   my %returnhash=();
+   foreach (@pairs) {
+      my ($key,$value)=split(/=/,$_);
+      my ($symb,$param) = split(/:/,$key);
+      $returnhash{&unescape($symb)}->{&unescape($param)} = &unescape($value);
    }
    return %returnhash;
 }