[2] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[74] | 3 | # Base subroutines for the Project-Builder project
|
---|
[2] | 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 |
|
---|
[18] | 8 | use strict;
|
---|
[5] | 9 | use lib qw (lib);
|
---|
[2] | 10 | use File::Basename;
|
---|
[9] | 11 | use File::Path;
|
---|
[2] | 12 | use File::Temp qw /tempdir/;
|
---|
[74] | 13 | use AppConfig qw(ARGCOUNT_HASH);
|
---|
[8] | 14 | use Data::Dumper;
|
---|
[2] | 15 |
|
---|
[49] | 16 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
[5] | 17 |
|
---|
[74] | 18 | sub pb_env_init {
|
---|
[2] | 19 |
|
---|
[5] | 20 | my $proj=shift;
|
---|
| 21 | my $ver;
|
---|
| 22 | my $tag;
|
---|
[2] | 23 |
|
---|
[8] | 24 | #
|
---|
[5] | 25 | # Check project name
|
---|
[49] | 26 | # Could be with env var PBPROJ
|
---|
| 27 | # or option -p
|
---|
| 28 | # if not define take the first in conf file
|
---|
[8] | 29 | #
|
---|
[5] | 30 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 31 | (not (defined $proj))) {
|
---|
| 32 | $proj = $ENV{'PBPROJ'};
|
---|
| 33 | }
|
---|
[69] | 34 |
|
---|
[49] | 35 | #
|
---|
[69] | 36 | # We get the pbrc file for that project
|
---|
| 37 | # and use its content
|
---|
| 38 | #
|
---|
[74] | 39 | my $pbrc = pb_conf_read("$ENV{'PBETC'}","pbrc");
|
---|
| 40 | print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
|
---|
[69] | 41 |
|
---|
[70] | 42 | %pbrc = %$pbrc;
|
---|
[69] | 43 | if (not defined $proj) {
|
---|
| 44 | # Take the first as the default project
|
---|
| 45 | $proj = (keys %pbrc)[0];
|
---|
| 46 | print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
|
---|
| 47 | }
|
---|
| 48 | die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
|
---|
| 49 |
|
---|
| 50 | #
|
---|
| 51 | # Set delivery directory
|
---|
| 52 | #
|
---|
[71] | 53 | my $topdir=dirname($pbrc{$proj});
|
---|
[69] | 54 | chdir $topdir || die "Unable to change directory to $topdir";
|
---|
| 55 | $ENV{'PBDESTDIR'}=$topdir."/delivery";
|
---|
| 56 |
|
---|
| 57 | #
|
---|
[67] | 58 | # Use project configuration file if needed
|
---|
[49] | 59 | #
|
---|
[67] | 60 | if (not defined $ENV{'PBROOT'}) {
|
---|
[69] | 61 | if (-f $pbrc{$proj}) {
|
---|
[74] | 62 | my $pbroot = pb_conf_read($pbrc{$proj},"pbroot");
|
---|
[71] | 63 | my %pbroot = %$pbroot;
|
---|
[77] | 64 | # All lines should point to the same pbroot so take the first
|
---|
[69] | 65 | $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
|
---|
| 66 | print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
|
---|
[67] | 67 | }
|
---|
[69] | 68 | die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
|
---|
[49] | 69 | }
|
---|
[2] | 70 |
|
---|
[8] | 71 | #
|
---|
[49] | 72 | # Check pb conf compliance
|
---|
[8] | 73 | #
|
---|
[49] | 74 | $ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
|
---|
| 75 | die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
|
---|
[2] | 76 |
|
---|
[74] | 77 | my %version = ();
|
---|
| 78 |
|
---|
[49] | 79 | if (-f "$ENV{'PBCONF'}/$proj.pb") {
|
---|
[74] | 80 | # List of pkg to build by default (mandatory)
|
---|
| 81 | # List of additional pkg to build when all is called (optional)
|
---|
| 82 | # Valid version names (optional)
|
---|
| 83 | # List of files to filter (optional)
|
---|
[87] | 84 | my $ptr = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles");
|
---|
| 85 | my ($defpkgdir, $extpkgdir, $version, $filteredfiles) = @$ptr;
|
---|
[74] | 86 | print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
|
---|
| 87 | print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
|
---|
| 88 | print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
|
---|
| 89 | print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
|
---|
| 90 | die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
|
---|
| 91 | # Global
|
---|
| 92 | %defpkgdir = %$defpkgdir;
|
---|
| 93 | # Global
|
---|
| 94 | %extpkgdir = ();
|
---|
| 95 | %extpkgdir = %$defpkgdir if (defined $defpkgdir);
|
---|
| 96 | %version = ();
|
---|
| 97 | %version = %$version if (defined $version);
|
---|
| 98 | # Global
|
---|
| 99 | %filteredfiles = ();
|
---|
| 100 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
[38] | 101 | } else {
|
---|
[49] | 102 | die "Unable to open $ENV{'PBCONF'}/$proj.pb";
|
---|
[38] | 103 | }
|
---|
| 104 |
|
---|
[8] | 105 | #
|
---|
[5] | 106 | # Set temp directory
|
---|
[8] | 107 | #
|
---|
[7] | 108 | if (not defined $ENV{'TMPDIR'}) {
|
---|
[2] | 109 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 110 | }
|
---|
[5] | 111 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
[2] | 112 |
|
---|
[8] | 113 | #
|
---|
[5] | 114 | # Get global VERSION
|
---|
[8] | 115 | #
|
---|
[11] | 116 | open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
|
---|
[5] | 117 | $ver = <VER>;
|
---|
| 118 | chomp($ver);
|
---|
[8] | 119 | #print Dumper(%version);
|
---|
| 120 | die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
|
---|
[5] | 121 | $ENV{'PBVER'}=$ver;
|
---|
| 122 | close(VER);
|
---|
| 123 |
|
---|
[8] | 124 | #
|
---|
[74] | 125 | # Get global TAG
|
---|
[8] | 126 | #
|
---|
[11] | 127 | open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
|
---|
[5] | 128 | $tag = <TAG>;
|
---|
| 129 | chomp($tag);
|
---|
[8] | 130 | die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
|
---|
[5] | 131 | $ENV{'PBTAG'}=$tag;
|
---|
| 132 | close(TAG);
|
---|
| 133 |
|
---|
[8] | 134 | #
|
---|
[69] | 135 | # Removes all directory existing below the delivery dir
|
---|
| 136 | # as they are temp dir only
|
---|
[68] | 137 | # Files stay and have to be cleaned up manually
|
---|
[8] | 138 | #
|
---|
[25] | 139 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
| 140 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
| 141 | foreach my $d (readdir(DIR)) {
|
---|
| 142 | next if ($d =~ /^\./);
|
---|
[68] | 143 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
[74] | 144 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
[25] | 145 | }
|
---|
| 146 | closedir(DIR);
|
---|
| 147 | }
|
---|
| 148 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
[74] | 149 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
[25] | 150 | }
|
---|
[5] | 151 |
|
---|
[25] | 152 | #
|
---|
| 153 | # Set build directory
|
---|
| 154 | #
|
---|
[71] | 155 | $ENV{'PBBUILDDIR'}=$topdir."/build";
|
---|
[74] | 156 | pb_rm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
|
---|
| 157 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
[25] | 158 |
|
---|
[8] | 159 | umask 0022;
|
---|
| 160 | return($proj);
|
---|
[2] | 161 | }
|
---|
[9] | 162 |
|
---|
[74] | 163 | # Internal mkdir -p function
|
---|
| 164 | sub pb_mkdir_p {
|
---|
[29] | 165 | my @dir = @_;
|
---|
| 166 | my $ret = mkpath(@dir, 0, 0755);
|
---|
| 167 | return($ret);
|
---|
[9] | 168 | }
|
---|
| 169 |
|
---|
[74] | 170 | # Internal rm -rf function
|
---|
| 171 | sub pb_rm_rf {
|
---|
[29] | 172 | my @dir = @_;
|
---|
| 173 | my $ret = rmtree(@dir, 0, 0);
|
---|
| 174 | return($ret);
|
---|
[9] | 175 | }
|
---|
| 176 |
|
---|
[74] | 177 | # Internal system function
|
---|
| 178 | sub pb_system {
|
---|
[29] | 179 |
|
---|
| 180 | my $cmd=shift;
|
---|
[30] | 181 | my $cmt=shift || $cmd;
|
---|
[29] | 182 |
|
---|
[30] | 183 | print $LOG "$cmt... ";
|
---|
[29] | 184 | system("$cmd");
|
---|
| 185 | if ($? == -1) {
|
---|
| 186 | print $LOG "failed to execute: $!\n" if ($debug >= 0);
|
---|
| 187 | } elsif ($? & 127) {
|
---|
| 188 | printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
|
---|
| 189 | } else {
|
---|
[30] | 190 | print $LOG "OK\n" if ($debug >= 0);
|
---|
[29] | 191 | }
|
---|
[30] | 192 | }
|
---|
[74] | 193 |
|
---|
| 194 | # Function which returns a pointer on a hash
|
---|
| 195 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
| 196 | sub pb_conf_read {
|
---|
| 197 |
|
---|
| 198 | my $conffile = shift;
|
---|
| 199 | my @param = @_;
|
---|
| 200 | my $trace;
|
---|
| 201 | my @ptr;
|
---|
| 202 |
|
---|
| 203 | if ($debug > 0) {
|
---|
| 204 | $trace = 1;
|
---|
| 205 | } else {
|
---|
| 206 | $trace = 0;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | my $config = AppConfig->new({
|
---|
| 211 | # Auto Create variables mentioned in Conf file
|
---|
| 212 | CREATE => 1,
|
---|
| 213 | DEBUG => $trace,
|
---|
| 214 | GLOBAL => {
|
---|
| 215 | # Each conf item is a hash
|
---|
| 216 | ARGCOUNT => ARGCOUNT_HASH,
|
---|
| 217 | },
|
---|
| 218 | });
|
---|
| 219 | $config->file($conffile);
|
---|
| 220 | for my $param (@param) {
|
---|
| 221 | push @ptr,$config->get($param);
|
---|
| 222 | }
|
---|
| 223 | if ($#param == 0) {
|
---|
| 224 | print "DEBUG: param: ".Dumper($ptr[0])."\n" if ($debug >= 1);
|
---|
| 225 | return($ptr[0]);
|
---|
| 226 | } else {
|
---|
| 227 | my $ptr = \@ptr;
|
---|
| 228 | print "DEBUG: params: ".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 229 | return($ptr);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | sub pb_conf_init {
|
---|
| 234 |
|
---|
| 235 | my $conffile = shift;
|
---|
| 236 | my $ptr;
|
---|
| 237 | my $trace;
|
---|
| 238 |
|
---|
| 239 | if ($debug > 0) {
|
---|
| 240 | $trace = 1;
|
---|
| 241 | } else {
|
---|
| 242 | $trace = 0;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | my $config = AppConfig->new({
|
---|
| 246 | # Auto Create variables mentioned in Conf file
|
---|
| 247 | DEBUG => $trace,
|
---|
| 248 | CREATE => '1',
|
---|
| 249 | GLOBAL => {
|
---|
| 250 | # Each conf item is a hash
|
---|
| 251 | ARGCOUNT => ARGCOUNT_HASH,
|
---|
| 252 | },
|
---|
| 253 | });
|
---|
| 254 | $config->file($conffile);
|
---|
| 255 |
|
---|
| 256 | # Root of the project to build
|
---|
| 257 | # needs at least 2 levels of dir as in the upper
|
---|
| 258 | # other dirs will be created and used
|
---|
| 259 |
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | # Setup environment for CMS system
|
---|
| 263 | sub pb_cms_init {
|
---|
| 264 |
|
---|
| 265 | my $proj = shift || undef;
|
---|
| 266 | my $ret;
|
---|
| 267 |
|
---|
[87] | 268 | my ($cms,$cvsroot) = pb_conf_read("$ENV{'PBETC'}","cms","cvsroot");
|
---|
[74] | 269 | die "No CMS defined for $proj" if (not defined $cms);
|
---|
| 270 | my %cms = %$cms;
|
---|
| 271 | die "No CMS defined for $proj" if (not defined $cms{$proj});
|
---|
| 272 |
|
---|
| 273 | if ($cms{$proj} eq "svn") {
|
---|
| 274 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
|
---|
| 275 | chomp($ENV{'PBREVISION'});
|
---|
| 276 | $ENV{'PBCMSLOG'}="svn log";
|
---|
| 277 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
| 278 | $ENV{'PBCMSEXP'}="svn export";
|
---|
| 279 | } elsif ($cms{$proj} eq "cvs") {
|
---|
| 280 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 281 | chomp($ENV{'PBREVISION'});
|
---|
| 282 | $ENV{'PBCMSLOG'}="cvs log";
|
---|
| 283 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
| 284 | $ENV{'PBCMSEXP'}="cvs export"
|
---|
[87] | 285 | #
|
---|
| 286 | # Export content if needed
|
---|
| 287 | #
|
---|
| 288 | $ENV{'CVSROOT'} = $cvsroot{$proj} if (defined $cvsroot{$proj});
|
---|
[74] | 289 | } else {
|
---|
| 290 | die "CMS $cms{$proj} unknown";
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[77] | 294 | # Get all filters to apply
|
---|
| 295 | # They're cumulative from less specific to most specific
|
---|
| 296 | # suffix is .pbf
|
---|
| 297 |
|
---|
| 298 | sub pb_get_filters {
|
---|
| 299 |
|
---|
| 300 | my @ffiles;
|
---|
| 301 | my ($ffile0, $ffile1, $ffile2, $ffile3);
|
---|
| 302 | my $pbpkg = shift || die "No package specified";
|
---|
| 303 | my $dtype = shift || die "No dtype specified";
|
---|
| 304 | my $dfam = shift || die "No dfam specified";
|
---|
| 305 | my $ddir = shift || die "No ddir specified";
|
---|
| 306 | my $dver = shift || die "No dver specified";
|
---|
| 307 | my $ptr; # returned value pointer on the hash of filters
|
---|
[79] | 308 | my %ptr;
|
---|
[77] | 309 |
|
---|
| 310 | if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
|
---|
| 311 | $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 312 | $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 313 | $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 314 | $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
| 315 |
|
---|
| 316 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 317 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 318 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 319 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 320 | }
|
---|
| 321 | if (@ffiles) {
|
---|
| 322 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
[79] | 323 |
|
---|
| 324 | my $config = AppConfig->new({
|
---|
| 325 | # Auto Create variables mentioned in Conf file
|
---|
| 326 | CREATE => 1,
|
---|
| 327 | DEBUG => 0,
|
---|
| 328 | GLOBAL => {
|
---|
| 329 | # Each conf item is a hash
|
---|
| 330 | ARGCOUNT => AppConfig::ARGCOUNT_HASH
|
---|
| 331 | }
|
---|
| 332 | });
|
---|
| 333 |
|
---|
[77] | 334 | $config->file(@ffiles);
|
---|
| 335 | $ptr = $config->get("filter");
|
---|
| 336 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 337 | } else {
|
---|
| 338 | $ptr = { };
|
---|
| 339 | }
|
---|
[79] | 340 | %ptr = %$ptr;
|
---|
| 341 | return(\%ptr);
|
---|
[77] | 342 | }
|
---|
| 343 |
|
---|
| 344 | # Function which applies filter on files (only for pb)
|
---|
| 345 | sub pb_filter_file_pb {
|
---|
| 346 |
|
---|
| 347 | my $f=shift;
|
---|
| 348 | my $ptr=shift;
|
---|
| 349 | my %filter=%$ptr;
|
---|
| 350 | my $destfile=shift;
|
---|
| 351 | my $dtype=shift;
|
---|
| 352 | my $dsuf=shift;
|
---|
[80] | 353 | my $pbpkg=shift;
|
---|
| 354 | my $pbver=shift;
|
---|
| 355 | my $pbtag=shift;
|
---|
| 356 | my $pbrev=shift;
|
---|
| 357 | my $pbdate=shift;
|
---|
[77] | 358 |
|
---|
| 359 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 360 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 361 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 362 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 363 | while (<FILE>) {
|
---|
| 364 | my $line = $_;
|
---|
| 365 | foreach my $s (keys %filter) {
|
---|
| 366 | # Process single variables
|
---|
[79] | 367 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
|
---|
[77] | 368 | my $tmp = $filter{$s};
|
---|
| 369 | next if (not defined $tmp);
|
---|
| 370 | # Expand variables if any single one found
|
---|
[79] | 371 | print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
|
---|
[77] | 372 | if ($tmp =~ /\$/) {
|
---|
| 373 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 374 | # special case for ChangeLog only for pb
|
---|
| 375 | } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
| 376 | $tmp = "";
|
---|
[82] | 377 | my $p = $defpkgdir{$pbpkg};
|
---|
| 378 | $p = $extpkgdir{$pbpkg} if (not defined $p);
|
---|
| 379 | pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
|
---|
[77] | 380 | }
|
---|
| 381 | $line =~ s|$s|$tmp|;
|
---|
| 382 | }
|
---|
| 383 | print DEST $line;
|
---|
| 384 | }
|
---|
| 385 | close(FILE);
|
---|
| 386 | close(DEST);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | # Function which applies filter on files (external call)
|
---|
| 390 | sub pb_filter_file {
|
---|
| 391 |
|
---|
| 392 | my $f=shift;
|
---|
| 393 | my $ptr=shift;
|
---|
| 394 | my %filter=%$ptr;
|
---|
| 395 | my $destfile=shift;
|
---|
[80] | 396 | my $pbpkg=shift;
|
---|
| 397 | my $pbver=shift;
|
---|
| 398 | my $pbtag=shift;
|
---|
| 399 | my $pbrev=shift;
|
---|
| 400 | my $pbdate=shift;
|
---|
[77] | 401 |
|
---|
| 402 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 403 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 404 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 405 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 406 | while (<FILE>) {
|
---|
| 407 | my $line = $_;
|
---|
| 408 | foreach my $s (keys %filter) {
|
---|
| 409 | # Process single variables
|
---|
| 410 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
| 411 | my $tmp = $filter{$s};
|
---|
| 412 | next if (not defined $tmp);
|
---|
| 413 | # Expand variables if any single one found
|
---|
| 414 | if ($tmp =~ /\$/) {
|
---|
| 415 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 416 | }
|
---|
| 417 | $line =~ s|$s|$tmp|;
|
---|
| 418 | }
|
---|
| 419 | print DEST $line;
|
---|
| 420 | }
|
---|
| 421 | close(FILE);
|
---|
| 422 | close(DEST);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 |
|
---|
[2] | 426 | 1;
|
---|