source: trunk/gsdl/bin/script/build@ 1227

Last change on this file since 1227 was 1198, checked in by sjboddie, 24 years ago

altered the build and build.bat scripts as the old build.bat didn't
seem to work on windows 98 -- build.bat now uses runperl.bat - this gives
the added advantage that the perl code only exists in build, there's
no duplication in build.bat

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1#!/usr/bin/perl
2
3# This perl script may be called directly or by running build.bat on
4# windows (build.bat is in bin\windows)
5
6BEGIN {
7
8 die "GSDLHOME not set - did you remember to source setup.bash (unix) or " .
9 "run setup.bat (windows)?\n" unless defined $ENV{'GSDLHOME'};
10 die "GSDLOS not set - did you remember to source setup.bash (unix) or " .
11 "run setup.bat (windows)?\n" unless defined $ENV{'GSDLOS'};
12 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
13}
14
15use parsargv;
16use util;
17
18
19if (!parsargv::parse(\@ARGV,
20 'buildtype/^(build|import)$/import', \$buildtype,
21 'maxdocs/^\-?\d+/-1', \$maxdocs)) {
22 &print_usage();
23 die "\n";
24}
25
26my ($collection) = @ARGV;
27
28if (!defined $collection || $collection !~ /\w/) {
29 print STDERR "You must specify a collection to build\n";
30 &print_usage();
31 die "\n";
32}
33
34if ($maxdocs == -1) {
35 $maxdocs = "";
36} else {
37 $maxdocs = "-maxdocs $maxdocs";
38}
39
40
41my $collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
42my $importdir = &util::filename_cat ($collectdir, "import");
43my $archivedir = &util::filename_cat ($collectdir, "archives");
44my $buildingdir = &util::filename_cat ($collectdir, "building");
45my $indexdir = &util::filename_cat ($collectdir, "index");
46my $bindir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin");
47
48&main();
49
50sub print_usage {
51 print STDERR "\n usage: $0 [options] collection-name\n\n";
52 print STDERR " options:\n";
53 print STDERR " -buildtype build|import If 'build' attempt to build directly\n";
54 print STDERR " from archives directory (bypassing import\n";
55 print STDERR " stage). Defaults to 'import'\n";
56 print STDERR " -maxdocs number Maximum number of documents to build\n\n";
57}
58
59sub main {
60
61 if (-e &util::filename_cat ($archivedir, "archives.inf")) {
62 if (&has_content ($importdir)) {
63 if ($buildtype eq "build") {
64 &gsdl_build();
65 } else {
66 &gsdl_import();
67 &gsdl_build();
68 }
69 } else {
70 # there are archives but no import, build directly from archives
71 print STDERR "build: no import material was found, building directly\n";
72 print STDERR " from archives\n";
73 &gsdl_build();
74 }
75 } else {
76 if (&has_content ($importdir)) {
77 if ($buildtype eq "build") {
78 print STDERR "build: can't build directly from archives as no\n";
79 print STDERR " imported archives exist (did you forget to\n";
80 print STDERR " move the contents of $collection/import to\n";
81 print STDERR " collection/archives?)\n";
82 }
83 &gsdl_import();
84 &gsdl_build();
85 } else {
86 # no import or archives
87 print STDERR "build: ERROR: The $collection collection has no import\n";
88 print STDERR " or archives data. Try downloading an unbuilt version\n";
89 print STDERR " of the collection from www.nzdl.org\n";
90 die "\n";
91 }
92 }
93}
94
95sub gsdl_import {
96
97 print STDERR "importing the $collection collection\n\n";
98
99 my $import = &util::filename_cat ($bindir, "script", "import.pl");
100 system ("perl $import -removeold $maxdocs $collection");
101 if (-e &util::filename_cat ($archivedir, "archives.inf")) {
102 print STDERR "$collection collection imported successfully\n\n";
103 } else {
104 die "\nimport.pl failed\n";
105 }
106}
107
108sub gsdl_build {
109
110 print STDERR "building the $collection collection\n\n";
111
112 my $buildcol = &util::filename_cat ($bindir, "script", "buildcol.pl");
113 system ("perl $buildcol $maxdocs $collection");
114 if (-e &util::filename_cat ($buildingdir, "text", "$collection.ldb") ||
115 -e &util::filename_cat ($buildingdir, "text", "$collection.bdb")) {
116 print STDERR "$collection collection built successfully\n\n";
117 } else {
118 die "\nbuildcol.pl failed\n";
119 }
120
121 # replace old indexes with new ones
122 if (&has_content ($indexdir)) {
123 print STDERR "removing old indexes\n";
124 &util::rm_r ($indexdir);
125 rename ($buildingdir, $indexdir);
126 }
127}
128
129sub has_content {
130 my ($dir) = @_;
131
132 if (!-d $dir) {return 0;}
133
134 opendir (DIR, $dir) || return 0;
135 my @files = readdir DIR;
136 close DIR;
137
138 foreach my $file (@files) {
139 if ($file !~ /^\.{1,2}$/) {
140 return 1;
141 }
142 }
143 return 0;
144}
Note: See TracBrowser for help on using the repository browser.