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 up to 9 parameters:
|
---|
51 | The first parameter is the type of the distribution.
|
---|
52 | The second parameter is the package name generated.
|
---|
53 | The third parameter is the version of the package.
|
---|
54 | The fourth parameter is the tag of the package.
|
---|
55 | The fifth parameter is the suffix of the package.
|
---|
56 | The sixth parameter is now unused.
|
---|
57 | The seventh parameter is the file descriptor on which to write the changelog content.
|
---|
58 | The eighth parameter is a flag in the configuration file indicating whether we want changelog expansion or not.
|
---|
59 | The nineth parameter is the potential changelog file pbcl.
|
---|
60 |
|
---|
61 | =cut
|
---|
62 |
|
---|
63 | sub pb_changelog {
|
---|
64 |
|
---|
65 | my $pb = shift;
|
---|
66 | my $dtype = $pb->{'dtype'};
|
---|
67 | my $pbrealpkg = $pb->{'realpkg'};
|
---|
68 | my $pbver = $pb->{'ver'};
|
---|
69 | my $pbtag = $pb->{'tag'};
|
---|
70 | my $pbsuf = $pb->{'suf'};
|
---|
71 | my $OUTPUT = shift;
|
---|
72 | my $doit = shift;
|
---|
73 | my $chglog = $pb->{'chglog'} || undef;
|
---|
74 |
|
---|
75 | my $log = "";
|
---|
76 |
|
---|
77 | # For date handling
|
---|
78 | $ENV{LANG}="C";
|
---|
79 |
|
---|
80 | if ((not (defined $dtype)) || ($dtype eq "") ||
|
---|
81 | (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
|
---|
82 | (not (defined $pbver)) || ($pbver eq "") ||
|
---|
83 | (not (defined $pbtag)) || ($pbtag eq "") ||
|
---|
84 | (not (defined $pbsuf)) || ($pbsuf eq "") ||
|
---|
85 | (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
|
---|
86 | (not (defined $doit)) || ($doit eq "")) {
|
---|
87 | print $OUTPUT "\n";
|
---|
88 | return;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (((not defined $chglog) || (! -f $chglog)) && ($doit eq "yes")) {
|
---|
92 | #pb_log(2,"No ChangeLog file ($chglog) for $pbrealpkg\n";
|
---|
93 | print $OUTPUT "\n";
|
---|
94 | return;
|
---|
95 | }
|
---|
96 |
|
---|
97 | my $date;
|
---|
98 | my $ndate;
|
---|
99 | my $n2date;
|
---|
100 | my $ver;
|
---|
101 | my $ver2;
|
---|
102 | my ($pbpackager) = pb_conf_get("pbpackager");
|
---|
103 |
|
---|
104 | if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
|
---|
105 | $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
|
---|
106 | }
|
---|
107 |
|
---|
108 | my @date = pb_get_date();
|
---|
109 | # If we don't need to do it, or don't have it fake something
|
---|
110 | if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
|
---|
111 | $date = strftime("%Y-%m-%d", @date);
|
---|
112 | $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
|
---|
113 | $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
|
---|
114 | if (($dtype eq "rpm") || ($dtype eq "fc")) {
|
---|
115 | $ver2 = "$pbver-$pbtag";
|
---|
116 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
117 | print $OUTPUT "- Updated to $pbver\n";
|
---|
118 | }
|
---|
119 | if ($dtype eq "deb") {
|
---|
120 | if ($pbver !~ /^[0-9]/) {
|
---|
121 | # dpkg-deb doesn't accept non digit versions. Prepending date
|
---|
122 | my $ldate = strftime("%Y%m%d", @date);
|
---|
123 | $pbver =~ s/^/$ldate/;
|
---|
124 | }
|
---|
125 | print $OUTPUT "$pbrealpkg ($pbver) unstable; urgency=low\n";
|
---|
126 | print $OUTPUT "\n";
|
---|
127 | print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
|
---|
128 | }
|
---|
129 | return;
|
---|
130 | }
|
---|
131 |
|
---|
132 | open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
|
---|
133 |
|
---|
134 | # Skip first 4 lines
|
---|
135 | my $tmp = <INPUT>;
|
---|
136 | $tmp = <INPUT>;
|
---|
137 | $tmp = <INPUT>;
|
---|
138 | if ($dtype eq "announce") {
|
---|
139 | chomp($tmp);
|
---|
140 | print $OUTPUT "$tmp<br>\n";
|
---|
141 | }
|
---|
142 | $tmp = <INPUT>;
|
---|
143 | if ($dtype eq "announce") {
|
---|
144 | chomp($tmp);
|
---|
145 | print $OUTPUT "$tmp<br>\n";
|
---|
146 | }
|
---|
147 |
|
---|
148 | my $first=1;
|
---|
149 |
|
---|
150 | # Handle each block separated by newline
|
---|
151 | while (<INPUT>) {
|
---|
152 | ($ver, $date) = split(/ /);
|
---|
153 | $ver =~ s/^v//;
|
---|
154 | chomp($date);
|
---|
155 | $date =~ s/\(([0-9-]+)\)/$1/;
|
---|
156 | #pb_log(2,"**$date**\n";
|
---|
157 | $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
|
---|
158 | $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
|
---|
159 | #pb_log(2,"**$ndate**\n";
|
---|
160 |
|
---|
161 | if (($dtype eq "rpm") || ($dtype eq "fc")) {
|
---|
162 | if ($ver !~ /-/) {
|
---|
163 | if ($first eq 1) {
|
---|
164 | $ver2 = "$ver-$pbtag";
|
---|
165 | $first=0;
|
---|
166 | } else {
|
---|
167 | $ver2 = "$ver-1";
|
---|
168 | }
|
---|
169 | } else {
|
---|
170 | $ver2 = "$ver";
|
---|
171 | }
|
---|
172 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
173 | print $OUTPUT "- Updated to $ver\n";
|
---|
174 | }
|
---|
175 | if ($dtype eq "deb") {
|
---|
176 | if ($ver !~ /^[0-9]/) {
|
---|
177 | # dpkg-deb doesn't accept non digit versions. Prepending date
|
---|
178 | my $ldate = strftime("%Y%m%d", @date);
|
---|
179 | $ver =~ s/^/$ldate/;
|
---|
180 | }
|
---|
181 | print $OUTPUT "$pbrealpkg ($ver) 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;
|
---|