Changeset 473 in ProjectBuilder


Ignore:
Timestamp:
Jun 4, 2008, 3:04:36 AM (16 years ago)
Author:
Bruno Cornec
Message:

Working announce action for pb

Location:
devel
Files:
4 edited

Legend:

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

    r471 r473  
    126126The first parameter is the shell command to call.
    127127The second parameter is the message to print on screen. If none is given, then the command is printed.
     128The third parameter print the result of the command after correct execution if value is verbose. If value is noredir, it avoids redirecting outputs (e.g. for vi).
    128129This function returns the result the return value of the system command.
    129130
     
    137138my $cmt=shift || $cmd;
    138139my $verbose=shift || undef;
     140my $redir = "";
    139141
    140142pb_log(0,"$cmt... ");
    141143pb_log(1,"Executing $cmd\n");
    142 system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
     144$redir = "2>&1 > $ENV{'PBTMP'}/system.log" if ((! defined $verbose) || ($verbose ne "noredir"));
     145system("$cmd $redir");
    143146my $res = $?;
    144147if ($res == -1) {
    145148    pb_log(0,"failed to execute ($cmd): $!\n");
    146     pb_display_file("$ENV{'PBTMP'}/system.log");
     149    pb_display_file("$ENV{'PBTMP'}/system.log") if (-f "$ENV{'PBTMP'}/system.log");
    147150} elsif ($res & 127) {
    148151    pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
    149     pb_display_file("$ENV{'PBTMP'}/system.log");
     152    pb_display_file("$ENV{'PBTMP'}/system.log") if (-f "$ENV{'PBTMP'}/system.log");
    150153} elsif ($res == 0) {
    151154    pb_log(0,"OK\n");
    152     pb_display_file("$ENV{'PBTMP'}/system.log") if (defined $verbose);
     155    pb_display_file("$ENV{'PBTMP'}/system.log") if ((defined $verbose) && (-f "$ENV{'PBTMP'}/system.log"));
    153156} else {
    154157    pb_log(0, "child ($cmd) exited with value ".($? >> 8)."\n");
    155     pb_display_file("$ENV{'PBTMP'}/system.log");
     158    pb_display_file("$ENV{'PBTMP'}/system.log") if (-f "$ENV{'PBTMP'}/system.log");
    156159}
    157160return($res);
  • devel/pb/bin/pb

    r471 r473  
    2727use ProjectBuilder::Env;
    2828use ProjectBuilder::Filter;
     29use ProjectBuilder::Changelog;
     30
     31use DBI;
    2932
    3033# Global variables
     
    17121715sub pb_announce {
    17131716
    1714     die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
    1715 
    1716     my ($pbrepo) = pb_conf_get("pbrepo");
     1717    # Get all required parameters
     1718    my ($pbpackager,$pbrepo,$pbml) = pb_conf_get("pbpackager","pbrepo","pbml");
    17171719    my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
    17181720    my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
     
    17211723    my $first = 0;
    17221724
     1725    # Command to find packages on repo
    17231726    my $findstr = "find . ";
     1727    # Generated announce files
     1728    my @files;
    17241729
    17251730    foreach my $pbpkg (@pkgs) {
     
    17401745
    17411746        $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver\.ebuild\' ";
     1747
     1748        my $chglog;
     1749
     1750        # Get project info on log file and generate tmp files used later on
     1751        pb_cms_init($pbinit);
     1752        $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
     1753        $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
     1754        $chglog = undef if (! -f $chglog);
     1755
     1756        open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
     1757        pb_changelog("announce",$pbpkg,$pbver,"N/A","N/A","N/A",\*OUT,"yes",$chglog);
     1758        close(OUT);
     1759        push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
    17421760    }
    17431761    $findstr .= " | grep -Ev \'src.rpm\'";
     
    17541772
    17551773    # Prepare a template of announce
    1756     open(ANN,"> $ENV{'PBTMP'}/pbannounce") || die "Unable to create $ENV{'PBTMP'}/pbannounce: $!";
     1774    open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
    17571775    print ANN << "EOF";
    1758 Project $ENV{'PBPROJ'} version $newver is now available</p>
    1759 
    1760 <p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $newver. Enjoy it as usual!</p>
     1776Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available</p>
     1777
     1778<p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $ENV{'PBPROJVER'}. Enjoy it as usual!</p>
    17611779<p>
    17621780Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
     
    17651783EOF
    17661784    open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
     1785    my $col = 2;
     1786    my $i = 1;
     1787    print ANN << 'EOF';
     1788<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
     1789<TR>
     1790EOF
    17671791    while (<LOG>) {
    1768         print ANN $_;
     1792        print ANN "<TD>$_</TD>";
     1793        $i++;
     1794        if ($i > $col) {
     1795            print ANN "</TR>\n<TR>";
     1796            $i = 1;
     1797        }
    17691798    }
    17701799    close(LOG);
    1771 
     1800    print ANN << "EOF";
     1801</TR>
     1802</TABLE>
     1803</p>
     1804
     1805<p>As usual source packages are also available in the same directory.</p>
     1806
     1807<p>
     1808Changes are :
     1809</p>
     1810<p>
     1811EOF
     1812    # Get each package changelog content
     1813    foreach my $f (sort(@files)) {
     1814        open(IN,"$f") || die "Unable to read $f:$!";
     1815        while (<IN>) {
     1816            print ANN $_;
     1817        }
     1818        close(IN);
     1819        print ANN "</p><p>\n";
     1820    }
     1821    print ANN "</p>\n";
    17721822    close(ANN);
    1773     pb_display_file("$ENV{'PBTMP'}/pbannounce");
     1823
     1824    # Allow for modification
     1825    pb_system("vi $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
     1826
     1827    # Store it in DB for external usage (Web pages generation)
     1828    my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
     1829
     1830    my $precmd = "";
     1831    if (! -f $db) {
     1832        $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
     1833    }
     1834
     1835    my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
     1836                        { RaiseError => 1, AutoCommit => 1 })
     1837                        || die "Unable to connect to $db";
     1838
     1839    if ($precmd ne "") {
     1840        my $sth = $dbh->prepare(qq{$precmd})
     1841                    || die "Unable to create table into $db";
     1842        $sth->execute();
     1843    }
     1844
     1845    # To read whole file
     1846    local $/;
     1847    open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
     1848    my $announce = <ANN>;
     1849    close(ANN);
     1850   
     1851    pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
     1852    my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
     1853                    || die "Unable to insert into $db";
     1854    $sth->execute($pbdate, $announce);
     1855    $dbh->disconnect;
     1856
     1857    # Then deliver it on the Web
     1858    # $TOOLHOME/livwww www
     1859
     1860    # Mail it to project's ML
     1861    open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
     1862    print ML << 'EOF';
     1863<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
     1864
     1865<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
     1866  <head>
     1867  </head>
     1868  <body>
     1869  <p>
     1870EOF
     1871    open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
     1872    while(<ANN>) {
     1873        print ML $_;
     1874    }
     1875    print ML << 'EOF';
     1876</body>
     1877</html>
     1878EOF
     1879    close(ML);
     1880
     1881    pb_system("export EMAIL=\'$pbpackager->{$ENV{'PBPROJ'}}\' ; mutt -s \"ANNOUNCE: Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available\" $pbml->{$ENV{'PBPROJ'}} < $ENV{'PBTMP'}/announce.txt","Mailing announce to $pbml->{$ENV{'PBPROJ'}}");
    17741882}
    17751883
  • devel/pb/lib/ProjectBuilder/Changelog.pm

    r415 r473  
    133133$tmp = <INPUT>;
    134134if ($dtype eq "announce") {
    135     print $OUTPUT $tmp;
     135    chomp($tmp);
     136    print $OUTPUT "$tmp<br>\n";
    136137}
    137138$tmp = <INPUT>;
    138139if ($dtype eq "announce") {
    139     print $OUTPUT $tmp;
     140    chomp($tmp);
     141    print $OUTPUT "$tmp<br>\n";
    140142}
    141143
     
    180182            print $OUTPUT "$tmp";
    181183        } else {
    182             print $OUTPUT "$tmp";
     184            chomp($tmp);
     185            print $OUTPUT "$tmp<br>\n";
    183186        }
    184187        last if (eof(INPUT));
  • devel/pb/lib/ProjectBuilder/Filter.pm

    r462 r473  
    166166pb_log(2,"DEBUG: From $f to $destfile\n");
    167167pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    168 open(DEST,"> $destfile") || die "Unable to create $destfile";
     168open(DEST,"> $destfile") || die "Unable to create $destfile: $!";
    169169open(FILE,"$f") || die "Unable to open $f: $!";
    170170while (<FILE>) {
Note: See TracChangeset for help on using the changeset viewer.