Changeset 556 in ProjectBuilder for devel/pb/bin/pb


Ignore:
Timestamp:
Sep 23, 2008, 12:41:14 PM (16 years ago)
Author:
Bruno Cornec
Message:
  • Prepare a web delivery function
  • Creates a pbinit script for website for mondorescue
  • Adds a pb_set_content function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r549 r556  
    446446
    447447    pb_announce();
    448 } elsif ($action =~ /^webnews2html$/) {
    449     # For news handling only. Require avoids the systematic load of these modules
     448} elsif ($action =~ /^web2ssh$/) {
    450449    require DBI;
    451450
    452     pb_web_news2html();
     451    pb_cms2build("Web");
     452    pb_send2target("Web");
    453453} else {
    454454    pb_log(0,"\'$action\' is not available\n");
     
    458458sub pb_cms2build {
    459459
    460     my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
    461     my @pkgs = @$pkg;
     460    my $param = shift || undef;
     461
     462    my $pkg;
     463    my @pkgs;
     464
     465    # If Website, then pkg is only the website
     466    if ((defined $param) && ($param eq "Web")) {
     467        my $webdir = pb_conf_get("webdir");
     468        @pkgs = ($webdir->{$ENV{'PBPROJ'}});
     469        $extpkgdir = $webdir;
     470        pb_log(0,"Packages: ".join(',',@pkgs)."\n");
     471    } else {
     472        $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
     473        @pkgs = @$pkg;
     474    }
     475
    462476    my %pkgs;
    463477    my %pb;             # Structure to store conf info
     
    501515        my $dir = $defpkgdir->{$pbpkg};
    502516        $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
     517        $dir = $webdir->{$ENV{'PBPROJ'}} if ((defined $param) && ($param eq "Web"));
    503518        pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
    504519
     
    542557            $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
    543558        }
    544 
     559   
    545560        # Setup %pb structure to allow filtering later on, on files using that structure
    546561        $pb{'tag'} = $pbtag;
     
    557572        $pb{'patches'} = \%patches;
    558573        pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
    559 
    560         foreach my $d (split(/,/,$tmpl)) {
    561             my ($name,$ver,$arch) = split(/-/,$d);
    562             chomp($arch);
    563             my ($ddir, $dver, $dfam);
    564             ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'}) = pb_distro_init($name,$ver);
    565             pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
    566             pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
    567 
    568             # We need to compute the real name of the package
    569             my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
    570             $pb{'realpkg'} = $pbrealpkg;
    571             pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
    572 
    573             # Filter build files from the less precise up to the most with overloading
    574             # Filter all files found, keeping the name, and generating in dest
    575 
    576             # Find all build files first relatively to PBROOTDIR
    577             # Find also all specific files referenced in the .pb conf file
    578             my %bfiles = ();
    579             my %pkgfiles = ();
    580             $build{"$ddir-$dver-$arch"} = "yes";
    581 
    582             if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
    583                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    584             } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
    585                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    586             } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
    587                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    588             } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
    589                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    590             } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
    591                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    592             } else {
    593                 $build{"$ddir-$dver-$arch"} = "no";
    594                 next;
    595             }
    596             pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
    597 
    598             # Get all filters to apply
    599             my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
    600 
    601             # Prepare local patches for this distro - They are always applied first - May be a problem one day
    602             foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
    603                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
    604                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
    605                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
    606                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
    607                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
    608                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
    609                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
    610                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
    611                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
    612                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
    613                 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
    614                 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
    615             }
    616 
    617             # Prepare also remote patches to be included - Applied after the local ones
    618             foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
    619                 my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
    620                 next if (not -f $f);
    621                 if (not open(PATCH,$f)) {
    622                     pb_display("Unable to open existing external patch file content $f\n");
     574   
     575        # Do not do that for website
     576        if ((not defined $param) || ($param ne "Web")) {
     577            foreach my $d (split(/,/,$tmpl)) {
     578                my ($name,$ver,$arch) = split(/-/,$d);
     579                chomp($arch);
     580                my ($ddir, $dver, $dfam);
     581                ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'}) = pb_distro_init($name,$ver);
     582                pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
     583                pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
     584   
     585                # We need to compute the real name of the package
     586                my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
     587                $pb{'realpkg'} = $pbrealpkg;
     588                pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
     589   
     590                # Filter build files from the less precise up to the most with overloading
     591                # Filter all files found, keeping the name, and generating in dest
     592   
     593                # Find all build files first relatively to PBROOTDIR
     594                # Find also all specific files referenced in the .pb conf file
     595                my %bfiles = ();
     596                my %pkgfiles = ();
     597                $build{"$ddir-$dver-$arch"} = "yes";
     598   
     599                if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
     600                    pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     601                } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
     602                    pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     603                } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
     604                    pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     605                } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
     606                    pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     607                } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
     608                    pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     609                } else {
     610                    $build{"$ddir-$dver-$arch"} = "no";
    623611                    next;
    624612                }
    625                 while (<PATCH>) {
    626                     chomp();
    627                     $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
    628                     $patches{"$ddir-$dver-$arch"} .= "$_";
     613                pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
     614   
     615                # Get all filters to apply
     616                my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
     617   
     618                # Prepare local patches for this distro - They are always applied first - May be a problem one day
     619                foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
     620                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
     621                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
     622                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
     623                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
     624                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
     625                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
     626                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
     627                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
     628                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
     629                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
     630                    $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
     631                    $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
    629632                }
    630                 close(PATCH);
    631             }
    632             pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
    633 
    634             # Apply now all the filters on all the files concerned
    635             # destination dir depends on the type of file
    636             if (defined $ptr) {
    637                 # For patch support
    638                 $pb{'tuple'} = "$ddir-$dver-$arch";
    639                 foreach my $f (values %bfiles,values %pkgfiles) {
    640                     pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
     633   
     634                # Prepare also remote patches to be included - Applied after the local ones
     635                foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
     636                    my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
     637                    next if (not -f $f);
     638                    if (not open(PATCH,$f)) {
     639                        pb_display("Unable to open existing external patch file content $f\n");
     640                        next;
     641                    }
     642                    while (<PATCH>) {
     643                        chomp();
     644                        $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
     645                        $patches{"$ddir-$dver-$arch"} .= "$_";
     646                    }
     647                    close(PATCH);
    641648                }
    642             }
    643         }
    644         my @found;
    645         my @notfound;
    646         foreach my $b (keys %build) {
    647             push @found,$b if ($build{$b} =~ /yes/);
    648             push @notfound,$b if ($build{$b} =~ /no/);
    649         }
    650         pb_log(0,"Build files generated for ".join(',',sort(@found))."\n");
    651         pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
    652         pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
     649                pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
     650   
     651                # Apply now all the filters on all the files concerned
     652                # destination dir depends on the type of file
     653                if (defined $ptr) {
     654                    # For patch support
     655                    $pb{'tuple'} = "$ddir-$dver-$arch";
     656                    foreach my $f (values %bfiles,values %pkgfiles) {
     657                        pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
     658                    }
     659                }
     660            }
     661            my @found;
     662            my @notfound;
     663            foreach my $b (keys %build) {
     664                push @found,$b if ($build{$b} =~ /yes/);
     665                push @notfound,$b if ($build{$b} =~ /no/);
     666            }
     667            pb_log(0,"Build files generated for ".join(',',sort(@found))."\n");
     668            pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
     669            pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
     670        }
    653671
    654672        # Get the generic filter (all.pbf) and
     
    668686        pb_log(2,"Files ".$liste."have been filtered\n");
    669687
    670         my %tmp;
    671         # Filter potential patches (local + remote)
    672         pb_log(0,"Delivering and compressing patches ");
    673         foreach my $v (keys %patches) {
    674             pb_mkdir_p("$dest/pbconf/$v/pbpatch");
    675             foreach my $pf (split(/,/,$patches{$v})) {
    676                 my $pp = basename($pf);
    677                 pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
    678                 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
    679                 pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
    680                 $tmp{$pf} = "";
    681             }
    682         }
    683         foreach my $v (keys %tmp) {
    684             pb_log(0,"$v ");
    685         }
    686         pb_log(0,"\n");
     688        # Do not do that for website
     689        if ((not defined $param) || ($param ne "Web")) {
     690            my %tmp;
     691            # Filter potential patches (local + remote)
     692            pb_log(0,"Delivering and compressing patches ");
     693            foreach my $v (keys %patches) {
     694                pb_mkdir_p("$dest/pbconf/$v/pbpatch");
     695                foreach my $pf (split(/,/,$patches{$v})) {
     696                    my $pp = basename($pf);
     697                    pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
     698                    pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
     699                    pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
     700                    $tmp{$pf} = "";
     701                }
     702            }
     703            foreach my $v (keys %tmp) {
     704                pb_log(0,"$v ");
     705            }
     706            pb_log(0,"\n");
     707        } else {
     708            # Instead call News generation
     709            pb_web_news2html($dest);
     710        }
    687711
    688712        # Prepare the dest directory for archive
     
    958982        $conf = "veconf";
    959983        $rebuild = "verebuild";
     984    } elsif ($cmt eq "Web") {
     985        $host = "websshhost";
     986        $login = "websshlogin";
     987        $dir = "websshdir";
     988        $port = "websshport";
    960989    }
    961990    my $cmd = "";
     
    10031032    } elsif ($cmt eq "Script") {
    10041033        $src="$src $ENV{'PBDESTDIR'}/pbscript";
    1005     } elsif ($cmt eq "Announce") {
     1034    } elsif (($cmt eq "Announce") || ($cmt eq "Web")) {
    10061035        $src="$src $ENV{'PBTMP'}/pbscript";
    10071036    } elsif ($cmt eq "Packages") {
     
    10551084            # This is a test pkg => target dir is under test
    10561085            $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test";
     1086        }
     1087    } elsif ($cmt eq "Web") {
     1088        $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
     1089        if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
     1090            # This is a test website => target dir is under test
     1091            $tdir = $sshdir->{$ENV{'PBPROJ'}}."../test";
    10571092        }
    10581093    } elsif ($cmt eq "Packages") {
     
    21082143sub pb_web_news2html {
    21092144
     2145    my $dest = shift || $ENV{'PBTMP'};
     2146
    21102147    # Get all required parameters
    21112148    my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
     
    21222159    my $oldfirst = strftime("%Y-%m-%d", 0, 0, 1, 1, localtime->year()-1, 0, 0, -1);
    21232160    my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
    2124     my $ynews = "";     # year's news
    2125     my $lynews = "";    # last year news
    2126     my $pynews = "";    # previous years news
    2127     my $fpnews = "";    # first page news
     2161    my %news;
     2162    $news{"cy"} = "";   # current year's news
     2163    $news{"ly"} = "";   # last year news
     2164    $news{"py"} = "";   # previous years news
     2165    $news{"fp"} = "";   # first page news
    21282166    my $cpt = 4;        # how many news for first page
    21292167    # Extract info from DB
    21302168    foreach my $row (@$all) {
    21312169        my ($id, $date, $announce) = @$row;
    2132         $ynews = $ynews."<p><B>$date</B> $announce\n" if (("$date" le $pbdate) && ($firstjan le "$date"));
    2133         $lynews = $lynews."<p><B>$date</B> $announce\n" if (("$date" le $firstjan) && ($oldfirst le "$date"));
    2134         $pynews = $pynews."<p><B>$date</B> $announce\n" if ("$date" le $oldfirst);
    2135         $fpnews = $fpnews."<p><B>$date</B> $announce\n" if ($cpt > 0);
     2170        $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if (("$date" le $pbdate) && ($firstjan le "$date"));
     2171        $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if (("$date" le $firstjan) && ($oldfirst le "$date"));
     2172        $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if ("$date" le $oldfirst);
     2173        $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
    21362174        $cpt--;
    21372175    }
    2138     pb_log(1,"fpnews: $fpnews\n");
     2176    pb_log(1,"news{fp}: ".$news{"fp"}."\n");
    21392177    $dbh->disconnect;
    2140 }
     2178
     2179    # Generate the HTML content
     2180    foreach my $pref (keys %news) {
     2181        open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
     2182        print NEWS "$news{$pref}";
     2183        close(NEWS);
     2184    }
     2185}
     2186
    21412187
    21422188# Return the SSH key file to use
Note: See TracChangeset for help on using the changeset viewer.