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 | blabla
|
---|
41 |
|
---|
42 | =cut
|
---|
43 |
|
---|
44 | sub pb_changelog {
|
---|
45 |
|
---|
46 | my $dtype = shift;
|
---|
47 | my $pkg = shift;
|
---|
48 | my $pbver = shift;
|
---|
49 | my $pbtag = shift;
|
---|
50 | my $dsuf = shift;
|
---|
51 | my $path = shift;
|
---|
52 | my $OUTPUT = shift;
|
---|
53 | my $doit = shift;
|
---|
54 | my $chglog = shift || undef;
|
---|
55 |
|
---|
56 | my $log = "";
|
---|
57 |
|
---|
58 | # For date handling
|
---|
59 | $ENV{LANG}="C";
|
---|
60 |
|
---|
61 | if ((not (defined $dtype)) || ($dtype eq "") ||
|
---|
62 | (not (defined $pkg)) || ($pkg eq "") ||
|
---|
63 | (not (defined $pbver)) || ($pbver eq "") ||
|
---|
64 | (not (defined $pbtag)) || ($pbtag eq "") ||
|
---|
65 | (not (defined $dsuf)) || ($dsuf eq "") ||
|
---|
66 | (not (defined $path)) || ($path eq "") ||
|
---|
67 | (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
|
---|
68 | (not (defined $doit)) || ($doit eq "")) {
|
---|
69 | print $OUTPUT "\n";
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | if (((not defined $chglog) || (! -f $chglog)) && ($doit eq "yes")) {
|
---|
74 | #pb_log(2,"No ChangeLog file ($chglog) for $pkg\n";
|
---|
75 | print $OUTPUT "\n";
|
---|
76 | return;
|
---|
77 | }
|
---|
78 |
|
---|
79 | my $date;
|
---|
80 | my $ndate;
|
---|
81 | my $n2date;
|
---|
82 | my $ver;
|
---|
83 | my $ver2;
|
---|
84 | my ($pbpackager) = pb_conf_get("pbpackager");
|
---|
85 |
|
---|
86 | if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
|
---|
87 | $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
|
---|
88 | }
|
---|
89 |
|
---|
90 | # If we don't need to do it, or don't have it fake something
|
---|
91 | if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
|
---|
92 | my @date = pb_get_date();
|
---|
93 | $date = strftime("%Y-%m-%d", @date);
|
---|
94 | $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
|
---|
95 | $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
|
---|
96 | if (($dtype eq "rpm") || ($dtype eq "fc")) {
|
---|
97 | $ver2 = "$pbver-$pbtag$dsuf";
|
---|
98 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
99 | print $OUTPUT "- Updated to $pbver\n";
|
---|
100 | }
|
---|
101 | if ($dtype eq "deb") {
|
---|
102 | print $OUTPUT "$pkg ($pbver) unstable; urgency=low\n";
|
---|
103 | print $OUTPUT "\n";
|
---|
104 | print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
|
---|
105 | }
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 | open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
|
---|
110 |
|
---|
111 | # Skip first 4 lines
|
---|
112 | my $tmp = <INPUT>;
|
---|
113 | $tmp = <INPUT>;
|
---|
114 | $tmp = <INPUT>;
|
---|
115 | if ($dtype eq "announce") {
|
---|
116 | print $OUTPUT $tmp;
|
---|
117 | }
|
---|
118 | $tmp = <INPUT>;
|
---|
119 | if ($dtype eq "announce") {
|
---|
120 | print $OUTPUT $tmp;
|
---|
121 | }
|
---|
122 |
|
---|
123 | my $first=1;
|
---|
124 |
|
---|
125 | # Handle each block separated by newline
|
---|
126 | while (<INPUT>) {
|
---|
127 | ($ver, $date) = split(/ /);
|
---|
128 | $ver =~ s/^v//;
|
---|
129 | chomp($date);
|
---|
130 | $date =~ s/\(([0-9-]+)\)/$1/;
|
---|
131 | #pb_log(2,"**$date**\n";
|
---|
132 | $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
|
---|
133 | $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
|
---|
134 | #pb_log(2,"**$ndate**\n";
|
---|
135 |
|
---|
136 | if (($dtype eq "rpm") || ($dtype eq "fc")) {
|
---|
137 | if ($ver !~ /-/) {
|
---|
138 | if ($first eq 1) {
|
---|
139 | $ver2 = "$ver-$pbtag$dsuf";
|
---|
140 | $first=0;
|
---|
141 | } else {
|
---|
142 | $ver2 = "$ver-1$dsuf";
|
---|
143 | }
|
---|
144 | } else {
|
---|
145 | $ver2 = "$ver$dsuf";
|
---|
146 | }
|
---|
147 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
148 | print $OUTPUT "- Updated to $ver\n";
|
---|
149 | }
|
---|
150 | if ($dtype eq "deb") {
|
---|
151 | print $OUTPUT "$pkg ($ver) unstable; urgency=low\n";
|
---|
152 | print $OUTPUT "\n";
|
---|
153 | }
|
---|
154 |
|
---|
155 | $tmp = <INPUT>;
|
---|
156 | while ($tmp !~ /^$/) {
|
---|
157 | if ($dtype eq "deb") {
|
---|
158 | $tmp =~ s/^- //;
|
---|
159 | print $OUTPUT " * $tmp";
|
---|
160 | } elsif ($dtype eq "rpm") {
|
---|
161 | print $OUTPUT "$tmp";
|
---|
162 | } else {
|
---|
163 | print $OUTPUT "$tmp";
|
---|
164 | }
|
---|
165 | last if (eof(INPUT));
|
---|
166 | $tmp = <INPUT>;
|
---|
167 | }
|
---|
168 | print $OUTPUT "\n";
|
---|
169 |
|
---|
170 | if ($dtype eq "deb") {
|
---|
171 | # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
|
---|
172 | print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
|
---|
173 | }
|
---|
174 |
|
---|
175 | last if (eof(INPUT));
|
---|
176 | last if ($dtype eq "announce");
|
---|
177 | }
|
---|
178 | close(INPUT);
|
---|
179 | }
|
---|
180 |
|
---|
181 | 1;
|
---|