Annotation of loncom/metadata_database/dump_db.pl, revision 1.1

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: #
        !             7: # $Id$
        !             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 = 0;
        !            39: my $help = 0;
        !            40: GetOptions("unescape" => \$unesc,
        !            41:              "help"     => \$help);
        !            42: 
        !            43: #
        !            44: # Help them out if they ask for it
        !            45: if ($help) {
        !            46:     print <<END;
        !            47: dump_db.pl - dump GDBM_File databases to stdout.  
        !            48: Specify the database filenames on the command line.
        !            49: Specify --unescape to have all the keys and values unescaped from every
        !            50: database.
        !            51: Options:
        !            52:    --help     Display this help.
        !            53:    --unescape Unescape the keys and values before printing them out.
        !            54: Examples: 
        !            55:     dump_db.pl mydata.db
        !            56:     dump_db.pl mydata.db yourdata.db ourdata.db theirdata.db
        !            57:     dump_db.pl --unescape \*db
        !            58: END
        !            59:     exit;
        !            60: }
        !            61: 
        !            62: #
        !            63: # Loop through ARGV getting files.
        !            64: while (my $fname = shift) {
        !            65:     my %db;
        !            66:     if (! tie(%db,'GDBM_File',$fname,&GDBM_READER,0640)) {
        !            67:         warn "Unable to tie to $fname";
        !            68:         next;
        !            69:     }
        !            70:     while (my ($key,$value) = each(%db)) {
        !            71:         if ($unesc) {
        !            72:             $key = &unescape($key);
        !            73:             $value = &unescape($value);
        !            74:         }
        !            75:         print "$key = $value\n";
        !            76:     }
        !            77:     untie %db;
        !            78: }
        !            79: exit;
        !            80: 
        !            81: ######################################
        !            82: sub unescape {
        !            83:     my $str=shift;
        !            84:     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        !            85:     return $str;
        !            86: }

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