Changeset 1905 in ProjectBuilder


Ignore:
Timestamp:
Oct 9, 2014, 12:14:42 PM (10 years ago)
Author:
Bruno Cornec
Message:
  • pb_conf_write is indeed working and tested now (git error)
Location:
devel/pb-modules
Files:
2 edited

Legend:

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

    r1904 r1905  
    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);
     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_print pb_conf_get_all pb_conf_cache);
    3232($VERSION,$REVISION) = pb_version_init();
    3333
     
    118118open(CONF,$cf) || confess "Unable to open $cf";
    119119while(<CONF>) {
     120    next if (/^#/);
    120121    if (/^\s*([A-z0-9-_.]+)\s+([[A-z0-9-_.]+)\s*=\s*(.*)$/) {
    121122        pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n");
     
    233234
    234235my $conffile = shift;
    235 my $h = $_;
    236 
    237 open(CONF,"> $conffile") || confess "Unbale to wirte into $conffile";
     236my $h = shift;
     237
     238confess "No configuration file defined to write into !" if (not defined $conffile);
     239confess "No hash defined to read from !" if (not defined $h);
     240open(CONF,"> $conffile") || confess "Unable to write into $conffile";
    238241
    239242foreach my $p (keys %$h) {
    240     foreach my $key ($p) {
    241         print CONF "$p $key = $p->{$key}\n";
     243    my $j = $h->{$p};
     244    foreach my $k (keys %$j) {
     245        print CONF "$p $k = $j->{$k}\n";
    242246    }
    243247}
  • devel/pb-modules/t/Conf.t

    r1904 r1905  
    66use ProjectBuilder::Base;
    77use ProjectBuilder::Conf;
     8use ProjectBuilder::Distribution;
    89
    910eval
     
    2829
    2930my $nt = 0;
    30     is($path, $test->{$uri}[4], "pb_get_uri Test path $uri");
    31     $nt++;
    32 }
    3331
    3432$ENV{'TMPDIR'} = "/tmp";
     
    3634
    3735pb_conf_init("test");
    38 my $cf = pb_distro_conffile();
    39 my $cnt = pb_get_content($cf);
     36open(FILE,"> $ENV{'TMPDIR'}/conf.pb") || die "Unable to create $ENV{'TMPDIR'}/conf.pb";
     37# should be in alphabetic order
     38print FILE "truc mageia-4-x86_64 = la tete a toto\n";
     39print FILE "yorro mageia-3-x86_64 = tartampion\n";
     40print FILE "zz mageia-3-x86_64 = yy\n";
     41close(FILE);
     42my $cnt = pb_get_content("$ENV{'TMPDIR'}/conf.pb");
    4043
    41 my %h = pb_conf_cache($cf,\%h);
    42 pb_conf_write("$PBTMP/test.pb",\%h);
    43 my $content = pb_get_content("$PBTMP/test.pb");
     44my %h;
     45my $h = \%h;
     46$h = pb_conf_cache("$ENV{'TMPDIR'}/conf.pb",$h);
     47pb_conf_write("$ENV{'TMPDIR'}/test.pb",$h);
     48my $content = pb_get_content("$ENV{'TMPDIR'}/test.pb");
    4449is($cnt, $content, "pb_conf_write Test");
    4550$nt++;
     51unlink("$ENV{'TMPDIR'}/conf.pb");
     52unlink("$ENV{'TMPDIR'}/test.pb");
    4653
    4754done_testing($nt);
Note: See TracChangeset for help on using the changeset viewer.