[system] / tags / rel-2-0-pr5-try2 / webwork-modperl / bin / wwdb Repository:
ViewVC logotype

View of /tags/rel-2-0-pr5-try2/webwork-modperl/bin/wwdb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2149 - (download) (annotate)
Sat May 22 01:08:10 2004 UTC (9 years ago)
File size: 3013 byte(s)
This commit was manufactured by cvs2svn to create tag 'rel-2-0-pr5-try2'.

    1 #!/usr/bin/env perl
    2 ################################################################################
    3 # WeBWorK Online Homework Delivery System
    4 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    5 # $CVSHeader: webwork-modperl/bin/wwdb,v 1.9 2004/04/29 23:33:26 sh002i Exp $
    6 # 
    7 # This program is free software; you can redistribute it and/or modify it under
    8 # the terms of either: (a) the GNU General Public License as published by the
    9 # Free Software Foundation; either version 2, or (at your option) any later
   10 # version, or (b) the "Artistic License" which comes with this package.
   11 # 
   12 # This program is distributed in the hope that it will be useful, but WITHOUT
   13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   14 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   15 # Artistic License for more details.
   16 ################################################################################
   17 
   18 =head1 NAME
   19 
   20 wwdb - export and import webwork databases.
   21 
   22 =head1 SYNOPSIS
   23 
   24  wwdb [-f] course { import | export } file [table ...]
   25 
   26 =head1 DESCRIPTION
   27 
   28 Exports data from a course database to an XML file, or imports data from an XML
   29 file to a course database. Optionally restrict which tables are imported or
   30 exported and specify a duplicate policy.
   31 
   32 =head1 OPTIONS
   33 
   34 =over
   35 
   36 =item -f
   37 
   38 Overwite duplicate records.
   39 
   40 =item course
   41 
   42 Course to use for import or export.
   43 
   44 =item { import | export }
   45 
   46 Specify action -- export or import data.
   47 
   48 =item file
   49 
   50 XML file to write to (in the case of export) or read from (in the case of
   51 import).
   52 
   53 =item [table ...]
   54 
   55 If specified, only the listed tables will be imported or exported.
   56 
   57 =back
   58 
   59 =cut
   60 
   61 use strict;
   62 use warnings;
   63 use Getopt::Std;
   64 
   65 BEGIN {
   66 	die "WEBWORK_ROOT not found in environment.\n"
   67 		unless exists $ENV{WEBWORK_ROOT};
   68 }
   69 
   70 use lib "$ENV{WEBWORK_ROOT}/lib";
   71 use WeBWorK::CourseEnvironment;
   72 use WeBWorK::DB;
   73 use WeBWorK::Utils::DBImportExport qw/listTables dbExport dbImport/;
   74 
   75 sub usage {
   76 	print STDERR "usage: $0 [-f] course { import | export } file [table ...]\n";
   77 	print STDERR "tables: ", join(" ", listTables()), "\n";
   78 	exit 1;
   79 }
   80 
   81 our $opt_f;
   82 getopts("f");
   83 
   84 my ($course, $command, $file, @tables) = @ARGV;
   85 
   86 usage() unless $course and $command and $file;
   87 
   88 my $ce = WeBWorK::CourseEnvironment->new($ENV{WEBWORK_ROOT}, "", "", $course);
   89 my $db = WeBWorK::DB->new($ce->{dbLayout});
   90 
   91 my @errors;
   92 
   93 if ($command eq "export") {
   94 	open my $fh, ">", $file or die "failed to open file '$file' for writing: $!\n";
   95 	@errors = dbExport(
   96 		db => $db,
   97 		xml => $fh,
   98 		tables => \@tables,
   99 	);
  100 	close $fh;
  101 } elsif ($command eq "import") {
  102 	my $conflict = ($opt_f ? "replace" : "skip");
  103 	open my $fh, "<", $file or die "failed to open file '$file' for writing: $!\n";
  104 	@errors = dbImport(
  105 		db => $db,
  106 		xml => $fh,
  107 		tables => \@tables,
  108 		conflict => $conflict,
  109 	);
  110 	close $fh;
  111 } else {
  112 	die "$command: unrecognized command.\n";
  113 }
  114 
  115 if (@errors) {
  116 	warn "The following errors occured:\n", map { "* $_\n" } @errors;
  117 	exit 1;
  118 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9