source: trunk/gsdl/bin/script/cancel_build.pl@ 1461

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

A few fixes to collectoraction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# cancel_build.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2000 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28
29# This program will create a .kill file within the GSDLCOLLECTDIR/collect-name
30# directory which will cause any import.pl or buildcol.pl processes running
31# on that collection to abort.
32# It then cleans any mess left laying around the collection (including the
33# import directory !!).
34# cancel_build.pl is really only intended to be called from within the
35# library's collectoraction and isn't much use for anything else. As such it
36# should be rewritten in C++ one day and included in the collectoraction
37# itself.
38
39BEGIN {
40 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
41 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
42}
43
44use util;
45use parsargv;
46use File::Copy;
47
48sub print_usage {
49 print STDERR "\n usage: $0 [options] collection-name\n\n";
50 print STDERR " options:\n";
51 print STDERR " -collectdir directory Collection directory (defaults to " .
52 &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n\n";
53}
54
55&main();
56
57sub main {
58 if (!parsargv::parse(\@ARGV, 'collectdir/.*/', \$collectdir)) {
59 &print_usage();
60 die "\n";
61 }
62
63 my $collection = pop @ARGV;
64 if (!defined $collection || $collection !~ /\w/) {
65 print STDERR "no collection specified\n";
66 &print_usage();
67 die "\n";
68 }
69
70 my $cdir = &util::filename_cat ($collectdir, $collection);
71 if ($collectdir eq "") {
72 $collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
73 $cdir = &util::filename_cat ($collectdir, $collection);
74 } elsif (!-d $cdir) {
75 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
76 }
77
78 if (! -d $cdir) {
79 print STDERR "Collection does not exist ($cdir)\n";
80 exit (1);
81 }
82
83 # create .kill file
84 my $killfile = &util::filename_cat ($cdir, ".kill");
85 if (!open (KILLFILE, ">$killfile")) {
86 print STDERR "Couldn't create .kill file ($killfile)\n";
87 exit (1);
88 }
89 print KILLFILE "kill $collection\n";
90 close KILLFILE;
91
92 sleep (2); # just give it a chance to die gracefully;
93
94 # remove archives, building, and import directories
95 &util::rm_r (&util::filename_cat ($cdir, "import"));
96 &util::rm_r (&util::filename_cat ($cdir, "building"));
97 &util::rm_r (&util::filename_cat ($cdir, "archives"));
98
99 # remove any other temporary files that may have been left laying around
100 # by the build
101 my $buildfile = &util::filename_cat ($collectdir, ".build");
102 &util::rm ($buildfile) if -e $buildfile;
103 my $bldfile = &util::filename_cat ($collectdir, "$collection.bld");
104 &util::rm ($bldfile) if -e $bldfile;
105 my $bldfile_d = &util::filename_cat ($collectdir, "$collection.bld.download");
106 &util::rm ($bldfile_d) if -e $bldfile_d;
107 my $bldfile_i = &util::filename_cat ($collectdir, "$collection.bld.import");
108 &util::rm ($bldfile_i) if -e $bldfile_i;
109 my $bldfile_b = &util::filename_cat ($collectdir, "$collection.bld.build");
110 &util::rm ($bldfile_b) if -e $bldfile_b;
111 my $bldfile_f = &util::filename_cat ($collectdir, "$collection.bld.final");
112 &util::rm ($bldfile_f) if -e $bldfile_f;
113
114 # if there's an archives.org directory, rename it back to archives
115 if (-d &util::filename_cat ($cdir, "archives.org")) {
116 &File::Copy::move (&util::filename_cat ($cdir, "archives.org"),
117 &util::filename_cat ($cdir, "archives"));
118 }
119}
Note: See TracBrowser for help on using the repository browser.