Changeset 77 in ProjectBuilder for devel/pb/lib/ProjectBuilder


Ignore:
Timestamp:
Sep 3, 2007, 3:34:11 AM (17 years ago)
Author:
Bruno Cornec
Message:

transfer pb_fiter_file to Base and duplicate :-( for external call
Create sub functions per action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/lib/ProjectBuilder/Base.pm

    r74 r77  
    6262        my $pbroot = pb_conf_read($pbrc{$proj},"pbroot");
    6363        my %pbroot = %$pbroot;
    64         # There is normaly only one line in it
     64        # All lines should point to the same pbroot so take the first
    6565        $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
    6666        print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
     
    300300}
    301301
     302# Get all filters to apply
     303# They're cumulative from less specific to most specific
     304# suffix is .pbf
     305
     306sub pb_get_filters {
     307
     308my @ffiles;
     309my ($ffile0, $ffile1, $ffile2, $ffile3);
     310my $pbpkg = shift || die "No package specified";
     311my $dtype = shift || die "No dtype specified";
     312my $dfam = shift || die "No dfam specified";
     313my $ddir = shift || die "No ddir specified";
     314my $dver = shift || die "No dver specified";
     315my $ptr; # returned value pointer on the hash of filters
     316
     317if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
     318    $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
     319    $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
     320    $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
     321    $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
     322
     323    push @ffiles,$ffile0 if (defined $ffile0);
     324    push @ffiles,$ffile1 if (defined $ffile1);
     325    push @ffiles,$ffile2 if (defined $ffile2);
     326    push @ffiles,$ffile3 if (defined $ffile3);
     327}
     328my $config = AppConfig->new({
     329    # Auto Create variables mentioned in Conf file
     330    CREATE => 1,
     331    DEBUG => 0,
     332    GLOBAL => {
     333        # Each conf item is a hash
     334        ARGCOUNT => AppConfig::ARGCOUNT_HASH
     335    }
     336});
     337
     338if (@ffiles) {
     339    print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
     340    $config->file(@ffiles);
     341    $ptr = $config->get("filter");
     342    print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
     343} else {
     344    $ptr = { };
     345}
     346return($ptr);
     347}
     348
     349# Function which applies filter on files (only for pb)
     350sub pb_filter_file_pb {
     351
     352my $f=shift;
     353my $ptr=shift;
     354my %filter=%$ptr;
     355my $destfile=shift;
     356my $pbpkg=shift;
     357my $dtype=shift;
     358my $dsuf=shift;
     359
     360print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
     361pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
     362open(DEST,"> $destfile") || die "Unable to create $destfile";
     363open(FILE,"$f") || die "Unable to open $f: $!";
     364while (<FILE>) {
     365    my $line = $_;
     366    foreach my $s (keys %filter) {
     367        # Process single variables
     368        print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
     369        my $tmp = $filter{$s};
     370        next if (not defined $tmp);
     371        # Expand variables if any single one found
     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 = "";
     377            my $p = $defpkgdir{$pbpkg};
     378            $p = $extpkgdir{$pbpkg} if (not defined $p);
     379            pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
     380        }
     381        $line =~ s|$s|$tmp|;
     382    }
     383    print DEST $line;
     384}
     385close(FILE);
     386close(DEST);
     387}
     388
     389# Function which applies filter on files (external call)
     390sub pb_filter_file {
     391
     392my $f=shift;
     393my $ptr=shift;
     394my %filter=%$ptr;
     395my $destfile=shift;
     396
     397print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
     398pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
     399open(DEST,"> $destfile") || die "Unable to create $destfile";
     400open(FILE,"$f") || die "Unable to open $f: $!";
     401while (<FILE>) {
     402    my $line = $_;
     403    foreach my $s (keys %filter) {
     404        # Process single variables
     405        print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
     406        my $tmp = $filter{$s};
     407        next if (not defined $tmp);
     408        # Expand variables if any single one found
     409        if ($tmp =~ /\$/) {
     410            eval { $tmp =~ s/(\$\w+)/$1/eeg };
     411        }
     412        $line =~ s|$s|$tmp|;
     413    }
     414    print DEST $line;
     415}
     416close(FILE);
     417close(DEST);
     418}
     419
     420
    3024211;
Note: See TracChangeset for help on using the changeset viewer.