File:
[LON-CAPA] /
loncom /
debugging_tools /
dump_db.pl
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Thu Sep 4 14:32:46 2003 UTC (21 years ago) by
matthew
Branches:
MAIN
CVS tags:
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
HEAD
Added automagic time localization command line option '-t'.
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.3 2003/09/04 14:32:46 matthew 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:
36: #
37: # Options
38: my ($unesc,$help,$localize_times) = (0,0,0);
39: GetOptions("unescape" => \$unesc,
40: "u" => \$unesc,
41: "t" => \$localize_times,
42: "help" => \$help);
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.
55: -u Same as --unescape
56: -t Localize times when possible (human readable times)
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);
77: }
78: if ($localize_times) {
79: if ($value =~ /^\s*([0-9]{10,10})\s*$/) {
80: $value = $value.' [ '.localtime($1).' ]';
81: }
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>