~cjwatson/debconf/dbus

1 by joey
move from cvs import
1
#!/usr/bin/perl
2
# Debconf db validity checker and fixer.
3
4
use strict;
5
use warnings;
6
use Debconf::Db;
7
use Debconf::Template;
8
use Debconf::Question;
9
10
# Load up all questions and templates and put them in hashes for
11
# ease of access.
12
Debconf::Db->load;
13
14
# There is no iterator method in the templates object, so I will do some nasty
15
# hacking to get them all. Oh well. Nothing else needs to iterate templates..
16
my %templates;
17
my $ti=$Debconf::Db::templates->iterator;
18
while (my $t=$ti->iterate) {
19
	$templates{$t}=Debconf::Template->get($t);
20
}
21
22
my %questions;
23
my $qi=Debconf::Question->iterator;
24
while (my $q=$qi->iterate) {
25
        $questions{$q->name}=$q;
26
27
	# I have seen instances where a question would have no associated
28
	# template field. Always a bug.
29
	if (! defined $q->template) {
30
		print STDERR "Warning: question \"".$q->name."\" has no template field.\n"
31
	}
32
}
33
34
# I had a report of a templates db that had templates that claimed to
35
# be owned by their matching questions -- but the questions didn't exist!
36
# Check for such a thing.
37
foreach my $t (keys %templates) {
38
	# Object has no owners method (not otherwise needed), so I'll do 
39
	# some nasty grubbing.
40
	my @owners=$Debconf::Db::templates->owners($t);
41
	foreach my $q (@owners) {
42
		if (! exists $questions{$q}) {
43
			print STDERR "Warning: template \"$t\" claims to be used by nonexistant question \"$q\".\n";
44
		}
45
	}
46
}