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

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

Working debian packages for virtual/real packages such as for perl modules (pb itself)

File size: 5.5 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
110# If we don't need to do it, or don't have it fake something
111if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
112 my @date = pb_get_date();
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 print $OUTPUT "$pbrealpkg ($pbver) unstable; urgency=low\n";
123 print $OUTPUT "\n";
124 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
125 }
126 return;
127}
128
129open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
130
131# Skip first 4 lines
132my $tmp = <INPUT>;
133$tmp = <INPUT>;
134$tmp = <INPUT>;
135if ($dtype eq "announce") {
136 chomp($tmp);
137 print $OUTPUT "$tmp<br>\n";
138}
139$tmp = <INPUT>;
140if ($dtype eq "announce") {
141 chomp($tmp);
142 print $OUTPUT "$tmp<br>\n";
143}
144
145my $first=1;
146
147# Handle each block separated by newline
148while (<INPUT>) {
149 ($ver, $date) = split(/ /);
150 $ver =~ s/^v//;
151 chomp($date);
152 $date =~ s/\(([0-9-]+)\)/$1/;
153 #pb_log(2,"**$date**\n";
154 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
155 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
156 #pb_log(2,"**$ndate**\n";
157
158 if (($dtype eq "rpm") || ($dtype eq "fc")) {
159 if ($ver !~ /-/) {
160 if ($first eq 1) {
161 $ver2 = "$ver-$pbtag$dsuf";
162 $first=0;
163 } else {
164 $ver2 = "$ver-1$dsuf";
165 }
166 } else {
167 $ver2 = "$ver$dsuf";
168 }
169 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
170 print $OUTPUT "- Updated to $ver\n";
171 }
172 if ($dtype eq "deb") {
173 print $OUTPUT "$pbrealpkg ($ver) unstable; urgency=low\n";
174 print $OUTPUT "\n";
175 }
176
177 $tmp = <INPUT>;
178 while ($tmp !~ /^$/) {
179 if ($dtype eq "deb") {
180 $tmp =~ s/^- //;
181 print $OUTPUT " * $tmp";
182 } elsif ($dtype eq "rpm") {
183 print $OUTPUT "$tmp";
184 } else {
185 chomp($tmp);
186 print $OUTPUT "$tmp<br>\n";
187 }
188 last if (eof(INPUT));
189 $tmp = <INPUT>;
190 }
191 print $OUTPUT "\n";
192
193 if ($dtype eq "deb") {
194 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
195 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
196 }
197
198 last if (eof(INPUT));
199 last if ($dtype eq "announce");
200}
201close(INPUT);
202}
203
204
205=back
206
207=head1 WEB SITES
208
209The 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/>.
210
211=head1 USER MAILING LIST
212
213None exists for the moment.
214
215=head1 AUTHORS
216
217The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
218
219=head1 COPYRIGHT
220
221Project-Builder.org is distributed under the GPL v2.0 license
222described in the file C<COPYING> included with the distribution.
223
224=cut
225
2261;
Note: See TracBrowser for help on using the repository browser.