[system] / trunk / webwork-modperl / bin / delcourse Repository:
ViewVC logotype

View of /trunk/webwork-modperl/bin/delcourse

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2007 - (download) (annotate)
Wed May 5 22:38:24 2004 UTC (9 years ago) by sh002i
File size: 4354 byte(s)
course deletion script

    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/addcourse,v 1.11 2004/05/05 22:02:50 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 delcourse - delete a course
   21 
   22 =head1 SYNOPSIS
   23 
   24  delcourse [options] COURSEID
   25 
   26 =head1 DESCRIPTION
   27 
   28 Delete a course, including its database and course directory.
   29 
   30 =head1 OPTIONS
   31 
   32 =over
   33 
   34 If the course's database layout is , the following options are valid:
   35 
   36 =over
   37 
   38 =item B<--sql-host>=I<HOST>
   39 
   40 Specifies the hostname of the SQL server on the course database resides. If not
   41 specified, the default for your RDBMS will be used.
   42 
   43 =item B<--sql-port>=I<PORT>
   44 
   45 Specifies the port of the SQL server on the course database resides. If not
   46 specified, the default for your RDBMS will be used.
   47 
   48 =item B<--sql-user>=I<USER>
   49 
   50 Specifies the username to use when connecting to the SQL server to delete the
   51 course database. This user must have CREATE, DELETE, FILE, INSERT, SELECT, and
   52 UPDATE privileges, WITH GRANT OPTION.
   53 
   54 =item B<--sql-pass>=I<PASS>
   55 
   56 Specifies the password to use when connecting to the SQL server.
   57 
   58 =item B<--sql-db>=I<DBNAME>
   59 
   60 Specifies the name of the database to delete. (This is usually
   61 "webwork_COURSENAME", but can be overridden by changing the database layout in
   62 F<global.conf>.)
   63 
   64 =back
   65 
   66 =item I<COURSEID>
   67 
   68 The name of the course to delete.
   69 
   70 =back
   71 
   72 =cut
   73 
   74 BEGIN {
   75 	# hide arguments (there could be passwords there!)
   76 	$0 = "$0";
   77 }
   78 
   79 use strict;
   80 use warnings;
   81 use Getopt::Long;
   82 
   83 BEGIN {
   84 	die "WEBWORK_ROOT not found in environment.\n"
   85 		unless exists $ENV{WEBWORK_ROOT};
   86 }
   87 
   88 use lib "$ENV{WEBWORK_ROOT}/lib";
   89 use WeBWorK::CourseEnvironment;
   90 use WeBWorK::DB;
   91 use WeBWorK::Utils qw(runtime_use readFile cryptPassword);
   92 use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses);
   93 
   94 sub usage {
   95 	print STDERR "usage: $0 [options] COURSEID\n";
   96 	print STDERR "Options:\n";
   97 	print STDERR "  for \"sql\" database layout:\n";
   98 	print STDERR "    [--sql-host=HOST] [--sql-port=port]\n";
   99 	print STDERR "    --sql-user=USER --sql-pass=PASS\n";
  100 	print STDERR "    --sql-db=DBNAME\n";
  101 	exit;
  102 }
  103 
  104 sub usage_error {
  105 	print STDERR "$0: @_\n";
  106 	usage();
  107 }
  108 
  109 my $sql_host = "";
  110 my $sql_port = "";
  111 my $sql_user = "";
  112 my $sql_pass = "";
  113 my $sql_db = "";
  114 
  115 ##### get command-line options #####
  116 
  117 GetOptions(
  118 	"sql-host=s" => \$sql_host,
  119 	"sql-port=s" => \$sql_port,
  120 	"sql-user=s" => \$sql_user,
  121 	"sql-pass=s" => \$sql_pass,
  122 	"sql-db=s" => \$sql_db,
  123 );
  124 my $courseID = shift;
  125 
  126 ##### perform sanity checks #####
  127 
  128 usage_error("must specify COURSEID.") unless $courseID;
  129 
  130 # bring up a minimal course environment
  131 my $ce = WeBWorK::CourseEnvironment->new($ENV{WEBWORK_ROOT}, "FAKE_URL_ROOT",
  132 	"FAKE_PG_ROOT", $courseID);
  133 
  134 my $dbLayout = $ce->{dbLayoutName};
  135 
  136 if ($dbLayout eq "sql") {
  137 	usage_error("must specify --sql-user.")   unless $sql_user;
  138 	usage_error("must specify --sql-pass.")   unless $sql_pass;
  139 	usage_error("must specify --sql-db.")     unless $sql_db;
  140 }
  141 
  142 ##### set up parameters to pass to deleteCourse() #####
  143 
  144 my %dbOptions;
  145 if ($dbLayout eq "sql") {
  146 	$dbOptions{host}     = $sql_host if $sql_host ne "";
  147 	$dbOptions{port}     = $sql_port if $sql_port ne "";
  148 	$dbOptions{username} = $sql_user;
  149 	$dbOptions{password} = $sql_pass;
  150 	$dbOptions{database} = $sql_db;
  151 }
  152 
  153 ##### call deleteCourse(), handle errors #####
  154 
  155 eval {
  156 	deleteCourse(
  157 		courseID      => $courseID,
  158 		ce            => $ce,
  159 		dbOptions     => \%dbOptions,
  160 	);
  161 };
  162 
  163 if ($@) {
  164 	my $error = $@;
  165 	print STDERR "$error\n";
  166 	exit;
  167 }
  168 
  169 =head1 AUTHOR
  170 
  171 Written by Sam Hathaway, hathaway at users.sourceforge.net.
  172 
  173 =cut

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9