]> git.donarmstrong.com Git - debian/debian-policy.git/blob - tools/license-count
Merge branch 'master' into bug23712-rra
[debian/debian-policy.git] / tools / license-count
1 #!/usr/bin/perl -w
2 #
3 # This script walks through a Lintian laboratory and counts license usage
4 # based on matching regexes against the contents of the copyright files.  It's
5 # intended to provide a rough estimate of the number of packages using a
6 # particular license when discussing whether to add a license to base-files.
7 #
8 # It expects one argument, which should be the root of the Lintian laboratory.
9
10 our @RULES = (
11     [qr,/usr/share/common-licenses/Apache-2.0,     => 'Apache 2.0'],
12     [qr,/usr/share/common-licenses/Artistic,       => 'Artistic'],
13     [qr,/usr/share/common-licenses/BSD,            => 'BSD (common-licenses)'],
14     [qr,/usr/share/common-licenses/GFDL-1.2,       => 'GFDL 1.2'],
15     [qr,/usr/share/common-licenses/GFDL-1.3,       => 'GFDL 1.3'],
16     [qr,/usr/share/common-licenses/GPL-2,          => 'GPL 2'],
17     [qr,/usr/share/common-licenses/GPL-3,          => 'GPL 3'],
18     [qr,/usr/share/common-licenses/LGPL-2,         => 'LGPL 2'],
19     [qr,/usr/share/common-licenses/LGPL-2.1,       => 'LGPL 2.1'],
20     [qr,/usr/share/common-licenses/LGPL-3,         => 'LGPL 3'],
21
22     [qr,/usr/share/common-licenses/GFDL(?!-),      => 'GFDL (symlink)'],
23     [qr,/usr/share/common-licenses/GPL(?!-),       => 'GPL (symlink)'],
24     [qr,/usr/share/common-licenses/LGPL(?!-),      => 'LGPL (symlink)'],
25
26     [qr,/usr/share/common-licenses/GFDL,           => 'GFDL (any)'],
27     [qr,/usr/share/common-licenses/GPL,            => 'GPL (any)'],
28     [qr,/usr/share/common-licenses/LGPL,           => 'LGPL (any)'],
29
30     [qr,(?m)^License:.*Artistic(?!-),              => 'Artistic'],
31     [qr,(?m)^License:.*Artistic-2,                 => 'Artistic 2.0'],
32     [qr,(?m)^License:.*CC-BY-3.0,                  => 'CC-BY 3.0'],
33     [qr,(?m)^License:.*CC-BY-SA-3.0,               => 'CC-BY-SA 3.0'],
34     [qr,(?m)^License:.*CDDL,                       => 'CDDL'],
35     [qr,(?m)^License:.*GPL-1,                      => 'GPL 1'],
36     [qr,(?m)^License:.*LPPL,                       => 'LaTeX PPL'],
37     [qr,(?m)^License:.*MPL-1\.1,                   => 'MPL 1.1'],
38     [qr,(?m)^License:.*Perl,                       => 'Artistic'],
39     [qr,(?m)^License:.*Perl,                       => 'GPL 1'],
40
41     [qr,(?i)The Artistic License 2\.0,             => 'Artistic 2.0'],
42     [qr,COMMON DEVELOPMENT AND DISTRIBUTION LICENSE \(CDDL\), => 'CDDL'],
43     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL(?!-), => 'CeCILL'],
44     [qr,CeCILL FREE SOFTWARE LICENSE AGREEMENT,    => 'CeCILL'],
45     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B, => 'CeCILL-B'],
46     [qr,CeCILL-B FREE SOFTWARE LICENSE AGREEMENT,  => 'CeCILL-B'],
47     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-C, => 'CeCILL-C'],
48     [qr,CeCILL-C FREE SOFTWARE LICENSE AGREEMENT,  => 'CeCILL-C'],
49     [qr,(?i)creative\s+commons\s+attribution\s+3\.0, => 'CC-BY 3.0'],
50     [qr,(?i)creative\s+commons\s+attribution[-\s]+share\s*alike\s+3\.0, => 'CC-BY-SA 3.0'],
51     [qr,GNU GENERAL PUBLIC LICENSE\s+Version 1,    => 'GPL 1'],
52     [qr,LPPL Version,                              => 'LaTeX PPL (any)'],
53     [qr,LPPL Version 1\.3a,                        => 'LaTeX PPL 1.3a'],
54     [qr,LPPL Version 1\.3c,                        => 'LaTeX PPL 1.3c'],
55     [qr,MOZILLA PUBLIC LICENSE\s+Version 1\.1,     => 'MPL 1.1'],
56     [qr,SIL OPEN FONT LICENSE Version 1\.1,        => 'SIL OFL 1.1'],
57     [qr,SIL OPEN FONT LICENSE Version 1\.0,        => 'SIL OFL 1.0'],
58 );
59
60 unless (@ARGV == 1) {
61     die "Usage: license-count <path-to-lintian-lab>\n";
62 }
63 my $lab = $ARGV[0];
64 opendir (LAB, "$lab/binary") or die "$0: cannot open $lab/binary: $!\n";
65 my ($package, %counts);
66 my $n = 0;
67 while (defined ($package = readdir LAB)) {
68     next if ($package =~ /^\./);
69     $n++;
70     print "Checked $n packages\n" if (($n % 100) == 0);
71     local $/;
72     open (COPYRIGHT, '<', "$lab/binary/$package/copyright") or next;
73     my $copyright = <COPYRIGHT>;
74     close COPYRIGHT;
75     my %seen;
76     study $copyright;
77     for my $rule (@RULES) {
78         if ($copyright =~ /$rule->[0]/ && !$seen{$rule->[1]}) {
79             $counts{$rule->[1]}++;
80             $seen{$rule->[1]} = 1;
81         }
82     }
83 }
84 closedir LAB;
85 my $length = 0;
86 for my $name (keys %counts) {
87     if (length ($name) > $length) {
88         $length = length ($name);
89     }
90 }
91 for my $name (sort keys %counts) {
92     printf "%-${length}s %5d\n", $name, $counts{$name};
93 }
94 print "\nTotal number of packages: $n\n";