1 # Copyright 2008 LibLime
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
28 # These variables get set from command line options
30 GetOptions( 'file=s', \$fname )
36 rewrite-test-config.PL - helper for the Koha packager and installer
40 perl rewrite-test-config.PL configurationfile
44 This helper script replaces keywords in the
45 configuration file with value either supplied through
48 I intend to make this part of hte normal make process eventually.
52 The following configuration keywords are available:
58 my $configfile = 'test-config.txt';
59 my $configuration = read_config_file( $configfile );
61 # Override configuration from the environment
62 foreach my $key (keys %$configuration) {
63 if (defined($ENV{$key})) {
64 $configuration->{$key} = $ENV{$key};
68 $configuration = add_underscores( $configuration );
69 my %configuration = replace_test_params( $configuration );
71 my $file = read_file($fname);
72 $file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg;
74 # At this point, file is in 'blib' and by default
75 # has mode a-w. Therefore, must change permission
76 # to make it writable. Note that stat and chmod
77 # (the Perl functions) should work on Win32
79 $old_perm = (stat $fname)[2] & 07777;
80 my $new_perm = $old_perm | 0200;
81 chmod $new_perm, $fname;
83 open(OUTPUT,">$fname") || die "Can't open $fname for write: $!";
87 chmod $old_perm, $fname;
89 =head2 read_config_file
91 takes the filename pointing to the configuration file that the
92 top-level Makefile wrote
94 returns a hashref that contains the configuration determined by
99 sub read_config_file {
100 my $config_file = shift;
101 if ( not -e $config_file ) {
102 die "unable to find configuration file: $config_file";
105 if ( open( my $confighandle, '<', $config_file ) ) {
106 while ( my $line = <$confighandle> ) {
108 next if ( $line eq '' );
109 next if ( $line =~ /^\s*#/ );
110 my ( $var, $value ) = split( /\s*=\s*/, $line );
111 $config->{ $var } = $value;
114 warn "unable to open configuration file: $config_file";
120 =head2 add_underscores
124 sub add_underscores {
128 foreach my $key ( keys %$config ) {
129 $newconfig->{ '__' . $key . '__' } = $config->{ $key };
135 =head2 replace_test_params
139 sub replace_test_params {
143 foreach my $key ( keys %$config ) {
144 if ( $key =~ /^__TEST_/ ) {
146 $newkey =~ s/^__TEST_/__/;
147 $testconfig->{ $newkey } = $config->{ $key };
150 # override variables with the "TEST_" variety.
151 my %newconfig = ( %$config, %$testconfig );
155 # Idea taken from perlfaq5
158 open(INPUT,$_[0]) || die "Can't open $_[0] for read";
168 Makefile.PL, ExtUtils::MakeMaker(3)
170 =head1 ACKNOWLEDGEMENTS
172 based on rewrite-config.PL by MJ Ray.
176 Andrew Moore <andrew.moore@liblime.com>