Parent Directory
|
Revision Log
Revision 10 - (view) (download) (as text)
| 1 : | sam | 10 | #!/usr/local/bin/perl |
| 2 : | sam | 2 | |
| 3 : | #################################################################### | ||
| 4 : | # Copyright @ 1995-1999 University of Rochester | ||
| 5 : | # All Rights Reserved | ||
| 6 : | #################################################################### | ||
| 7 : | |||
| 8 : | gage | 8 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 9 : | sam | 2 | |
| 10 : | # Called as | ||
| 11 : | # showDatabase.pl courseID | ||
| 12 : | |||
| 13 : | use Global; | ||
| 14 : | use Auth; | ||
| 15 : | use strict; | ||
| 16 : | use GDBM_File; | ||
| 17 : | |||
| 18 : | if (@ARGV != 2) | ||
| 19 : | { | ||
| 20 : | print "\nSyntax is import_webwork-database.pl courseID textDatabaseFile\n"; | ||
| 21 : | print " (e.g. import_webwork-database.pl demoCourse textDataBase)\n\n"; | ||
| 22 : | exit(0); | ||
| 23 : | } | ||
| 24 : | |||
| 25 : | my $course = $ARGV[0]; | ||
| 26 : | my $textDatabaseFile = $ARGV[1]; | ||
| 27 : | |||
| 28 : | # establish environment for this script | ||
| 29 : | |||
| 30 : | &Global::getCourseEnvironment($course); | ||
| 31 : | |||
| 32 : | # Directory paths | ||
| 33 : | |||
| 34 : | my $databaseDirectory = getCourseDatabaseDirectory(); | ||
| 35 : | my $courseScriptsDirectory = getWebworkScriptDirectory(); | ||
| 36 : | |||
| 37 : | # File names | ||
| 38 : | |||
| 39 : | require "${courseScriptsDirectory}$Global::DBglue_pl"; | ||
| 40 : | require "${courseScriptsDirectory}$Global::HTMLglue_pl"; | ||
| 41 : | require "${courseScriptsDirectory}$Global::FILE_pl"; | ||
| 42 : | |||
| 43 : | my $databaseFile = $Global::database; | ||
| 44 : | |||
| 45 : | # get all psvn's for set | ||
| 46 : | |||
| 47 : | my ($line,$item); | ||
| 48 : | my @probSetRecord = (); | ||
| 49 : | my $probSetString = ''; | ||
| 50 : | my @PROBSETarray = (); | ||
| 51 : | |||
| 52 : | open (INFILE, "$textDatabaseFile") or wwerror("$0","can't open $textDatabaseFile for reading"); | ||
| 53 : | |||
| 54 : | while (defined ($line = <INFILE>)) { | ||
| 55 : | chomp($line); | ||
| 56 : | unless ($line =~ /\S/) {next;} ## skip blank lines | ||
| 57 : | if ($line =~ /^[^\[]\s*(.*)/) { ## non bracketed line | ||
| 58 : | push @probSetRecord, $1;} | ||
| 59 : | |||
| 60 : | else { ## bracketed line | ||
| 61 : | $probSetString = join ("\&", @probSetRecord); | ||
| 62 : | push @PROBSETarray, $probSetString; | ||
| 63 : | $line =~ /^\[(.*)\]$/; | ||
| 64 : | push @PROBSETarray, $1; | ||
| 65 : | @probSetRecord =(); | ||
| 66 : | } | ||
| 67 : | } | ||
| 68 : | |||
| 69 : | close (INFILE); | ||
| 70 : | |||
| 71 : | $probSetString = join ("\&", @probSetRecord); ## last record | ||
| 72 : | push @PROBSETarray, $probSetString; ## add last record | ||
| 73 : | shift @PROBSETarray; ## remove first item which is an empty probSetString | ||
| 74 : | |||
| 75 : | my $mode = &GDBM_WRCREAT(); | ||
| 76 : | my $permission = $Global::standard_tie_permission; | ||
| 77 : | my $db; | ||
| 78 : | my %hash; | ||
| 79 : | |||
| 80 : | $db = tie(%hash, "GDBM_File", "${databaseDirectory}${databaseFile}", $mode, $permission); | ||
| 81 : | %hash = @PROBSETarray; | ||
| 82 : | $db->reorganize(); | ||
| 83 : | untie($db); | ||
| 84 : | chmod($permission,"${databaseDirectory}${databaseFile}") or | ||
| 85 : | warn("compress_GDBM_webwork-database.pl: error", " Can't do chmod($permission, ${databaseDirectory}${databaseFile})"); | ||
| 86 : | |||
| 87 : |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |