source: gsdl/trunk/perllib/scriptutil.pm@ 19620

Last change on this file since 19620 was 17143, checked in by kjdon, 16 years ago

modified check_removeold_and_keepold so that you don't need to pass in collectcfg

  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 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);
43
44 }
45
46 if (!$keepold && !$removeold && !$incremental && defined $collectcfg) {
47 # we only look at config file options if we dont have these on the command line
48 if (defined $collectcfg->{'removeold'} && $collectcfg->{'removeold'} =~ /^true$/i ) {
49 $removeold = 1;
50 } elsif (defined $collectcfg->{'keepold'} && $collectcfg->{'keepold'} =~ /^true$/i) {
51 $keepold = 1;
52 } elsif (defined $collectcfg->{'incremental'} && $collectcfg->{'incremental'} =~ /^true$/i) {
53 $incremental = 1;
54 }
55 }
56
57 if (!$keepold && !$removeold && !$incremental) {
58 gsprintf(STDERR, "{scripts.no_old_options} \n", $dir);
59 sleep(3); #just in case
60 return (1,0);
61 }
62
63 # incremental implies keepold
64 if ($incremental) {
65 $keepold = 1;
66 }
67 return ($removeold, $keepold, $incremental);
68
69}
70
711;
Note: See TracBrowser for help on using the repository browser.