forked from ovh/ovh-ttyrec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-spec-file-changelog-from-debian.pl
executable file
·50 lines (47 loc) · 1.17 KB
/
update-spec-file-changelog-from-debian.pl
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
#! /usr/bin/perl
use strict;
use warnings;
use File::Copy;
my $ver;
my @changes;
my $changelog_fd;
my $oldspec_fd;
my $newspec_fd;
my $first = 1;
open($changelog_fd, '<', 'debian/changelog') or die $!;
open($oldspec_fd, '<', 'ovh-ttyrec.spec') or die $!;
open($newspec_fd, '>', 'ovh-ttyrec.spec.tmp') or die $!;
# first, copy all the old spec contents up to %changelog
while (<$oldspec_fd>) {
print $newspec_fd $_;
if (/^%changelog/) { last; }
}
close($oldspec_fd);
while (<$changelog_fd>) {
if (m{^ovh-ttyrec \(([^)]+)\)}) {
$ver = $1;
}
elsif (m{^ -- (.+)\s+(...), (..) (...) (....)}) {
my ($author,$wday,$day,$month,$year) = ($1,$2,$3,$4,$5);
# from: Thu, 15 Sep 2020 10:59:22 +0200
# to: Wed Nov 04 2020
my $date = "$wday $month $day $year";
if (@changes) { s/^\*/-/ for @changes; }
print $newspec_fd "\n" if $first == 0;
$first = 0;
print $newspec_fd "* $date $author $ver\n";
print $newspec_fd join("\n", @changes);
print $newspec_fd "\n";
undef $ver;
@changes = ();
}
elsif (m{^ (\* .+)}) {
push @changes, $1;
}
elsif (m{^ (.+)}) {
push @changes, $1;
}
}
close($changelog_fd);
close($newspec_fd);
move("ovh-ttyrec.spec.tmp", "ovh-ttyrec.spec");