X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bin%2Fkeep-latest;h=ebc4fa9d7d048c7c03a002283ace2edf897cbdb4;hb=1fa3e310692f1499af36eb54526f2e23766847d5;hp=c66c41b1200a02a8330ff15287ef0ef871fc82e4;hpb=009aaa975da342fdeaeb7932b95eac0e632e56cb;p=wannabuild.git diff --git a/bin/keep-latest b/bin/keep-latest index c66c41b..ebc4fa9 100755 --- a/bin/keep-latest +++ b/bin/keep-latest @@ -3,44 +3,72 @@ use strict; use warnings; +use lib '/org/wanna-build/lib'; use WannaBuild; # for version compare if (!@ARGV) { - print STDERR "Usage: $0 Packages1 Packages2 ..\n"; + print STDERR "Usage: $0 arch Packages1 Packages2 ..\n"; print STDERR "\n"; print STDERR "This perl scripts reads the Packages files given on the command line and\n"; - print STDERR "outputs a Packages file which contians each package/architecture pair at most\n"; + print STDERR "outputs a Packages file which contians each package at most\n"; print STDERR "once, using the one with the highest version number.\n"; print STDERR ""; print STDERR "Since it only looks at Package:, Version: and Architecture:, it works with\n"; print STDERR "Sources files as well\n"; + print STDERR "\n"; + print STDERR "It throws out any package not arch \"all\" or the given architecture.\n"; + print STDERR "Pass \"source\" to keep all entries.\n"; + exit 1; } my %version; my %data; -local($/) = ""; # read in paragraph mode -while (<>) { - my( $version, $name, $architecture ); - $architecture="none"; # better to keep an entry too much than to delete an entry - /^Package:\s*(\S+)$/mi and $name = $1; - /^Version:\s*(\S+)$/mi and $version = $1; - /^Architecture:\s*(\S+)$/mi and $architecture = $1; - if (!defined $name or !defined $version) { - warn "Stanza without Package or Version\n"; +my $arch = shift @ARGV; + +#Read in all data files: +for my $file (@ARGV) { + if (! -f $file) { next; } - my $key = $name."_".$architecture; + my $fh; + if ($file =~ /.gz$/) { + open($fh, '-|', 'gzip', '-d', '-c', $file) + or die("Can't open pipe from gzip: $!"); + } else { + open($fh, '<', $file) + or die("Can't open $file: $!"); + } + + local($/) = ""; # read in paragraph mode + while (<$fh>) { + my( $version, $name, $architecture ); + $architecture="none"; # better to keep an entry too much than to delete an entry + /^Package:\s*(\S+)$/mi and $name = $1; + /^Version:\s*(\S+)$/mi and $version = $1; + /^Architecture:\s*(\S+)$/mi and $architecture = $1; + if (!defined $name or !defined $version) { + warn "Stanza without Package or Version\n"; + next; + } + if ($arch ne "source" && defined $architecture && $architecture ne "all" && $architecture ne $arch) { + next; + } + my $key = $name; - if ((!exists $version{$key}) or version_less($version{$key},$version)) { - $version{$key} = $version; - $data{$key} = $_; + if ((!exists $version{$key}) or version_less($version{$key},$version)) { + $version{$key} = $version; + $data{$key} = $_; + } } + + close($fh); } +#Now output the shortened list: foreach (values %data) { - s/\n*$/\n\n/;# always one empty line to separate stanzas + chomp; chomp; $_ .= "\n\n"; print; }