summaryrefslogtreecommitdiffstats
path: root/listpackages.pl
blob: c3b9fce1d7f49d61bd43cb162eaffc21038ff044 (plain)
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
#!/usr/bin/perl
#
# listpackages directory [field]
#
# This program spits out a list of all the packages listed in the tasks.
#
# If you go to auric, this command is then useful:
#
# for package in $(listpackages); do
#   madison -s testing -a "i386 all" $package >/dev/null || echo "No $package!"
# done
#
# Or to see just key packages:
#
# listpackages tasks key

my $dir=shift or die "no directory specified\n";
my @toshow=qw{packages-list key};
@toshow=@ARGV if @ARGV;

use File::Find;
find(\&processfile, $dir);

sub processfile {
	my $file=$_; # File::Find craziness.
	$file eq 'po' && -d $file && ($File::Find::prune = 1);
	return if $File::Find::dir=~/\.(svn|git)/;
	return unless $file =~ /^[-+_.a-z0-9]+$/ and -f $file;
	open (IN, $file) or die "$file: $!";
	my %fields;
	my $field="";
	while (<IN>) {
		chomp;
		next if /^\s*#/;
		s/#.*//;

		if (/^\s/) {
			$fields{$field}.="\n$_";
		}
		else {
			($field, my $value)=split(/:\s*/, $_, 2);
			$field=lc($field);
			$fields{$field}=$value;
		}
	}
	close IN;

	my @list;
	push @list, split(' ', $fields{$_}) foreach @toshow;
	print join("\n", @list)."\n" if @list;
}