source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Changelog.pm@ 1262

Last change on this file since 1262 was 1262, checked in by Bruno Cornec, 13 years ago
  • Fix doc generation for pb.conf.pod
File size: 6.0 KB
RevLine 
[405]1#!/usr/bin/perl -w
2#
3# ProjectBuilder Changelog module
4# Changelog management subroutines brought by the the Project-Builder project
5#
6# $Id$
7#
8# Copyright B. Cornec 2007
9# Provided under the GPL v2
10
11package ProjectBuilder::Changelog;
12
13use strict 'vars';
14use Data::Dumper;
15use English;
16use Date::Manip;
17use POSIX qw(strftime);
18use lib qw (lib);
[1148]19use ProjectBuilder::Version;
[405]20use ProjectBuilder::Base;
21use ProjectBuilder::Conf;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24
[1156]25use vars qw($VERSION $REVISION @ISA @EXPORT);
[405]26use Exporter;
27
28# Export, by default, all the functions into the namespace of
29# any code which uses this module.
30
31our @ISA = qw(Exporter);
32our @EXPORT = qw(pb_changelog);
[1156]33($VERSION,$REVISION) = pb_version_init();
[405]34
35=pod
36
37=head1 NAME
38
39ProjectBuilder::Changelog, part of the project-builder.org - module dealing with changelog management
40
41=head1 DESCRIPTION
42
[409]43This modules provides generic functions suitable for changelog management for project-builder.org
[405]44
[409]45=head1 USAGE
46
47=over 4
48
49=item B<pb_changelog>
50
51Function that generates the changelog used in build files, or for announcements (web, mailing-list, ...)
52
[916]53It takes 3 parameters:
54The first parameter is the %pb hash containing packge info
55The second parameter is the file descriptor on which to write the changelog content.
56The third parameter is a flag in the configuration file indicating whether we want changelog expansion or not.
[409]57
[405]58=cut
59
60sub pb_changelog {
61
[543]62my $pb = shift;
[1192]63
64my $dtype = $pb->{'pbos'}->{'type'};
[543]65my $pbrealpkg = $pb->{'realpkg'};
66my $pbver = $pb->{'ver'};
67my $pbtag = $pb->{'tag'};
[1192]68my $pbsuf = $pb->{'pbos'}->{'suffix'};
[405]69my $OUTPUT = shift;
70my $doit = shift;
[543]71my $chglog = $pb->{'chglog'} || undef;
[405]72
73my $log = "";
74
[1192]75pb_log(2,"Entering pb_changelog - pb: ".Dumper($pb)."\n");
76pb_log(2,"Entering pb_changelog - doit: $doit\n") if (defined $doit);
77pb_log(2,"Entering pb_changelog - OUTPUT: $OUTPUT\n") if (defined $OUTPUT);
[405]78# For date handling
79$ENV{LANG}="C";
80
81if ((not (defined $dtype)) || ($dtype eq "") ||
[543]82 (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
[405]83 (not (defined $pbver)) || ($pbver eq "") ||
84 (not (defined $pbtag)) || ($pbtag eq "") ||
[585]85 (not (defined $pbsuf)) || ($pbsuf eq "") ||
[405]86 (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
87 (not (defined $doit)) || ($doit eq "")) {
[1192]88 pb_log(2,"Not enough input params\n");
[405]89 print $OUTPUT "\n";
90 return;
91}
92
93my $date;
94my $ndate;
95my $n2date;
96my $ver;
97my $ver2;
98my ($pbpackager) = pb_conf_get("pbpackager");
99
100if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
101 $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
102}
103
[544]104my @date = pb_get_date();
[405]105# If we don't need to do it, or don't have it fake something
106if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
[1192]107 pb_log(2,"No ChangeLog file for $pbrealpkg - faking one\n");
[405]108 $date = strftime("%Y-%m-%d", @date);
109 $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
110 $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
[1192]111 if ($dtype eq "rpm") {
[642]112 $ver2 = "$pbver-$pbtag";
[405]113 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
114 print $OUTPUT "- Updated to $pbver\n";
[1192]115 } elsif ($dtype eq "deb") {
[544]116 if ($pbver !~ /^[0-9]/) {
[916]117 # dpkg-deb doesn't accept non digit versions.
118 # Prepending 0 in order to make updates easy hopefully
119 $pbver =~ s/^/0/;
[544]120 }
[916]121 print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
122 print $OUTPUT " * Updated to $pbver\n";
[405]123 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
[1192]124 } else {
125 pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
126 }
[405]127 return;
128}
129
[1262]130die "No changelog file for $pbrealpkg found at $ENV{'PBROOTDIR'}/$pbrealpkg/pbcl" if (not defined $chglog);
[1261]131
[405]132open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
133
134# Skip first 4 lines
135my $tmp = <INPUT>;
136$tmp = <INPUT>;
137$tmp = <INPUT>;
138if ($dtype eq "announce") {
[473]139 chomp($tmp);
140 print $OUTPUT "$tmp<br>\n";
[405]141}
142$tmp = <INPUT>;
143if ($dtype eq "announce") {
[473]144 chomp($tmp);
145 print $OUTPUT "$tmp<br>\n";
[405]146}
147
148my $first=1;
149
150# Handle each block separated by newline
151while (<INPUT>) {
152 ($ver, $date) = split(/ /);
153 $ver =~ s/^v//;
154 chomp($date);
155 $date =~ s/\(([0-9-]+)\)/$1/;
[916]156 pb_log(3,"**Date:$date**\n");
[405]157 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
158 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
[916]159 pb_log(3,"**nDate:$ndate**\n");
[405]160
[916]161 pb_log(3,"**Ver:$ver**\n");
162 if ($ver !~ /-/) {
163 if ($first eq 1) {
164 $ver2 = "$ver-$pbtag";
165 $first = 0;
[405]166 } else {
[916]167 $ver2 = "$ver-1";
[405]168 }
[916]169 } else {
170 $ver2 = $ver;
171 }
172 pb_log(3,"**Ver2:$ver2**\n");
173
174 if (($dtype eq "rpm") || ($dtype eq "fc")) {
[405]175 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
176 print $OUTPUT "- Updated to $ver\n";
177 }
178 if ($dtype eq "deb") {
[916]179 if ($ver2 !~ /^[0-9]/) {
180 # dpkg-deb doesn't accept non digit versions.
181 # Prepending 0 in order to make updates easy hopefully
182 $ver2 =~ s/^/0/;
[544]183 }
[916]184 print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
[405]185 print $OUTPUT "\n";
186 }
187
188 $tmp = <INPUT>;
189 while ($tmp !~ /^$/) {
190 if ($dtype eq "deb") {
191 $tmp =~ s/^- //;
192 print $OUTPUT " * $tmp";
193 } elsif ($dtype eq "rpm") {
194 print $OUTPUT "$tmp";
195 } else {
[473]196 chomp($tmp);
197 print $OUTPUT "$tmp<br>\n";
[405]198 }
199 last if (eof(INPUT));
200 $tmp = <INPUT>;
201 }
202 print $OUTPUT "\n";
203
204 if ($dtype eq "deb") {
205 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
206 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
207 }
208
209 last if (eof(INPUT));
210 last if ($dtype eq "announce");
211}
212close(INPUT);
[1192]213pb_log(2,"Exiting pb_changelog\n");
[405]214}
215
[409]216
217=back
218
219=head1 WEB SITES
220
221The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
222
223=head1 USER MAILING LIST
224
225None exists for the moment.
226
227=head1 AUTHORS
228
229The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
230
231=head1 COPYRIGHT
232
233Project-Builder.org is distributed under the GPL v2.0 license
234described in the file C<COPYING> included with the distribution.
235
236=cut
237
[405]2381;
Note: See TracBrowser for help on using the repository browser.