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