forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec2changelog
executable file
·94 lines (84 loc) · 2.92 KB
/
spec2changelog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl
#
# Tiny perl script that parses a .spec file (STDIN), extracts
# its %changelog entries and prints (STDOUT) them in the
# format of a .changes file, ordered.
#
# Usage: cat foo.spec | spec2changes.pl > foo.changes
#
################################################################
#
# Copyright 2009 by Pascal Bleser <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
use warnings;
use strict;
use Date::Language;
use POSIX qw(strftime setlocale LC_ALL);
# make sure date printed in correct locale
$ENV{'TZ'} = 'UTC';
setlocale(LC_ALL, 'C');
my $sep = "-" x 67;
my @days = qw{Mon Tue Wed Thu Fri Sat Sun};
my @months = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
#----------------------------------------------------------------------
#
my %dh = map { $_ => 1 } @days;
my %mh = map { $_ => 1 } @months;
my $date_parser = Date::Language->new('English');
my %items = ();
my $current_block = undef;
my $time = undef;
while (<>) {
if (/^%changelog/ .. eof()) {
next if /^%/;
next if /^\s*#/;
chomp;
s/\s+$//;
if (/^\*\s+(([A-Z][a-z]{2})\s+([A-Z][a-z]{2})\s+\d{1,2}\s+\d{4})(\s+(.*)\s*)$/ and exists $dh{$2} and exists $mh{$3}) {
$items{$time} = $current_block if defined $current_block and defined $time;
$time = $date_parser->str2time($1);
$current_block = [];
$_ = $4;
} elsif (/^\*/) {
warn("not matching a headline: \"$_\"\n");
}
push(@$current_block, $_);
}
}
$items{$time} = $current_block if defined $current_block and defined $time;
foreach my $time (sort { $b <=> $a } (keys(%items))) {
print $sep, "\n";
my $item = $items{$time};
my $head = shift(@$item);
$head =~ s/^\s+//;
$head =~ s/^\-\s+//;
if ($head =~ m/^(.+?)\s*<(.+?\@.+?\..+?)>(\s*.*)$/) {
$head = $2;
} elsif ($head =~ m/^<(.+?\@.+?\..+?)>(\s*.*)$/) {
$head = $1;
}
if ($head =~ m/^\s*-\s*(.+)$/) {
$head = $1;
}
print strftime("%a %b %e %H:%M:%S %Z %Y", localtime($time)), " - ", $head, "\n";
my $first = shift(@$item);
print "\n" unless defined($first) && ($first eq '');
print $first, "\n";
print join("\n", @$item), "\n" if @$item;
print "\n";
}