Parent Directory
|
Revision Log
initial support for WWDBv2:
- DB.pm finished (except for getGlobalUser{Set,Problem} methods)
- schema modules for password, permission, key, and user with
WWDBv1 hash-bashed backends
- GDBM driver
- wwdb command-line frontend
-sam
1 #!/usr/bin/env perl 2 3 ################################################################################ 4 # WeBWorK mod_perl (c) 1995-2002 WeBWorK Team, Univeristy of Rochester 5 # $Id: wwdb,v 1.1 2003-03-21 23:30:09 sh002i Exp $ 6 ################################################################################ 7 8 =head1 NAME 9 10 wwdb - command-line interface to the WeBWorK databases (WWDBv2). 11 12 =cut 13 14 use strict; 15 use warnings; 16 use WeBWorK::ContentGenerator; # for cook_args 17 use WeBWorK::CourseEnvironment; 18 use WeBWorK::DB; 19 #use WeBWorK::DB::Record::User; 20 21 # Command line syntax 22 # 23 # wwdb course command [ argument ... ] 24 # 25 # Commands correspond to the functions of WeBWorK::DB. Arguments are either 26 # strings or records. To represent records, use the following syntax: 27 # 28 # {id="sh002i" first_name="Sam" last_name="Hathaway"} 29 # 30 # You'll have to protect arguments like this from your shell by enclosing them 31 # in single quotes. 32 33 sub main(@) { 34 my ($course, $command, @arguments) = @_; 35 36 my $ce = WeBWorK::CourseEnvironment->new($ENV{WEBWORK_ROOT}, "", $course); 37 my $db = WeBWorK::DB->new($ce); 38 39 die "$command: unsupported command.\n" 40 unless $db->can($command); 41 42 my ($verb, $noun) = $command =~ m/^(list|new|get|put|delete)(.*?)s?$/; 43 44 my $type = "WeBWorK::DB::Record::"; 45 if ($noun =~ m/^Global(User)?(Set|Problem)$/) { 46 $type .= "$1$2"; 47 } else { 48 $type .= $noun; 49 } 50 51 foreach (@arguments) { 52 if (m/^{(.*)}$/) { 53 $_ = string2record($type, $1); 54 } 55 } 56 57 my @result = $db->$command(@arguments); 58 59 if ($verb eq "list") { 60 print join("\n", @result), "\n"; 61 } elsif ($verb eq "new") { 62 # ignore result 63 } elsif ($verb eq "get") { 64 if (defined $result[0]) { 65 print "{", record2string($result[0]), "}\n"; 66 } else { 67 print "$arguments[0]: record not found\n"; 68 } 69 } elsif ($verb eq "put") { 70 # ignore result 71 } elsif ($verb eq "delete") { 72 # ignore result 73 } 74 } 75 76 sub string2record($$) { 77 my ($type, $string) = @_; 78 my %hash = WeBWorK::ContentGenerator::cook_args($string); 79 my $record = $type->new(%hash); 80 return $record; 81 } 82 83 sub record2string($) { 84 my ($record) = @_; 85 my $string; 86 foreach my $key ($record->FIELDS()) { 87 my $value = $record->$key(); 88 $value = "" unless defined $value; 89 $value =~ s/"/\\"/g; 90 $string .= "$key=\"$value\" "; 91 } 92 chop $string; 93 return $string; 94 } 95 96 main(@ARGV);
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |