[10418] | 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 |
|
---|
| 26 | package scriptutil;
|
---|
[15740] | 27 |
|
---|
| 28 | use strict;
|
---|
[10418] | 29 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 30 | no strict 'refs'; # ...but allow filehandles to be variables and vice versa
|
---|
| 31 |
|
---|
| 32 | use gsprintf 'gsprintf';
|
---|
| 33 |
|
---|
| 34 | # returns $removeold, $keepold
|
---|
| 35 | sub check_removeold_and_keepold {
|
---|
| 36 |
|
---|
[12966] | 37 | my ($removeold, $keepold, $incremental, $dir, $collectcfg) = @_;
|
---|
[10418] | 38 |
|
---|
[12966] | 39 | if (($keepold && $removeold) || ($incremental && $removeold) ) {
|
---|
[10418] | 40 | gsprintf(STDERR, "{scripts.both_old_options}\n", $dir);
|
---|
| 41 | sleep(3); #just in case
|
---|
| 42 | return (1,0);
|
---|
| 43 |
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[12966] | 46 | if (!$keepold && !$removeold && !$incremental) {
|
---|
[10418] | 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;
|
---|
[12966] | 52 | } elsif (defined $collectcfg->{'incremental'} && $collectcfg->{'incremental'} =~ /^true$/i) {
|
---|
| 53 | $incremental = 1;
|
---|
[10418] | 54 | }
|
---|
| 55 | }
|
---|
[12966] | 56 |
|
---|
| 57 | if (!$keepold && !$removeold && !$incremental) {
|
---|
[10418] | 58 | gsprintf(STDERR, "{scripts.no_old_options} \n", $dir);
|
---|
| 59 | sleep(3); #just in case
|
---|
| 60 | return (1,0);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[12966] | 63 | # incremental implies keepold
|
---|
| 64 | if ($incremental) {
|
---|
| 65 | $keepold = 1;
|
---|
| 66 | }
|
---|
| 67 | return ($removeold, $keepold, $incremental);
|
---|
[10418] | 68 |
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | 1;
|
---|