Skip to content

Instantly share code, notes, and snippets.

@omega
Created February 10, 2009 13:00
Show Gist options
  • Save omega/61374 to your computer and use it in GitHub Desktop.
Save omega/61374 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump qw/dump/;
use List::Uniq 'uniq';
my %pkgs;
=pod
{
pkgname =>
'file1 => {
source => 'file1',
version => '0.1-1',
description => 'Something awfull',
name => 'pkgname',
},
'file2' => {
source => 'file2',
version => '0.2-2',
description => 'Something awfull',
name => 'pkgname',
}
]
}
=cut
my $maxlength = 0;
foreach my $filename (@ARGV) {
open my $fh, "<", $filename or die "cannot read $filename: $!";
while (<$fh>) {
last if (/^\+\+\+\-/);
next;
}
# Skipped header now :)
while (<$fh>) {
my ($status, $name, $version, $desc) = split(/\s+/, $_, 4);
$maxlength = length($name) if length($name) > $maxlength;
$pkgs{ $name }->{ $filename } = {
source => $filename,
version => $version,
description => $desc,
name => $name,
};
}
close $fh;
}
my $filecount = scalar(@ARGV);
print "Problem report: \n";
# Try to find all packages that have either different version or only exist in one or the other
foreach my $name (sort keys %pkgs) {
my $versions = $pkgs{$name};
if (scalar(keys(%$versions)) == $filecount) {
# we have the right number of versions
my @vs = uniq( map { $_->{version} } values(%$versions));
next if scalar(@vs) == 1; # only one version, so no diff
report($name => $versions);
} else {
# We have fewer versions than files, so at least one is missing it.
report($name => $versions);
}
}
sub report {
my ($name, $versions) = @_;
print " " . $name . " "x($maxlength - length($name) + 2 ) . ":";
if (scalar(keys(%$versions)) == $filecount) {
foreach my $v (sort { $b->{version} cmp $a->{version} } values %$versions) {
print " " . $v->{source} . " (" . $v->{version} . ")";
}
} else {
print " only in " . dump(keys(%$versions));
}
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment