-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load OPL set definitions from files instead of searching the OPL dire…
…ctory. This is done in the getDefList method of lib/WeBWorK/ContentGenerator/Instructor.pm. The only time that method is called is when the homework sets editor is loaded. Note that the course's templates directory is still searched, but the Library and Contrib subdirectories are pruned and so not look into. A new script `bin/generate-OPL-set-def-lists.pl` is created that generates the needed data files by searching the OPL directory. Note that this script is executed by `bin/OPL-update`. For now, this scrit is executed in docker-entrypoint.sh when the docker container is started. However, these files should be added to the OPL release built by webwork2/bin/OPL_releases/release.sh, and dealt with in the same way as the other files in webwork2/htdocs/DATA. Of course, that whole process needs to be updated and removed from the personal fork it is currently in. The release there is now more than two years old. The defaults.config option $option{useOPLdefFiles} still is checked to determine if OPL set defintion files will be loaded and listed, but note that the $options{setDefSearchDepth} is ignored for this. The new defaults.config option $option{useContribDefFiles} determines if set definition files from the Contrib directory will be loaded and listed. This also ignores depth. So the search depth option only applies to local directories for the course.
- Loading branch information
Showing
5 changed files
with
180 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env perl | ||
|
||
=head1 NAME | ||
generate-OPL-set-def-list - find all set definition files in the OPL and Contrib | ||
=head1 SYNOPSIS | ||
generate-OPL-set-def-list | ||
The environment variable $WEBWORK_ROOT must be set with the location of | ||
webwork2, and either the environment variable $PG_ROOT must be set with the | ||
location of pg, or pg must be located in the parent directory of the webwork2 | ||
location. | ||
=head1 DESCRIPTION | ||
This script will find all set definition files in the OpenProblemLibrary and | ||
Contrib subdirectories of the webwork-open-problem-library and list them in the | ||
files $WEBWORK_ROOT/htdocs/DATA/library-set-defs.json and | ||
$WEBWORK_ROOT/htdocs/DATA/contrib-set-defs.json. | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Pod::Usage; | ||
use File::Find; | ||
|
||
my $pg_root; | ||
|
||
BEGIN { | ||
pod2usage(2) unless exists $ENV{WEBWORK_ROOT}; | ||
$pg_root = $ENV{PG_ROOT} // "$ENV{WEBWORK_ROOT}/../pg"; | ||
pod2usage(2) unless (-e $pg_root); | ||
} | ||
|
||
use lib "$ENV{WEBWORK_ROOT}/lib"; | ||
use lib "$pg_root/lib"; | ||
use lib "$ENV{WEBWORK_ROOT}/bin"; | ||
|
||
use OPLUtils qw/writeJSONtoFile/; | ||
use WeBWorK::CourseEnvironment; | ||
|
||
my $ce = new WeBWorK::CourseEnvironment({ webwork_dir => $ENV{WEBWORK_ROOT} }); | ||
my $libraryRoot = $ce->{problemLibrary}{root}; | ||
my $contribRoot = $ce->{contribLibrary}{root}; | ||
|
||
print "Using WeBWorK root: $ENV{WEBWORK_ROOT}\n"; | ||
print "Using PG root: $pg_root\n"; | ||
print "Using library root: $libraryRoot\n"; | ||
print "Using contrib root: $contribRoot\n"; | ||
|
||
# Search the OPL directory for set definition files. | ||
my @opl_set_defs; | ||
find( | ||
{ | ||
wanted => sub { | ||
push @opl_set_defs, $_ =~ s|^$libraryRoot/?|Library/|r if m|/set[^/]*\.def$|; | ||
}, | ||
follow_fast => 1, | ||
no_chdir => 1 | ||
}, | ||
$libraryRoot | ||
); | ||
|
||
# Search the Contrib directory for set definition files. | ||
my @contrib_set_defs; | ||
find( | ||
{ | ||
wanted => sub { | ||
push @contrib_set_defs, $_ =~ s|^$contribRoot/?|Contrib/|r if m|/set[^/]*\.def$|; | ||
}, | ||
follow_fast => 1, | ||
no_chdir => 1 | ||
}, | ||
$contribRoot | ||
); | ||
|
||
sub depth_then_iname_sort { | ||
my $file_list = shift; | ||
my @file_depths; | ||
my @uc_file_names; | ||
for (@$file_list) { | ||
push @file_depths, scalar(@{ [ $_ =~ /\//g ] }); | ||
push @uc_file_names, uc($_); | ||
} | ||
@$file_list = | ||
@$file_list[ sort { $file_depths[$a] <=> $file_depths[$b] || $uc_file_names[$a] cmp $uc_file_names[$b] } | ||
0 .. $#$file_list ]; | ||
} | ||
|
||
# Sort the files first by depth then by path. | ||
depth_then_iname_sort(\@opl_set_defs); | ||
depth_then_iname_sort(\@contrib_set_defs); | ||
|
||
# Write the lists to the files in htdocs/DATA. | ||
if ($ce->{options}{useOPLdefFiles}) { | ||
writeJSONtoFile(\@opl_set_defs, "$ce->{webworkDirs}{htdocs}/DATA/library-set-defs.json"); | ||
print "Saved OPL set definition list to $ce->{webworkDirs}{htdocs}/DATA/library-set-defs.json.\n"; | ||
} | ||
|
||
if ($ce->{options}{useContribDefFiles}) { | ||
writeJSONtoFile(\@contrib_set_defs, "$ce->{webworkDirs}{htdocs}/DATA/contrib-set-defs.json"); | ||
print "Saved Contrib set definition list to $ce->{webworkDirs}{htdocs}/DATA/contrib-set-defs.json.\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters