Changeset 2253 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder


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
Location:
devel/pb-modules/lib/ProjectBuilder
Files:
2 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
  • devel/pb-modules/lib/ProjectBuilder/Env.pm

    r2252 r2253  
    7676
    7777if (! -f $ENV{'PBETC'}) {
    78     pb_log(0, "No existing $ENV{'PBETC'} found, creating one as template\n");
    79     open(PBRC, "> $ENV{'PBETC'}") || die "Unable to create $ENV{'PBETC'}";
    80     print PBRC << "EOF";
    81 ---
     78    if (! -f "$dir/.pbrc") {
     79        pb_log(0, "No existing $ENV{'PBETC'} found, creating one as template\n");
     80        open(PBRC, "> $ENV{'PBETC'}") || die "Unable to create $ENV{'PBETC'}";
     81        print PBRC << "EOF";
     82--- %YAML 1.0
    8283#
    8384# Define for each project the URL of its pbconf repository
    8485# No default option allowed here as they need to be all different
    8586#
    86 #pbconfurl example = svn+ssh://svn.example.org/svn/pb/projects/example/pbconf
    87 #pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
    88 
     87#  pbconfurl:
     88#    example: svn+ssh://svn.example.org/svn/pb/projects/example/pbconf
     89#  pbconfurl:
     90#    pb: svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
     91#
    8992# Under that dir will take place everything related to pb
    9093# If you want to use VMs/chroot/..., then use \$ENV{'HOME'} to make it portable
    9194# to your VMs/chroot/...
    9295# if not defined then /var/cache
    93 #pbdefdir default = \$ENV{'HOME'}/pb/projects
    94 #pbdefdir pb = \$ENV{'HOME'}
    95 
     96#  pbdefdir:
     97#    default: \$ENV{'HOME'}/pb/projects
     98#  pbdefdir:
     99#    pb: \$ENV{'HOME'}
     100#
    96101# If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
    97 #pbconfdir pb = \$ENV{'HOME'}/pb/pbconf
    98 
     102#  pbconfdir:
     103#    pb: \$ENV{'HOME'}/pb/pbconf
     104#
    99105# If not defined, pbprojdir is under pbdefdir/pbproj
    100106# Only defined if we have access to the dev of the project
    101 #pbprojdir example = \$ENV{'HOME'}/example/svn
    102 
     107#  pbprojdir:
     108#    example: \$ENV{'HOME'}/example/svn
     109#
    103110# We have commit acces to these
    104 #pburl example = cvs+ssh://user\@example.cvs.sourceforge.net:/cvsroot/example
    105 #pburl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb
    106 
     111#  pburl:
     112#    example: cvs+ssh://user\@example.cvs.sourceforge.net:/cvsroot/example
     113#  pburl:
     114#    pb: svn+ssh://svn.project-builder.org/mondo/svn/pb
     115#
    107116# I mask my real login on the ssh machines here
    108 #sshlogin example = user
    109 
     117#  sshlogin:
     118#    example: user
     119#
    110120# where to find Build System infos:
    111 #vmpath default = /home/qemu
    112 #vepath default = /home/rpmbootstrap
    113 #rmpath default = /home/remote
    114 
     121#  vmpath:
     122#    default: /home/qemu
     123#  vepath:
     124#    default: /home/rpmbootstrap
     125#  rmpath:
     126#    default: /home/remote
     127#
    115128# Overwrite generic setup
    116 #vmport pb = 2223
    117 #vmport example = 2224
    118 
     129#  vmport:
     130#    pb: 2223
     131#  vmport:
     132#    example: 2224
     133#
    119134# Info on who is packaging
    120 #pbpackager default = William Porte <bill\@porte.org>
    121 #pbpassphrase default = TheScretePassPhrase
    122 #pbpassfile default = /home/williamporte/secret/passfile
    123 EOF
     135#  pbpackager:
     136#    default: William Porte <bill\@porte.org>
     137#  pbpassphrase:
     138#    default: TheScretePassPhrase
     139#  pbpassfile:
     140#    default: /home/williamporte/secret/passfile
     141EOF
     142    } else {
     143        pb_log(0, "Found an existing $dir/.pbrc converting it into $ENV{'PBETC'}\n");
     144        pb_conf_update_v0("$dir/.pbrc",$ENV{'PBETC'});
    124145    }
     146}
    125147
    126148# We only have one configuration file for now.
     
    421443            open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
    422444            print CONF << "EOF";
    423 ---
     445--- YAML 1.0
    424446#
    425447# Project Builder configuration file
     
    620642            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/all.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/all.yml";
    621643            print CONF << "EOF";
    622 ---
     644--- YAML 1.0
    623645#
    624646# \$Id\$
     
    692714            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.yml";
    693715            print CONF << "EOF";
    694 ---
     716--- YAML 1.0
    695717#
    696718# \$Id\$
     
    725747            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora.yml";
    726748            print CONF << "EOF";
    727 ---
     749--- YAML 1.0
    728750#
    729751# \$Id\$
     
    756778                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml";
    757779                print CONF << "EOF";
    758 ---
     780--- YAML 1.0
    759781#
    760782# \$Id\$
     
    770792            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.yml";
    771793            print CONF << "EOF";
    772 ---
     794--- YAML 1.0
    773795#
    774796# \$Id\$
     
    799821            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml";
    800822            print CONF << "EOF";
    801 ---
     823--- YAML 1.0
    802824#
    803825# \$Id\$
     
    815837            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml";
    816838            print CONF << "EOF";
    817 ---
     839--- YAML 1.0
    818840#
    819841# \$Id\$
     
    831853            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml";
    832854            print CONF << "EOF";
    833 ---
     855--- YAML 1.0
    834856#
    835857# \$Id\$
     
    847869            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml";
    848870            print CONF << "EOF";
    849 ---
     871--- YAML 1.0
    850872#
    851873# \$Id\$
     
    863885            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian.yml";
    864886            print CONF << "EOF";
    865 ---
     887--- YAML 1.0
    866888#
    867889# \$Id\$
     
    880902                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    881903                print CONF << "EOF";
    882 ---
     904--- YAML 1.0
    883905#
    884906# \$Id\$
     
    898920                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    899921                print CONF << "EOF";
    900 ---
     922--- YAML 1.0
    901923#
    902924# \$Id\$
     
    916938                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    917939                print CONF << "EOF";
    918 ---
     940--- YAML 1.0
    919941#
    920942# \$Id\$
     
    935957                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    936958                print CONF << "EOF";
    937 ---
     959--- YAML 1.0
    938960#
    939961# \$Id\$
     
    952974            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.yml";
    953975            print CONF << "EOF";
    954 ---
     976--- YAML 1.0
    955977#
    956978# \$Id\$
     
    969991            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.yml";
    970992            print CONF << "EOF";
    971 ---
     993--- YAML 1.0
    972994#
    973995# \$Id\$
Note: See TracChangeset for help on using the changeset viewer.