[LON-CAPA-cvs] cvs: loncom /debugging_tools rebuild_db_from_hist.pl

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 09 Dec 2004 22:25:47 -0000


matthew		Thu Dec  9 17:25:47 2004 EDT

  Modified files:              
    /loncom/debugging_tools	rebuild_db_from_hist.pl 
  Log:
  Added handling of 'S' storage.
  Made error messages a little more specific.
  
  
Index: loncom/debugging_tools/rebuild_db_from_hist.pl
diff -u loncom/debugging_tools/rebuild_db_from_hist.pl:1.3 loncom/debugging_tools/rebuild_db_from_hist.pl:1.4
--- loncom/debugging_tools/rebuild_db_from_hist.pl:1.3	Thu Dec  9 15:01:48 2004
+++ loncom/debugging_tools/rebuild_db_from_hist.pl	Thu Dec  9 17:25:47 2004
@@ -4,7 +4,7 @@
 #
 # rebuild_db_from_hist.pl Rebuild a *.db file from a *.hist file
 #
-# $Id: rebuild_db_from_hist.pl,v 1.3 2004/12/09 20:01:48 matthew Exp $
+# $Id: rebuild_db_from_hist.pl,v 1.4 2004/12/09 22:25:47 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,10 +35,11 @@
 
 #
 # Options
-my ($help,$debug,$test);
+my ($help,$debug,$test,$p_is_s);
 GetOptions("help"    => \$help,
            "debug"   => \$debug,
-           "test"    => \$test);
+           "test"    => \$test,
+           "p_is_s"  => \$p_is_s);
 
 if (! defined($debug))   { $debug   = 0; }
 if (! defined($test))    { $test    = 0; }
@@ -53,6 +54,7 @@
    -debug    Output debugging code (not much is output yet)
    -test     Verify the given *.hist file will reconstruct the current db file
              Sends error messages to STDERR.
+   -p_is_s   Treat 'P' lines as 'S' lines.
 Examples: 
     rebuild_db_from_hist.pl -t $file.hist  # Perform a test rebuild
     rebuild_db_from_hist.pl $file.hist       
@@ -107,6 +109,15 @@
         if ($fname eq 'roles.hist' && $concatenated_data =~ /^.*:.*:/) {
             (undef,undef,$concatenated_data) = split(':',$concatenated_data,3);
         }
+        next if (! defined($action));
+        if ($action eq 'P' && $p_is_s) { $action = 'S'; }
+        my ($rid,$allkeys,$version);
+        if ($action eq 'S') {
+            ($rid,$concatenated_data) = split(':',$concatenated_data,2);
+            $version = ++$db_to_store{"version:$rid"};
+            # print $version.$/;
+        }
+        next if (! defined($concatenated_data));
         my @data = split('&',$concatenated_data);
         foreach my $k_v_pair (@data) {
             my ($key,$value) = split('=',$k_v_pair,2);
@@ -116,12 +127,21 @@
                 } else {
                     $no_action_count++;
                 }
+            } elsif ($action eq 'S') {
+                # Versioning of data, so we update the old ata
+                $allkeys.=$key.':';
+                $db_to_store{"$version:$rid:$key"}=$value;
             } elsif ($action eq 'D') {
                 delete($db_to_store{$key});
             } else {
                 $error = "Unable to understand action '".$action."'";
             }
         }
+        if ($action eq 'S') {
+	    $db_to_store{"$version:$rid:timestamp"}=$time;
+	    $allkeys.='timestamp';
+	    $db_to_store{"$version:keys:$rid"}=$allkeys;
+        }
         if (defined($error)) {
             return ('Error:'.$error.$/,undef);
         }
@@ -175,21 +195,21 @@
     my $error;
     my $extra_count = scalar(keys(%$my_db));
     if ($extra_count) {
-        $error.=$extra_count.' extra key/value pairs found: '.$/;
+        $error.=$extra_count.' extra key/value pairs found in hist: '.$/;
         while (my ($k,$v) = each(%$my_db)) {
             $error .= '  "'.$k.'" => "'.$v.'"'.$/;
         }
     }
     my $key_count = scalar(keys(%key_errors));
     if ($key_count) {
-        $error.=$key_count.' missing keys found: '.$/;
+        $error.=$key_count.' missing keys found in db but not in hist: '.$/;
         while (my ($k,$v) = each(%key_errors)) {
             $error .= '  "'.$k.'" => "'.$v.'"'.$/;
         }
     }
     my $value_count = scalar(keys(%value_errors));
     if ($value_count) {
-        $error.=$value_count.' missing values found: '.$/;
+        $error.=$value_count.' mismatched values found: '.$/;
         while (my ($k,$v) = each(%value_errors)) {
             $error .= '  "'.$k.'" => "'.$v.'"'.$/;
         }