@@ -9,23 +9,18 @@ =head1 SYNOPSIS
99build-search-db.pl [options]
1010
1111 Options:
12- -p|--pg-root Directory containing a git clone of pg.
13- If this option is not set, then the environment
14- variable $PG_ROOT will be used if it is set.
1512 -f|--json-file Location (relative to WW_ROOT) to store the resulting JSON file.
1613 Default value is htdocs/DATA/search.json
17- -s|--sample-prob-dir Location (relative to $PG_ROOT ) where the sample problems are located.
14+ -s|--sample-prob-dir Location (relative to $pg_root ) where the sample problems are located.
1815 Default value is tutorial/samples-problems
1916 -b|--build One of (all, macros, samples) to determine if the macros, sample
2017 problems or both should be scraped for data.
2118 -v|--verbose Setting this flag provides details as the script runs.
22-
23- Note that --pg-root must be provided or the PG_ROOT environment variable set
24- if the POD for pg is desired.
19+ -h|--help Show this help message.
2520
2621=head1 DESCRIPTION
2722
28- This script parses all of the files in $PG_ROOT /tutorial/samples-problems and the POD in the macro files.
23+ This script parses all of the files in $pg_root /tutorial/samples-problems and the POD in the macro files.
2924The result is a JSON file containing information about every file to be searched for in the sample-problems
3025space. The purpose of creating this file is to be used on the Sample Problems page (linked from
3126the PG Editor) to search through macros and samples problems.
@@ -42,34 +37,37 @@ =head1 DESCRIPTION
4237use Mojo::JSON qw( encode_json) ;
4338use Mojo::File qw( curfile) ;
4439use Pod::Simple::SimpleTree;
40+ use Pod::Usage;
41+ use YAML::XS qw( LoadFile) ;
42+
43+ my $ww_root = Mojo::File-> curfile-> dirname-> dirname;
44+
45+ # Load the configuration file to obtain the PG root directory.
46+ my $config_file = " $ww_root /conf/webwork2.mojolicious.yml" ;
47+ $config_file = " $ww_root /conf/webwork2.mojolicious.dist.yml" unless -e $config_file ;
48+ my $config = LoadFile($config_file );
4549
50+ my $pg_root = $config -> {pg_dir };
4651my $build = " all" ;
47- my $pg_root = $ENV {PG_ROOT };
4852
4953# These are the default sample problem directory and JSON file.
5054my $sample_prob_dir = " tutorial/sample-problems" ;
5155my $json_file = " htdocs/DATA/search.json" ;
52- my ($verbose , $show_warnings ) = (1 , 0);
56+ my ($verbose , $show_warnings , $show_help ) = (0, 0 , 0);
5357
5458GetOptions(
55- ' p|pg-root=s' => \$pg_root ,
5659 ' f|json-file=s' => \$json_file ,
5760 ' s|sample-prob-dir=s' => \$sample_prob_dir ,
5861 ' b|build=s' => \$build ,
5962 ' w|show-warnings' => \$show_warnings ,
60- ' v|verbose+' => \$verbose
63+ ' v|verbose+' => \$verbose ,
64+ ' h|help' => \$show_help
6165);
66+ pod2usage(2) if $show_help ;
6267
6368die " The build options must be one of (all, macros, samples). The value $build is not valid."
6469 if ((grep { $_ eq $build } qw/ all macros samples/ ) != 1);
6570
66- my $ww_root = $ENV {WW_ROOT };
67- $ww_root = Mojo::File-> curfile-> dirname-> dirname-> realpath unless defined ($ww_root );
68-
69- say $ww_root ;
70-
71- die " ww_root: $ww_root is not a directory" unless -d $ww_root ;
72-
7371$sample_prob_dir = " $pg_root /$sample_prob_dir " ;
7472$json_file = Mojo::File-> new(" $ww_root /$json_file " );
7573
0 commit comments