source: main/trunk/greenstone2/perllib/scriptutil.pm@ 24193

Last change on this file since 24193 was 20646, checked in by kjdon, 15 years ago

if keepold is true, set incremental_mode to onlyadd

  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1###########################################################################
2#
3# scriptutil.pm -- various useful utilities for the scripts
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package scriptutil;
27
28use strict;
29no strict 'subs'; # allow barewords (eg STDERR) as function arguments
30no strict 'refs'; # ...but allow filehandles to be variables and vice versa
31
32use gsprintf 'gsprintf';
33
34# returns $removeold, $keepold
35sub check_removeold_and_keepold {
36
37 my ($removeold, $keepold, $incremental, $dir, $collectcfg) = @_;
38
39 if (($keepold && $removeold) || ($incremental && $removeold) ) {
40 gsprintf(STDERR, "{scripts.both_old_options}\n", $dir);
41 sleep(3); #just in case
42 return (1,0,0,"none");
43
44 }
45
46 # Incremental mode may be set to "none", "onlyadd" or "all"
47 # depending on status of -keepold and -incremental flags
48 my $incremental_mode = "none";
49 if ($incremental) {
50 $incremental_mode = "all";
51 } elsif ($keepold) {
52 $incremental_mode = "onlyadd";
53 }
54
55 if (!$keepold && !$removeold && !$incremental && defined $collectcfg) {
56 # we only look at config file options if we dont have these on the command line
57 if (defined $collectcfg->{'removeold'} && $collectcfg->{'removeold'} =~ /^true$/i ) {
58 $removeold = 1;
59 } elsif (defined $collectcfg->{'keepold'} && $collectcfg->{'keepold'} =~ /^true$/i) {
60 $keepold = 1;
61 $incremental_mode = "onlyadd";
62 } elsif (defined $collectcfg->{'incremental'} && $collectcfg->{'incremental'} =~ /^true$/i) {
63 $incremental = 1;
64 $incremental_mode = "all";
65 }
66 }
67
68 if (!$keepold && !$removeold && !$incremental) {
69 gsprintf(STDERR, "{scripts.no_old_options} \n", $dir);
70 sleep(3); #just in case
71 return (1,0,0,"none");
72 }
73
74 # incremental implies keepold
75 if ($incremental) {
76 $keepold = 1;
77 }
78 return ($removeold, $keepold, $incremental, $incremental_mode);
79
80}
81
821;
Note: See TracBrowser for help on using the repository browser.