File:  [LON-CAPA] / loncom / debugging_tools / dump_db.pl
Revision 1.8: download - view: text, annotated - select for diffs
Wed Jul 25 17:43:34 2007 UTC (16 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_99_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
- properly unti non lonUsers db files

    1: #!/usr/bin/perl -w
    2: #
    3: # The LearningOnline Network
    4: #
    5: # dump_db.pl - dump a GDBM database to standard output, unescaping if asked to.
    6: #
    7: # $Id: dump_db.pl,v 1.8 2007/07/25 17:43:34 albertel Exp $
    8: #
    9: # Copyright Michigan State University Board of Trustees
   10: #
   11: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   12: #
   13: # LON-CAPA is free software; you can redistribute it and/or modify
   14: # it under the terms of the GNU General Public License as published by
   15: # the Free Software Foundation; either version 2 of the License, or
   16: # (at your option) any later version.
   17: #
   18: # LON-CAPA is distributed in the hope that it will be useful,
   19: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21: # GNU General Public License for more details.
   22: #
   23: # You should have received a copy of the GNU General Public License
   24: # along with LON-CAPA; if not, write to the Free Software
   25: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26: #
   27: # /home/httpd/html/adm/gpl.txt
   28: #
   29: # http://www.lon-capa.org/
   30: #
   31: #################################################
   32: use strict;
   33: use Getopt::Long;
   34: use GDBM_File;
   35: use Data::Dumper;
   36: use Storable qw(thaw);
   37: use lib '/home/httpd/lib/perl/';
   38: use LONCAPA;
   39: use LONCAPA::Configuration;
   40: use Cwd;
   41: 
   42: #
   43: # Options
   44: my ($unesc,$help,$localize_times) = (0,0,0);
   45: GetOptions("unescape" => \$unesc,
   46:            "u"        => \$unesc,
   47:            "t"        => \$localize_times,
   48:            "help"     => \$help);
   49: 
   50: #
   51: # Help them out if they ask for it
   52: if ($help) {
   53:     print <<END;
   54: dump_db.pl - dump GDBM_File databases to stdout.  
   55: Specify the database filenames on the command line.
   56: Specify --unescape to have all the keys and values unescaped from every
   57: database.
   58: Options:
   59:    --help     Display this help.
   60:    --unescape Unescape the keys and values before printing them out.
   61:    -u        Same as --unescape
   62:    -t        Localize times when possible (human readable times)
   63: Examples: 
   64:     dump_db.pl mydata.db
   65:     dump_db.pl mydata.db yourdata.db ourdata.db theirdata.db
   66:     dump_db.pl --unescape \*db
   67: END
   68:     exit;
   69: }
   70: 
   71: my  %perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')};
   72: 
   73: #
   74: # Loop through ARGV getting files.
   75: while (my $fname = shift) {
   76:     $fname = &Cwd::abs_path($fname);
   77:     my $dbref;
   78:     if ($fname =~ m/^\Q$perlvar{'lonUsersDir'}\E/) {
   79: 	$dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER());
   80:     } else {
   81: 	if (tie(my %db,'GDBM_File',$fname,&GDBM_READER(),0640)) {
   82: 	    $dbref = \%db;
   83: 	}
   84:     }
   85: 
   86:     if (!$dbref) {
   87:         warn "Unable to tie to $fname";
   88:         next;
   89:     }
   90:     while (my ($key,$value) = each(%$dbref)) {
   91:         if ($value =~ s/^__FROZEN__//) {
   92:             $value = thaw(&unescape($value));
   93:         }
   94:         if ($unesc) {
   95:             $key = &unescape($key);
   96:             $value = &unescape($value) if (! ref($value));
   97:         }
   98:         if ($localize_times && ! ref($value)) {
   99:             $value =~ s/([0-9]{10,10})/localtime($1)/ge;
  100:         }
  101:         print "$key = ".(ref($value)?Dumper($value):$value)."\n";
  102:     }
  103:     if ($fname =~ m/^\Q$perlvar{'lonUsersDir'}\E/) {
  104: 	&LONCAPA::locking_hash_untie($dbref);
  105:     } else {
  106: 	untie($dbref);
  107:     }
  108: }
  109: exit;
  110: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>