Annotation of loncom/debugging_tools/dump_db.pl, revision 1.3
1.1 matthew 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: #
1.3 ! matthew 7: # $Id: dump_db.pl,v 1.2 2002/09/04 20:49:16 matthew Exp $
1.1 matthew 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:
36: #
37: # Options
1.3 ! matthew 38: my ($unesc,$help,$localize_times) = (0,0,0);
1.1 matthew 39: GetOptions("unescape" => \$unesc,
1.2 matthew 40: "u" => \$unesc,
1.3 ! matthew 41: "t" => \$localize_times,
1.2 matthew 42: "help" => \$help);
1.1 matthew 43:
44: #
45: # Help them out if they ask for it
46: if ($help) {
47: print <<END;
48: dump_db.pl - dump GDBM_File databases to stdout.
49: Specify the database filenames on the command line.
50: Specify --unescape to have all the keys and values unescaped from every
51: database.
52: Options:
53: --help Display this help.
54: --unescape Unescape the keys and values before printing them out.
1.3 ! matthew 55: -u Same as --unescape
! 56: -t Localize times when possible (human readable times)
1.1 matthew 57: Examples:
58: dump_db.pl mydata.db
59: dump_db.pl mydata.db yourdata.db ourdata.db theirdata.db
60: dump_db.pl --unescape \*db
61: END
62: exit;
63: }
64:
65: #
66: # Loop through ARGV getting files.
67: while (my $fname = shift) {
68: my %db;
69: if (! tie(%db,'GDBM_File',$fname,&GDBM_READER,0640)) {
70: warn "Unable to tie to $fname";
71: next;
72: }
73: while (my ($key,$value) = each(%db)) {
74: if ($unesc) {
75: $key = &unescape($key);
76: $value = &unescape($value);
1.3 ! matthew 77: }
! 78: if ($localize_times) {
! 79: if ($value =~ /^\s*([0-9]{10,10})\s*$/) {
! 80: $value = $value.' [ '.localtime($1).' ]';
! 81: }
1.1 matthew 82: }
83: print "$key = $value\n";
84: }
85: untie %db;
86: }
87: exit;
88:
89: ######################################
90: sub unescape {
91: my $str=shift;
92: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
93: return $str;
94: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>