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

Last change on this file since 405 was 405, checked in by Bruno Cornec, 16 years ago

Split again function in modules to allow for usage with pbinit and easier reuse.

  • Property svn:executable set to *
File size: 3.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::Base;
20use ProjectBuilder::Conf;
21
22# Inherit from the "Exporter" module which handles exporting functions.
23
24use Exporter;
25
26# Export, by default, all the functions into the namespace of
27# any code which uses this module.
28
29our @ISA = qw(Exporter);
30our @EXPORT = qw(pb_changelog);
31
32=pod
33
34=head1 NAME
35
36ProjectBuilder::Changelog, part of the project-builder.org - module dealing with changelog management
37
38=head1 DESCRIPTION
39
40blabla
41
42=cut
43
44sub pb_changelog {
45
46my $dtype = shift;
47my $pkg = shift;
48my $pbver = shift;
49my $pbtag = shift;
50my $dsuf = shift;
51my $path = shift;
52my $OUTPUT = shift;
53my $doit = shift;
54my $chglog = shift || undef;
55
56my $log = "";
57
58# For date handling
59$ENV{LANG}="C";
60
61if ((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
73if (((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
79my $date;
80my $ndate;
81my $n2date;
82my $ver;
83my $ver2;
84my ($pbpackager) = pb_conf_get("pbpackager");
85
86if (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
91if (((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
109open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
110
111# Skip first 4 lines
112my $tmp = <INPUT>;
113$tmp = <INPUT>;
114$tmp = <INPUT>;
115if ($dtype eq "announce") {
116 print $OUTPUT $tmp;
117}
118$tmp = <INPUT>;
119if ($dtype eq "announce") {
120 print $OUTPUT $tmp;
121}
122
123my $first=1;
124
125# Handle each block separated by newline
126while (<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}
178close(INPUT);
179}
180
1811;
Note: See TracBrowser for help on using the repository browser.