summaryrefslogtreecommitdiffstats
path: root/private/tag-stats
blob: 9aa6696d15f44b851b523c0a9572ac2fa179049b (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

# tag-stats - tag classification statistics
#
# This script displays statistics and data for tag classification based on
# Severity fields and their mapping to a E/W/I code.
#
# The verbose options (-v, -vv, -vvv) can be used to display a detailed list
# of which tags are assigned to each category.

use v5.20;
use warnings;
use utf8;
use autodie qw(opendir closedir);

use Const::Fast;
use Cwd qw(realpath);
use File::Basename qw(dirname);
use Unicode::UTF8 qw(encode_utf8);

# neither Path::This nor lib::relative are in Debian
use constant THISFILE => realpath __FILE__;
use constant THISDIR => dirname realpath __FILE__;

# use Lintian modules that belong to this program
use lib THISDIR . '/../lib';

use Lintian::Profile;
use Lintian::Tag;

const my $SPACE => q{ };
const my $INDENT => $SPACE x 4;
const my $EXTRA_VERBOSE => 3;

$ENV{LINTIAN_BASE} = realpath(THISDIR . '/..')
  // die encode_utf8('Cannot resolve LINTIAN_BASE');

my @severities = reverse qw(pedantic info warning error);
my @types = qw(E W I P);

my %stats;
my $num_tags = 0;
my $num_ok = 0;
my $percent = 0;

my $verbose = $ARGV[0] ? ($ARGV[0] =~ s/v/v/g) : 0;

my $profile = Lintian::Profile->new;
$profile->load;

for my $tag_name ($profile->known_tags) {

    my $tag = $profile->get_tag($tag_name);

    my $name = $tag->name;
    my $severity = $tag->visibility;
    my $code = $tag->code;

    $severity = 'unclassified'
      unless length $severity;

    push(@{$stats{severity}{$severity}}, $name);
    push(@{$stats{type}{severity}{$code}{$severity}}, $name);

    $num_tags++;
}

print encode_utf8("Severity\n");

foreach my $s (@severities) {
    my $tags = $stats{severity}{$s} // [];
    print encode_utf8("  $s: " . @{$tags} . "\n");
    print encode_utf8($INDENT . join("\n    ", sort @{$tags}) . "\n")
      if $verbose >= $EXTRA_VERBOSE;
}

foreach my $t (@types) {
    print encode_utf8("\nType $t Severity\n");
    foreach my $s (@severities) {
        if (my $tags = $stats{type}{severity}{$t}{$s}) {
            print encode_utf8("  $s: " . @{$tags} . "\n");
            print encode_utf8($INDENT . join("\n    ", sort @{$tags}) . "\n")
              if $verbose >= 2;
        }
    }
}

print encode_utf8("\nCollections\n");
foreach my $s (@severities) {
    if (my $needs = $stats{needs}{$s}) {
        my $size = scalar keys %{$needs};
        my @list = sort keys %{$needs};
        print encode_utf8("  $s: $size\n");
        print encode_utf8($INDENT . join("\n    ", @list) . "\n")
          if $verbose >= 2;
    }
}

if ($verbose >= 1 and exists $stats{severity}{unclassified}) {
    print encode_utf8("\nUnclassified tags\n");
    print encode_utf8(
        $SPACE x 2 . join("\n  ", @{$stats{severity}{unclassified}}) . "\n");
}

# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et