Changeset 2253 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/Conf.pm


Ignore:
Timestamp:
Aug 30, 2017, 5:07:33 PM (7 years ago)
Author:
Bruno Cornec
Message:

More YAML transformations

  • We now generate a .pbrc.yml if none exist
  • If no .pbrc.yml is found but a former .pbrc is there convert it automatically
  • Adds a function pb_conf_update_v0 to convert automatically v0 conf files into v1 conf files
  • pb_conf_cache now handles multi lines and can be used for filter management by pb_get_filters
File:
1 edited

Legend:

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

    r2252 r2253  
    192192        if (/^\s*([A-z0-9-_.]+)\s+([[A-z0-9-_.\?\[\]\*\+\\]+)\s*=\s*(.*)$/) {
    193193            pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n");
    194             $lh->{$1}->{$2}=$3;
     194            my ($what, $var, $value) = ($1, $2, $3);
     195            # Add support for multi-lines
     196            while ($value =~ s/\\\s*$//o) {
     197                $_ = <CONF>;
     198                die "Still processing continuations for $what $var at EOF" if (not defined $_);
     199                s/[\r\n]//go;
     200                $value .= "\n$_";
     201            }
     202            $lh->{$what}->{$var}=$value;
     203        } elsif ((/^\s*#/o) || (/^\s*$/o)) {
     204            # ignore
     205        } else {
     206            chomp();
     207            warn "unexpected line '$_' in $f";
    195208        }
    196209    }
     
    513526}
    514527
     528=item B<pb_conf_update_v0>
     529
     530This function transform the old configuration v0 file as first param into a new v1 one as second param
     531
     532=cut
     533
     534sub pb_conf_update_v0 {
     535
     536my $orig = shift;
     537my $dest = shift;
     538
     539open(ORIG,$orig) || confess "Unable to open $orig";
     540confess "Will not erase existing $dest while transforming $orig" if (-f $dest);
     541open(DEST,"> $dest") || confess "Unable to write into $dest";
     542print DEST "--- %YAML 1.0\n";
     543my $parambkp = "";
     544my $pbconfverbkp = $PBCONFVER;
     545# We force migration from v0 to v1
     546$PBCONFVER = 0;
     547my $lh0;
     548$lh0 = pb_conf_cache($orig,$lh0);
     549$PBCONFVER = $pbconfverbkp;
     550
     551# We can't just write the YAML if we want to ckeep comments !
     552while (<ORIG>) {
     553    if ($_ =~ /^#/) {
     554        # Keep comments
     555        print DEST $_;
     556    } else {
     557        if (/^\s*([A-z0-9-_]+)\s+(.+)$/) {
     558            # Handle parameters
     559            my ($param,$void) = ($1, $2);
     560            print DEST "  $param:\n" if ($param ne $parambkp);
     561            print DEST "    $lh0->{$param} $lh0->{$param}->{$var}\n";
     562            $parambkp = $param;
     563        } else {
     564            pb_log(0,"Unable to handle line $_\n");
     565        }
     566    }
     567}
     568close(ORIG);
     569close(DEST);
     570return();
     571}
     572
    515573=back
    516574
Note: See TracChangeset for help on using the changeset viewer.