File make_release.pl of Package winexe

#!/usr/bin/perl -W

use strict;
use POSIX;
use Date::Parse;

my $gitDir = "/lab/winexe/winexe/.git";

sub writeChangelog($) {
	my ($fileName) = @_;

	my $changes = [];
	open IN, "git --git-dir=$gitDir for-each-ref --format='%(refname)/%(taggername) %(taggeremail)/%(taggerdate:rfc2822)/%(contents)' 'refs/tags/*' | tac |";
	while (<IN>) {
		chomp;
		my @s = split(/\//);
		next if $#s < 5;
		my ($version, $who, $date, $details) = @s[2,3,4,5];
		push @$changes, ["winexe", $version, "stable", "low", $details, $who, str2time($date)];
	}
	close IN;
	my ($fn) = @_;
	open IN, "git --git-dir=$gitDir show 0.91~2:source4/winexe/changes |" or die "Cannot open $fn\n";
	while (<IN>) {
		chomp;
		if (/^([0-9.-]+) - (..)\/(..)\/(..) (.*)$/) {
			my ($version, $day, $month, $year, $details) = ($1, $2, $3, $4, $5);
			push @$changes, ["winexe", $version, "stable", "low", $details, "Andrzej Hajda <andrzej.hajda\@wp.pl>", POSIX::mktime(0, 0, 0, $day, $month - 1, 100 + $year)];
		} elsif (/^    (.*)$/) {
			$$changes[$#$changes][4] .= " $1";
		} else {
			print "$_\n";
		}
	}
	close IN;

	open OUT, ">$fileName" or die "Cannot open $fileName\n";
	foreach my $l (@$changes) {
		printf(OUT "$$l[0] ($$l[1]) $$l[2]; urgency=$$l[3]\n  * $$l[4]\n -- $$l[5]  %s\n", strftime("%a, %d %b %Y %H:%M:%S %z", localtime($$l[6])));
	}
	close OUT;
}

sub writeTemplate($$$) {
	my ($template, $file, $vars) = @_;
	system(join("; ", map("$_=$vars->{$_}", sort keys %$vars)) . "; eval \"echo \\\"`cat $template`\\\"\" >$file");
}

my $vars = {};

$_ = `git --git-dir=$gitDir tag | tail -1`;
s/\n//;
m!^[0-9.]+$! or die "Last ref do not contain version number: $_";
$vars->{VERSION} = $_;

$_ = `osc log --csv`;
$vars->{RELEASE} = (() = /\|$vars->{VERSION}\|/g) + 1;

setlocale(LC_ALL, "C");
writeChangelog("debian.changelog");
writeTemplate("winexe.dsc.tpl", "winexe.dsc", $vars);
writeTemplate("winexe.spec.tpl", "winexe.spec", $vars);
system("git --git-dir=$gitDir archive --prefix winexe-$vars->{VERSION}/ $vars->{VERSION} | gzip >winexe-$vars->{VERSION}.tar.gz");
system("osc add winexe-$vars->{VERSION}.tar.gz");
system("EDITOR=mcedit osc commit");
openSUSE Build Service is sponsored by