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