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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 03 Aug 2006 17:53:47 -0000


albertel		Thu Aug  3 13:53:47 2006 EDT

  Modified files:              
    /loncom/debugging_tools	rebuild_db_from_hist.pl 
  Log:
  - teaching it about the 'M' command from lond's putstore
  - making the test db creation an option
  
  
Index: loncom/debugging_tools/rebuild_db_from_hist.pl
diff -u loncom/debugging_tools/rebuild_db_from_hist.pl:1.5 loncom/debugging_tools/rebuild_db_from_hist.pl:1.6
--- loncom/debugging_tools/rebuild_db_from_hist.pl:1.5	Thu Aug  3 13:27:48 2006
+++ loncom/debugging_tools/rebuild_db_from_hist.pl	Thu Aug  3 13:53:47 2006
@@ -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.5 2006/08/03 17:27:48 albertel Exp $
+# $Id: rebuild_db_from_hist.pl,v 1.6 2006/08/03 17:53:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,11 +38,12 @@
 
 #
 # Options
-my ($help,$debug,$test,$p_is_s);
-GetOptions("help"    => \$help,
-           "debug"   => \$debug,
-           "test"    => \$test,
-           "p_is_s"  => \$p_is_s);
+my ($help,$debug,$test,$test_db,$p_is_s);
+GetOptions("help"           => \$help,
+           "debug"          => \$debug,
+           "test"           => \$test,
+           "create_test_db" => \$test_db,
+           "p_is_s"         => \$p_is_s);
 
 if (! defined($debug))   { $debug   = 0; }
 if (! defined($test))    { $test    = 0; }
@@ -57,6 +58,8 @@
    -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.
+   -create_test_db
+             when testing also create a *.db.test db of the testing info
    -p_is_s   Treat 'P' lines as 'S' lines.
 Examples: 
     rebuild_db_from_hist.pl -t $file.hist  # Perform a test rebuild
@@ -76,7 +79,7 @@
     my $db_filename = $fname;
     $db_filename =~ s/\.hist$/\.db/;
     if (-e $db_filename && ! $test) {
-        print "Aborting: The target file $db_filename exists.".$/;
+        print STDERR "Aborting: The target file $db_filename exists.".$/;
         next;
     }
     my ($error,$constructed_hash) = &process_file($fname,$db_filename,$debug);
@@ -86,14 +89,14 @@
     if (! defined($error) || ! $test) {
         $error = &write_hash($db_filename,$constructed_hash);
     }
-    if ($test) {
+    if ($test && $test_db) {
         $error = &write_hash($db_filename.'.test',$constructed_hash);
     }
     if ($test) {
         my $error = &test_hash($db_filename,$constructed_hash);
         if (defined($error)) {
             print "Error processing ".$fname.$/;
-            print $error;
+            print STDERR $error;
         } else {
             print "Everything looks good for ".$fname.$/;
         }
@@ -121,18 +124,23 @@
         #  S:store
         #  D:delete
         #  N:new put (only adds tha values if they are all new values)
+	#  M:modify the values for a previous S
         my ($action,$time,$concatenated_data) = split(':',$command,3);
         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);
+        my ($rid,@allkeys,$version);
         if ($action eq 'S') {
             ($rid,$concatenated_data) = split(':',$concatenated_data,2);
             $version = ++$db_to_store{"version:$rid"};
              #print $version.$/;
         }
+	if ($action eq 'M') {
+            ($rid,$version,$concatenated_data) = 
+		split(':',$concatenated_data,3);
+	}
         next if (! defined($concatenated_data));
 	my $add_new_data = 1;
         my @data = split('&',$concatenated_data);
@@ -144,9 +152,9 @@
                 } else {
                     $no_action_count++;
                 }
-            } elsif ($action eq 'S') {
+            } elsif ($action eq 'S' || $action eq 'M') {
                 # Versioning of data, so we update the old ata
-                $allkeys.=$key.':';
+                push(@allkeys,$key);
                 $db_to_store{"$version:$rid:$key"}=$value;
             } elsif ($action eq 'N') {
                 if (exists($db_to_store{$key})) {
@@ -159,16 +167,19 @@
                 $error = "Unable to understand action '".$action."'";
             }
         }
+
 	if ($action eq 'N' && $add_new_data) {
 	    foreach my $k_v_pair (@data) {
 		my ($key,$value) = split('=',$k_v_pair,2);
 		$db_to_store{$key}=$value;
 	    }
 	}
-        if ($action eq 'S') {
+	if ($action eq 'S') {
 	    $db_to_store{"$version:$rid:timestamp"}=$time;
-	    $allkeys.='timestamp';
-	    $db_to_store{"$version:keys:$rid"}=$allkeys;
+	    push(@allkeys,'timestamp');
+	}
+        if ($action eq 'S' || $action eq 'M') {
+	    $db_to_store{"$version:keys:$rid"}=join(':',@allkeys);
         }
         if (defined($error)) {
             return ('Error:'.$error.$/,undef);