Skip to content

Commit 155964d

Browse files
committed
add ww-update script to call OPL-update and build-search-json.pl
1 parent 05edad0 commit 155964d

5 files changed

Lines changed: 76 additions & 14 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ htdocs/themes/*
3636
DATA/*
3737
!DATA/uploads
3838
DATA/uploads/*
39-
!htdocs/DATA/search.json
4039
!*README*
4140

4241
docker-compose.yml
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,24 @@ =head1 DESCRIPTION
4949
# These are the default sample problem directory and JSON file.
5050
my $sample_prob_dir = "tutorial/sample-problems";
5151
my $json_file = "htdocs/DATA/search.json";
52-
my $verbose = 0;
52+
my ($verbose, $show_warnings) = (1,0);
5353

5454
GetOptions(
5555
'p|pg-root=s' => \$pg_root,
5656
'f|json-file=s' => \$json_file,
5757
's|sample-prob-dir=s' => \$sample_prob_dir,
5858
'b|build=s' => \$build,
59+
'w|show-warnings' => \$show_warnings,
5960
'v|verbose+' => \$verbose
6061
);
6162

6263
die "The build options must be one of (all, macros, samples). The value $build is not valid."
6364
if ((grep { $_ eq $build } qw/all macros samples/) != 1);
6465

6566
my $ww_root = $ENV{WW_ROOT};
66-
$ww_root = Mojo::File->new(curfile->dirname, "..", "..")->realpath unless defined($ww_root);
67+
$ww_root = Mojo::File->curfile->dirname->dirname->realpath unless defined($ww_root);
68+
69+
say $ww_root;
6770

6871
die "ww_root: $ww_root is not a directory" unless -d $ww_root;
6972

@@ -73,6 +76,7 @@ =head1 DESCRIPTION
7376
my $json_dir = $json_file->dirname;
7477
$json_dir->make_path unless -d $json_dir;
7578

79+
7680
if ($verbose) {
7781
say "Running script build-search-data with the following options:";
7882
say " pg-root: $pg_root";
@@ -99,7 +103,7 @@ =head1 DESCRIPTION
99103
my @files;
100104
my $index = 1; # set an index for each file.
101105

102-
sub processFile {
106+
sub processPGfile {
103107
return unless $_ =~ /\.pg$/;
104108
say "Processing $_" if $verbose;
105109
my $filename = $_;
@@ -192,11 +196,11 @@ sub extractPODNode {
192196
my ($filename, $root, $title) = @_;
193197
my @index = grep { ref($root->[$_]) eq 'ARRAY' && $root->[$_][2] =~ /$title/ } 0 .. scalar(@$root) - 1;
194198
if (@index == 0) {
195-
warn "In $filename: The section named $title is not found in the POD.";
199+
warn "In $filename: The section named $title is not found in the POD." if $show_warnings;
196200
return;
197201
}
198202
if (@index > 1) {
199-
warn "In $filename: There are more than one section named $title in the POD.";
203+
warn "In $filename: There are more than one section named $title in the POD." if $show_warnings;
200204
return;
201205
}
202206
# start at index 2 and extract all text
@@ -225,9 +229,12 @@ sub parseHead2 {
225229
# process a macro file's POD
226230
sub processMacro {
227231
return unless $_ =~ /\.pl$/;
228-
say "Processing $_" if $verbose;
229232
my $file = Mojo::File->new($File::Find::name);
230-
return if $file->dirname =~ /deprecated/;
233+
if ($file->dirname =~ /deprecated/){
234+
say "Skipping $_. This is deprecated." if $verbose;
235+
return;
236+
}
237+
say "Processing $_" if $verbose;
231238

232239
my $parser = Pod::Simple::SimpleTree->new();
233240
my $root = $parser->parse_file("$file")->root;
@@ -245,7 +252,7 @@ sub processMacro {
245252
}
246253

247254
# Process the sample problems in $sample_prob_dir.
248-
find({ wanted => \&processFile }, "$sample_prob_dir") if (grep { $build eq $_ } qw/all samples/);
255+
find({ wanted => \&processPGfile }, "$sample_prob_dir") if (grep { $build eq $_ } qw/all samples/);
249256

250257
# Process the POD within the macros dir.
251258
find({ wanted => \&processMacro }, "$pg_root/macros") if (grep { $build eq $_ } qw/all macros/);

bin/download-OPL-metadata-release.pl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ BEGIN
8080
die "The directory $libraryDirectory does not exist or is not writable."
8181
if (!-d $libraryDirectory || !-w $libraryDirectory);
8282

83+
warn $ENV{OPL_GIT_REPOSITORY};
84+
85+
my $git_repo = $ENV{OPL_GIT_REPOSITORY} // 'origin';
86+
8387
# Checkout the release tag in the library clone if it hasn't already been done.
84-
`$ce->{externalPrograms}{git} -C $libraryDirectory fetch --tags origin`;
88+
`$ce->{externalPrograms}{git} -C $libraryDirectory fetch --tags $git_repo`;
8589
`$ce->{externalPrograms}{git} -C $libraryDirectory show-ref refs/heads/$releaseTag -q`;
8690
if ($?) {
8791
say "Switching OPL clone in $libraryDirectory to new branch of release tag $releaseTag.";

bin/update-ww.pl

100644100755
Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,67 @@ =head1 NAME
44
55
update-ww.pl -- run all needed scripts when webwork is updated.
66
7+
=head1 SYNOPSIS
8+
9+
update-ww.pl [options]
10+
11+
Options:
12+
-a|--all Run both OPL-update and build-search-json.pl
13+
14+
-b|--build-sample-probs Run the build-search-json.pl script with the 'all' flag.
15+
The other options are 'samples' and 'macros' if not all
16+
are desired.
17+
-o|--opl-update Run the OPL-update script. By default the upload-opl-statistics
18+
part of the script is not run. See the upload-opl-stats flags
19+
to change this.
20+
-s|--sample-probs Run the sample-probs part of the script.
21+
22+
-v|--verbose Setting this flag provides details as the script runs.
23+
724
=cut
825

926
use strict;
1027
use warnings;
1128
use feature 'say';
1229

13-
use Mojo::File qw(curfile);
30+
use Mojo::File;
31+
use Getopt::Long qw(:config bundling);
32+
33+
# BEGIN {
34+
# use Env qw(WEBWORK_ROOT);
35+
# }
36+
37+
my $ww_root = Mojo::File->curfile->dirname->dirname->realpath;
38+
39+
my $build = 'all';
40+
my $git_repo = 'origin';
41+
my $all = 1;
42+
my ($verbose, $opl_update, $sample_probs, $upload_opl_stats) = (0, 0, 0, 0);
43+
44+
GetOptions(
45+
'a|all' => \$all,
46+
'b|build-sample-probs=s' => \$build,
47+
'o|opl-update' => \$opl_update,
48+
'g|git-opl-repository=s' => \$git_repo,
49+
's|sample-probs' => \$sample_probs,
50+
'u|upload-opl-stats' => \$upload_opl_stats,
51+
'v|verbose+' => \$verbose
52+
);
1453

15-
my $ww_root = Mojo::File->new(curfile->dirname, "..")->realpath;
54+
my $v = $verbose ? '-v' : '';
55+
if ($all || $sample_probs) {
56+
say 'Rebuilding the sample problem and macro POD file.';
57+
my $search_output = `perl $ww_root/bin/build-search-json.pl $v -b $build`;
58+
say $search_output if $verbose;
59+
}
1660

17-
`perl $ww_root/bin/dev_scripts/build-search-json.pl -b all`;
61+
if ($all || $opl_update) {
62+
say 'Running the OPL-update script.';
63+
$ENV{SKIP_UPLOAD_OPL_STATISTICS} = 1 unless $upload_opl_stats;
64+
$ENV{OPL_GIT_REPOSITORY} = $git_repo;
65+
say "Running the OPL upate script" if $verbose;
66+
my $opl_output = `perl $ww_root/bin/OPL-update`;
67+
say $opl_output if $verbose;
68+
}
1869

70+
1;

htdocs/DATA/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)