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

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