Ignore:
Timestamp:
Dec 23, 2016, 4:25:49 AM (3 years ago)
Author:
bruno
Message:

Fix conf file analysis:

  • pb_conf_get_if now returns the value and theone for default if it doesn't exist. pb_conf_get inherits it
  • Fix pb_conf_add_last_in_hash by analyzing correctly the 2 hashes without taking in account default values
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Conf.pm

    r2152 r2154  
    2929 
    3030our @ISA = qw(Exporter);
    31 our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_write pb_conf_get pb_conf_get_if pb_conf_print pb_conf_get_all pb_conf_get_hash pb_conf_cache);
     31our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_write pb_conf_get pb_conf_get_if pb_conf_get_all pb_conf_get_hash pb_conf_cache);
    3232($VERSION,$REVISION) = pb_version_init();
    3333
     
    156156    return($lh) if (defined $pbconffiles{$cf});
    157157   
    158     # Add the new one at the end
     158    # The new conf file overload values already managed
    159159    my $num = keys %pbconffiles;
    160160    pb_log(2,"DEBUG: pb_conf_cache of $cf at position $num\n");
     
    317317sub pb_conf_get_if {
    318318
    319 return(pb_conf_get_in_hash_if($h,@_));
     319my @param = @_;
     320my @return = pb_conf_get_in_hash_if($h,@_);
     321my $proj = undef;
     322
     323if (not defined $ENV{'PBPROJ'}) {
     324    $proj = "unknown";
     325} else {
     326    $proj = $ENV{'PBPROJ'};
     327}
     328
     329foreach my $i (0..$#param) {
     330    if (not defined $return[$i]->{$proj}) {
     331        $return[$i]->{$proj} = $return[$i]->{'default'} if (defined $return[$i]->{'default'});
     332    }
     333}
     334return(@return);
    320335}
    321336
     
    342357# Everything is returned via @h
    343358# @h contains the values overloading what @ptr may contain.
    344 my @h = pb_conf_get_if(@params);
     359my @h = pb_conf_get_in_hash_if($h,@params);
    345360my @ptr = pb_conf_get_in_hash_if($ptr,@params);
    346361
     
    349364
    350365pb_log(2,"DEBUG: pb_conf_add_last_in_hash params: ".Dumper(@params)."\n");
    351 pb_log(2,"DEBUG: pb_conf_add_last_in_hash hash: ".Dumper(@h)."\n");
    352 pb_log(2,"DEBUG: pb_conf_add_last_in_hash input: ".Dumper(@ptr)."\n");
     366pb_log(2,"DEBUG: pb_conf_add_last_in_hash current hash: ".Dumper(@h)."\n");
     367pb_log(2,"DEBUG: pb_conf_add_last_in_hash new inputs: ".Dumper(@ptr)."\n");
    353368
    354369foreach my $i (0..$#params) {
    355370    $p1 = $h[$i];
    356371    $p2 = $ptr[$i];
    357     # Always try to take the param from h
     372    # Always try to take the param from h in priority
    358373    # in order to mask what could be defined already in ptr
    359374    if (not defined $p2) {
    360375        # exit if no p1 either
    361376        next if (not defined $p1);
    362         # No ref in p2 so use p1
    363         $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if ((not defined $p1->{$ENV{'PBPROJ'}}) && (defined $p1->{'default'}));
    364377    } else {
    365378        # Ref found in p2
    366379        if (not defined $p1) {
    367380            # No ref in p1 so use p2's value
    368             $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if ((not defined $p2->{$ENV{'PBPROJ'}}) && (defined $p2->{'default'}));
    369381            $p1 = $p2;
    370382        } else {
    371383            # Both are defined - handling the overloading
    372             if (not defined $p1->{'default'}) {
    373                 if (defined $p2->{'default'}) {
    374                     $p1->{'default'} = $p2->{'default'};
    375                 }
    376             }
    377 
     384            # Now copy back into p1 all p2 content
     385            # as p1 content always has priority over p2
    378386            if (not defined $p1->{$ENV{'PBPROJ'}}) {
    379387                if (defined $p2->{$ENV{'PBPROJ'}}) {
    380388                    $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
    381                 } else {
    382                     $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (defined $p1->{'default'});
    383389                }
    384390            }
    385391            # Now copy back into p1 all p2 content which doesn't exist in p1
    386             # p1 content always has priority over p2
     392            # # p1 content always has priority over p2
    387393            foreach my $k (keys %$p2) {
    388394                $p1->{$k} = $p2->{$k} if (not defined $p1->{$k});
Note: See TracChangeset for help on using the changeset viewer.