makedesc.pl 2.62 KB
Newer Older
Joey Hess's avatar
Joey Hess committed
1 2 3 4 5 6
#!/usr/bin/perl
#
# makedesc directory file
#
# Scan the directory for files, and use the files to generate a task
# description file. The format of the task description file is described in
Joey Hess's avatar
Joey Hess committed
7
# data.c. The format of the input files is:
Joey Hess's avatar
Joey Hess committed
8 9 10 11 12 13 14 15
#
# Task: desktop
# Description: Provide a basic GUI system
#  This task provides functionality for a basic desktop; whether Gnome
#   based, KDE based or customised. With this task, your system will boot
#   into a graphical login screen, at which point you can choose which of
#   these desktops you wish to use on a per-user basis. You can further
#   customise your desktop once installed.
16
# Packages-list:
Joey Hess's avatar
Joey Hess committed
17 18 19 20 21 22 23 24 25
#  kdebase
#  gdm
#  ...
#
# Hash-comments are allowed in the files, but must be on their own lines.

my $dir=shift or die "no directory specified\n";
my $file=shift or die "no file specified\n";

26
my %package;
27
my %notmain;
28 29 30
my $dolint=1;
{
	local $/="\n\n";
31
	if (! open (AVAIL, "apt-cache dumpavail |")) {
Joey Hess's avatar
Joey Hess committed
32
		warn "cannot real available info, so disabling lint check\n";
33 34 35 36 37
		$dolint=0;
	}
	while (<AVAIL>) {
		my ($package)=/Package:\s*(.*?)\n/;
		$package{$package}=1;
38 39 40
		if (/Section:\s*(contrib|non-free)/) {
			$notmain{$package}=$1;
		}
41 42 43 44
	}
	close AVAIL;
}

Joey Hess's avatar
Joey Hess committed
45 46 47
open (OUT, ">$file") or die ">$file: $!";

use File::Find;
48
find({ wanted => \&processfile, preprocess => sub { return sort @_}}, $dir);
Joey Hess's avatar
Joey Hess committed
49 50

sub processfile {
51
	my $file=$_; # File::Find craziness.
52
	$file eq 'po' && -d $file && ($File::Find::prune = 1);
53
	return if $File::Find::dir=~/\.(svn|git)/;
54 55
	return unless $file =~ /^[-+_.a-z0-9]+$/ and -f $file;
	open (IN, $file) or die "$file: $!";
Joey Hess's avatar
Joey Hess committed
56 57 58 59 60
	my %fields;
	my $field="";
	while (<IN>) {
		chomp;
		next if /^\s*#/;
61
		s/#.*//;
Joey Hess's avatar
Joey Hess committed
62 63 64 65 66 67 68 69 70 71 72 73

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

74 75 76 77
	# Basic lint of the listed packages.
	# TODO: a better lint would incloude checks for conflicting
	# packages. Hard tho.
	if ($dolint) {
78
		foreach my $field (qw(key packages-list)) {
79 80 81 82
			foreach (split ' ', $fields{$field}) {
				if (! $package{$_}) {
					print STDERR "$file: $_ is not a valid package.\n";
					if ($field eq 'key') {
83
						print STDERR "MISSING KEY PACKAGE, TASK BROKEN\n";
84 85 86 87
					}
				}
				if ($notmain{$_}) {
					print STDERR "$file: $_ is in $notmain{$_}.\n";
88 89 90
					if ($field eq 'key') {
						print STDERR "MISSING KEY PACKAGE, TASK BROKEN\n";
					}
91
				}
92
			}
93 94 95
		}
	}

96
	foreach (qw{task parent relevance description key enhances provides depends packages section}, 
97
	         grep(/^test-(.*)/, keys %fields)) {
98 99
		print OUT ucfirst($_).": ".$fields{$_}."\n" if length $fields{$_};
	}
Joey Hess's avatar
Joey Hess committed
100 101 102 103
	print OUT "\n";
}

close OUT;