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

Last change on this file since 1192 was 1192, checked in by Bruno Cornec, 13 years ago
  • Fix pb_get_filters to also support filter based on os name and os-ver-arch as well to be coherent, and also fix bugs in the tests made for filter exitence.
  • Fix pb_changelog with test for correct pb hash values which were changed previously
  • Revert back using no arch subdir for deb based repo
  • Introduce new parameter oscmdpath to support external commands full path name easier (could also be very useful for MondoRescue)
  • Another set of fixes for sudo comands support: no parameter taken in account, replace localhost by ALL to avoid nightmares with VMs naming
File size: 5.9 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::Version;
20use ProjectBuilder::Base;
21use ProjectBuilder::Conf;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24
25use vars qw($VERSION $REVISION @ISA @EXPORT);
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);
33($VERSION,$REVISION) = pb_version_init();
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
43This modules provides generic functions suitable for changelog management for project-builder.org
44
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
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.
57
58=cut
59
60sub pb_changelog {
61
62my $pb = shift;
63
64my $dtype = $pb->{'pbos'}->{'type'};
65my $pbrealpkg = $pb->{'realpkg'};
66my $pbver = $pb->{'ver'};
67my $pbtag = $pb->{'tag'};
68my $pbsuf = $pb->{'pbos'}->{'suffix'};
69my $OUTPUT = shift;
70my $doit = shift;
71my $chglog = $pb->{'chglog'} || undef;
72
73my $log = "";
74
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);
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 $pbsuf)) || ($pbsuf eq "") ||
86 (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
87 (not (defined $doit)) || ($doit eq "")) {
88 pb_log(2,"Not enough input params\n");
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
104my @date = pb_get_date();
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")) {
107 pb_log(2,"No ChangeLog file for $pbrealpkg - faking one\n");
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");
111 if ($dtype eq "rpm") {
112 $ver2 = "$pbver-$pbtag";
113 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
114 print $OUTPUT "- Updated to $pbver\n";
115 } elsif ($dtype eq "deb") {
116 if ($pbver !~ /^[0-9]/) {
117 # dpkg-deb doesn't accept non digit versions.
118 # Prepending 0 in order to make updates easy hopefully
119 $pbver =~ s/^/0/;
120 }
121 print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
122 print $OUTPUT " * Updated to $pbver\n";
123 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
124 } else {
125 pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
126 }
127 return;
128}
129
130open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
131
132# Skip first 4 lines
133my $tmp = <INPUT>;
134$tmp = <INPUT>;
135$tmp = <INPUT>;
136if ($dtype eq "announce") {
137 chomp($tmp);
138 print $OUTPUT "$tmp<br>\n";
139}
140$tmp = <INPUT>;
141if ($dtype eq "announce") {
142 chomp($tmp);
143 print $OUTPUT "$tmp<br>\n";
144}
145
146my $first=1;
147
148# Handle each block separated by newline
149while (<INPUT>) {
150 ($ver, $date) = split(/ /);
151 $ver =~ s/^v//;
152 chomp($date);
153 $date =~ s/\(([0-9-]+)\)/$1/;
154 pb_log(3,"**Date:$date**\n");
155 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
156 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
157 pb_log(3,"**nDate:$ndate**\n");
158
159 pb_log(3,"**Ver:$ver**\n");
160 if ($ver !~ /-/) {
161 if ($first eq 1) {
162 $ver2 = "$ver-$pbtag";
163 $first = 0;
164 } else {
165 $ver2 = "$ver-1";
166 }
167 } else {
168 $ver2 = $ver;
169 }
170 pb_log(3,"**Ver2:$ver2**\n");
171
172 if (($dtype eq "rpm") || ($dtype eq "fc")) {
173 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
174 print $OUTPUT "- Updated to $ver\n";
175 }
176 if ($dtype eq "deb") {
177 if ($ver2 !~ /^[0-9]/) {
178 # dpkg-deb doesn't accept non digit versions.
179 # Prepending 0 in order to make updates easy hopefully
180 $ver2 =~ s/^/0/;
181 }
182 print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
183 print $OUTPUT "\n";
184 }
185
186 $tmp = <INPUT>;
187 while ($tmp !~ /^$/) {
188 if ($dtype eq "deb") {
189 $tmp =~ s/^- //;
190 print $OUTPUT " * $tmp";
191 } elsif ($dtype eq "rpm") {
192 print $OUTPUT "$tmp";
193 } else {
194 chomp($tmp);
195 print $OUTPUT "$tmp<br>\n";
196 }
197 last if (eof(INPUT));
198 $tmp = <INPUT>;
199 }
200 print $OUTPUT "\n";
201
202 if ($dtype eq "deb") {
203 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
204 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
205 }
206
207 last if (eof(INPUT));
208 last if ($dtype eq "announce");
209}
210close(INPUT);
211pb_log(2,"Exiting pb_changelog\n");
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.