1 | #!/usr/local/bin/perl5 -w
|
---|
2 |
|
---|
3 | # This program will build a particular collection
|
---|
4 |
|
---|
5 | BEGIN {
|
---|
6 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
7 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
8 | unshift (@INC, "$ENV{'GSDLHOME'}/lib");
|
---|
9 | unshift (@INC, "$ENV{'GSDLHOME'}/lib/plugins");
|
---|
10 | }
|
---|
11 |
|
---|
12 | use parsargv;
|
---|
13 | use util;
|
---|
14 |
|
---|
15 | &main();
|
---|
16 |
|
---|
17 | sub print_usage {
|
---|
18 | print STDERR "\n usage: $0 [options] collection-name\n\n";
|
---|
19 | print STDERR " options:\n";
|
---|
20 | print STDERR " -verbosity number 0=none, 3=lots\n";
|
---|
21 | print STDERR " -archivedir directory Where the archives live\n";
|
---|
22 | print STDERR " -cachedir directory Where to cache the archives\n";
|
---|
23 | print STDERR " -builddir directory Where to put the built indexes\n\n";
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | sub main
|
---|
28 | {
|
---|
29 | if (!parsargv::parse(\@ARGV,
|
---|
30 | 'verbosity/\d+/2', \$verbosity,
|
---|
31 | 'archivedir/.*/', \$archivedir,
|
---|
32 | 'cachedir/.*/', \$cachedir,
|
---|
33 | 'builddir/.*/', \$builddir)) {
|
---|
34 | &print_usage();
|
---|
35 | die "\n";
|
---|
36 | }
|
---|
37 |
|
---|
38 | # get and check the collection
|
---|
39 | ($collection) = @ARGV;
|
---|
40 | if (!defined ($collection)) {
|
---|
41 | &print_usage();
|
---|
42 | die "\n";
|
---|
43 | }
|
---|
44 | if (!-e "$ENV{'GSDLHOME'}/collect/$collection") {
|
---|
45 | die "Invalid collection name ($collection).\n";
|
---|
46 | }
|
---|
47 |
|
---|
48 | # fill in the default archives and building directories if none
|
---|
49 | # were supplied, turn all \ into / and remove trailing /
|
---|
50 | $archivedir = "$ENV{'GSDLHOME'}/collect/$collection/archives" if $archivedir eq "";
|
---|
51 | $archivedir =~ s/[\\\/]+/\//g;
|
---|
52 | $archivedir =~ s/\/$//;
|
---|
53 | $builddir = "$ENV{'GSDLHOME'}/collect/$collection/building" if $builddir eq "";
|
---|
54 | $builddir =~ s/[\\\/]+/\//g;
|
---|
55 | $builddir =~ s/\/$//;
|
---|
56 |
|
---|
57 | # update the archive cache if needed
|
---|
58 | if ($cachedir) {
|
---|
59 | print STDERR "Updating archive cache\n" if ($verbosity >= 1);
|
---|
60 |
|
---|
61 | $cachedir =~ s/[\\\/]+$//;
|
---|
62 | $cachedir .= "/collect/$collection" unless
|
---|
63 | $cachedir =~ /collect\/$collection/;
|
---|
64 |
|
---|
65 | $realarchivedir = "$cachedir/archives";
|
---|
66 | $realbuilddir = "$cachedir/building";
|
---|
67 | &util::mk_all_dir ($realarchivedir);
|
---|
68 | &util::mk_all_dir ($realbuilddir);
|
---|
69 | &util::cachedir ($archivedir, $realarchivedir, $verbosity);
|
---|
70 |
|
---|
71 | } else {
|
---|
72 | $realarchivedir = $archivedir;
|
---|
73 | $realbuilddir = $builddir;
|
---|
74 | }
|
---|
75 |
|
---|
76 | # build it in realbuilddir
|
---|
77 | &util::mk_all_dir ($realbuilddir);
|
---|
78 |
|
---|
79 |
|
---|
80 | # if a builder class has been created for this collection, use it
|
---|
81 | # otherwise, use the mg builder
|
---|
82 | if (-e "$ENV{'GSDLHOME'}/collect/$collection/lib/${collection}builder.pm") {
|
---|
83 | $builderdir = "$ENV{'GSDLHOME'}/collect/$collection/lib";
|
---|
84 | $buildertype = "${collection}builder";
|
---|
85 | } else {
|
---|
86 | $builderdir = "$ENV{'GSDLHOME'}/lib";
|
---|
87 | $buildertype = "mgbuilder";
|
---|
88 | }
|
---|
89 |
|
---|
90 | require "$builderdir/$buildertype.pm";
|
---|
91 |
|
---|
92 | eval("\$builder = new $buildertype(\$collection, " .
|
---|
93 | "\$realarchivedir, \$realbuilddir, \$verbosity)");
|
---|
94 | die "$@" if $@;
|
---|
95 |
|
---|
96 | $builder->init();
|
---|
97 | $builder->compress_text();
|
---|
98 | $builder->build_indexes();
|
---|
99 | $builder->make_infodatabase();
|
---|
100 | $builder->make_auxiliary_files();
|
---|
101 | $builder->deinit();
|
---|
102 |
|
---|
103 |
|
---|
104 | if ($realbuilddir ne $builddir) {
|
---|
105 | print STDERR "Copying back the cached build\n" if ($verbosity >= 1);
|
---|
106 | &util::rm_r ($builddir);
|
---|
107 | &util::cp_r ($realbuilddir, $builddir);
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|