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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 27 Jun 2006 14:35:25 -0000


albertel		Tue Jun 27 10:35:25 2006 EDT

  Modified files:              
    /loncom/debugging_tools	clean_db.pl 
  Log:
  - morphing to use LONCAPA.pm
  
  
Index: loncom/debugging_tools/clean_db.pl
diff -u loncom/debugging_tools/clean_db.pl:1.2 loncom/debugging_tools/clean_db.pl:1.3
--- loncom/debugging_tools/clean_db.pl:1.2	Fri Mar 18 16:36:49 2005
+++ loncom/debugging_tools/clean_db.pl	Tue Jun 27 10:35:24 2006
@@ -4,7 +4,7 @@
 #
 # dump_db.pl - dump a GDBM database to standard output, unescaping if asked to.
 #
-# $Id: clean_db.pl,v 1.2 2005/03/18 21:36:49 albertel Exp $
+# $Id: clean_db.pl,v 1.3 2006/06/27 14:35:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,6 +32,8 @@
 use strict;
 use Getopt::Long;
 use GDBM_File;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
 
 #
 # Options
@@ -47,8 +49,6 @@
 And the Key to remove.
 Options:
    --help     Display this help.
-   --unescape Unescape the keys and values before printing them out.
-   -u        Same as --unescape
    -t        Localize times when possible (human readable times)
 Example: 
     dump_db.pl mydata.db "error:"
@@ -59,19 +59,20 @@
 my $fname = shift;
 my $key_to_remove = shift;
 
-my %db;
-if (! tie(%db,'GDBM_File',$fname,&GDBM_WRITER(),0640)) {
-    warn "Unable to tie to $fname";
+my $dbref =&LONCAPA::locking_hash_tie($fname,&GDBM_WRCREAT());
+
+if (! $dbref) {
+    warn("Unable to tie to $fname");
     exit;
 }
-while (my ($key,$value) = each(%db)) {
+while (my ($key,$value) = each(%{$dbref})) {
     if ($key ne $key_to_remove) { next; }
-    delete($db{$key});
+    delete($dbref->{$key});
     if ($fname =~ m|/nohist_[^/]*.db|) { exit; }
     my $hist=$fname;
     $hist=~s/\.db$/.hist/;
     open(HIST,">>$hist");
-    print HIST "D:".time.":$key\n";
+    print HIST ("D:".time.":$key\n");
     close(HIST);
 }
 exit;