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

Last change on this file since 544 was 544, checked in by Bruno Cornec, 16 years ago

Still improving debian handling. Final delivery and $made still not completely correct

File size: 5.8 KB
Line 
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);
19use ProjectBuilder::Base;
20use ProjectBuilder::Conf;
21
22# Inherit from the "Exporter" module which handles exporting functions.
23
24use Exporter;
25
26# Export, by default, all the functions into the namespace of
27# any code which uses this module.
28
29our @ISA = qw(Exporter);
30our @EXPORT = qw(pb_changelog);
31
32=pod
33
34=head1 NAME
35
36ProjectBuilder::Changelog, part of the project-builder.org - module dealing with changelog management
37
38=head1 DESCRIPTION
39
40This modules provides generic functions suitable for changelog management for project-builder.org
41
42=head1 USAGE
43
44=over 4
45
46=item B<pb_changelog>
47
48Function that generates the changelog used in build files, or for announcements (web, mailing-list, ...)
49
50It takes up to 9 parameters:
51The first parameter is the type of the distribution.
52The second parameter is the package name generated.
53The third parameter is the version of the package.
54The fourth parameter is the tag of the package.
55The fifth parameter is the suffix of the package.
56The sixth parameter is now unused.
57The seventh parameter is the file descriptor on which to write the changelog content.
58The eighth parameter is a flag in the configuration file indicating whether we want changelog expansion or not.
59The nineth parameter is the potential changelog file pbcl.
60
61=cut
62
63sub pb_changelog {
64
65my $pb = shift;
66my $dtype = $pb->{'dtype'};
67my $pbrealpkg = $pb->{'realpkg'};
68my $pbver = $pb->{'ver'};
69my $pbtag = $pb->{'tag'};
70my $dsuf = $pb->{'suf'};
71my $path = shift;
72my $OUTPUT = shift;
73my $doit = shift;
74my $chglog = $pb->{'chglog'} || undef;
75
76my $log = "";
77
78# For date handling
79$ENV{LANG}="C";
80
81if ((not (defined $dtype)) || ($dtype eq "") ||
82 (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
83 (not (defined $pbver)) || ($pbver eq "") ||
84 (not (defined $pbtag)) || ($pbtag eq "") ||
85 (not (defined $dsuf)) || ($dsuf eq "") ||
86 (not (defined $path)) || ($path eq "") ||
87 (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
88 (not (defined $doit)) || ($doit eq "")) {
89 print $OUTPUT "\n";
90 return;
91}
92
93if (((not defined $chglog) || (! -f $chglog)) && ($doit eq "yes")) {
94 #pb_log(2,"No ChangeLog file ($chglog) for $pbrealpkg\n";
95 print $OUTPUT "\n";
96 return;
97}
98
99my $date;
100my $ndate;
101my $n2date;
102my $ver;
103my $ver2;
104my ($pbpackager) = pb_conf_get("pbpackager");
105
106if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
107 $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
108}
109
110my @date = pb_get_date();
111# If we don't need to do it, or don't have it fake something
112if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
113 $date = strftime("%Y-%m-%d", @date);
114 $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
115 $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
116 if (($dtype eq "rpm") || ($dtype eq "fc")) {
117 $ver2 = "$pbver-$pbtag$dsuf";
118 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
119 print $OUTPUT "- Updated to $pbver\n";
120 }
121 if ($dtype eq "deb") {
122 if ($pbver !~ /^[0-9]/) {
123 # dpkg-deb doesn't accept non digit versions. Prepending date
124 my $ldate = strftime("%Y%m%d", @date);
125 $pbver =~ s/^/$ldate/;
126 }
127 print $OUTPUT "$pbrealpkg ($pbver) unstable; urgency=low\n";
128 print $OUTPUT "\n";
129 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
130 }
131 return;
132}
133
134open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
135
136# Skip first 4 lines
137my $tmp = <INPUT>;
138$tmp = <INPUT>;
139$tmp = <INPUT>;
140if ($dtype eq "announce") {
141 chomp($tmp);
142 print $OUTPUT "$tmp<br>\n";
143}
144$tmp = <INPUT>;
145if ($dtype eq "announce") {
146 chomp($tmp);
147 print $OUTPUT "$tmp<br>\n";
148}
149
150my $first=1;
151
152# Handle each block separated by newline
153while (<INPUT>) {
154 ($ver, $date) = split(/ /);
155 $ver =~ s/^v//;
156 chomp($date);
157 $date =~ s/\(([0-9-]+)\)/$1/;
158 #pb_log(2,"**$date**\n";
159 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
160 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
161 #pb_log(2,"**$ndate**\n";
162
163 if (($dtype eq "rpm") || ($dtype eq "fc")) {
164 if ($ver !~ /-/) {
165 if ($first eq 1) {
166 $ver2 = "$ver-$pbtag$dsuf";
167 $first=0;
168 } else {
169 $ver2 = "$ver-1$dsuf";
170 }
171 } else {
172 $ver2 = "$ver$dsuf";
173 }
174 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
175 print $OUTPUT "- Updated to $ver\n";
176 }
177 if ($dtype eq "deb") {
178 if ($ver !~ /^[0-9]/) {
179 # dpkg-deb doesn't accept non digit versions. Prepending date
180 my $ldate = strftime("%Y%m%d", @date);
181 $ver =~ s/^/$ldate/;
182 }
183 print $OUTPUT "$pbrealpkg ($ver) unstable; urgency=low\n";
184 print $OUTPUT "\n";
185 }
186
187 $tmp = <INPUT>;
188 while ($tmp !~ /^$/) {
189 if ($dtype eq "deb") {
190 $tmp =~ s/^- //;
191 print $OUTPUT " * $tmp";
192 } elsif ($dtype eq "rpm") {
193 print $OUTPUT "$tmp";
194 } else {
195 chomp($tmp);
196 print $OUTPUT "$tmp<br>\n";
197 }
198 last if (eof(INPUT));
199 $tmp = <INPUT>;
200 }
201 print $OUTPUT "\n";
202
203 if ($dtype eq "deb") {
204 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
205 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
206 }
207
208 last if (eof(INPUT));
209 last if ($dtype eq "announce");
210}
211close(INPUT);
212}
213
214
215=back
216
217=head1 WEB SITES
218
219The 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/>.
220
221=head1 USER MAILING LIST
222
223None exists for the moment.
224
225=head1 AUTHORS
226
227The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
228
229=head1 COPYRIGHT
230
231Project-Builder.org is distributed under the GPL v2.0 license
232described in the file C<COPYING> included with the distribution.
233
234=cut
235
2361;
Note: See TracBrowser for help on using the repository browser.