]> git.donarmstrong.com Git - debian/debian-policy.git/blob - tools/license-count
9a56b425433fede5961c90dd69409b25e4eda0e1
[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 use File::Find qw(find);
11
12 our @RULES = (
13     [qr,/usr/share/common-licenses/Apache-2.0,     => 'Apache 2.0'],
14     [qr,/usr/share/common-licenses/Artistic,       => 'Artistic'],
15     [qr,/usr/share/common-licenses/BSD,            => 'BSD (common-licenses)'],
16     [qr,/usr/share/common-licenses/GFDL-1.2,       => 'GFDL 1.2'],
17     [qr,/usr/share/common-licenses/GFDL-1.3,       => 'GFDL 1.3'],
18     [qr,/usr/share/common-licenses/GPL-2,          => 'GPL 2'],
19     [qr,/usr/share/common-licenses/GPL-3,          => 'GPL 3'],
20     [qr,/usr/share/common-licenses/LGPL-2,         => 'LGPL 2'],
21     [qr,/usr/share/common-licenses/LGPL-2.1,       => 'LGPL 2.1'],
22     [qr,/usr/share/common-licenses/LGPL-3,         => 'LGPL 3'],
23
24     [qr,/usr/share/common-licenses/GFDL(?!-),      => 'GFDL (symlink)'],
25     [qr,/usr/share/common-licenses/GPL(?!-),       => 'GPL (symlink)'],
26     [qr,/usr/share/common-licenses/LGPL(?!-),      => 'LGPL (symlink)'],
27
28     [qr,/usr/share/common-licenses/GFDL,           => 'GFDL (any)'],
29     [qr,/usr/share/common-licenses/GPL,            => 'GPL (any)'],
30     [qr,/usr/share/common-licenses/LGPL,           => 'LGPL (any)'],
31
32     [qr,(?m)^License:.*AGPL-3,                     => 'AGPL 3'],
33     [qr,(?m)^License:.*Artistic(?!-),              => 'Artistic'],
34     [qr,(?m)^License:.*Artistic-2,                 => 'Artistic 2.0'],
35     [qr,(?m)^License:.*CC-BY-3.0,                  => 'CC-BY 3.0'],
36     [qr,(?m)^License:.*CC-BY-SA-3.0,               => 'CC-BY-SA 3.0'],
37     [qr,(?m)^License:.*CDDL,                       => 'CDDL'],
38     [qr,(?m)^License:.*GPL-1,                      => 'GPL 1'],
39     [qr,(?m)^License:.*LPPL,                       => 'LaTeX PPL'],
40     [qr,(?m)^License:.*MPL-1\.1,                   => 'MPL 1.1'],
41     [qr,(?m)^License:.*MPL-2\.0,                   => 'MPL 2.0'],
42     [qr,(?m)^License:.*Perl,                       => 'Artistic'],
43     [qr,(?m)^License:.*Perl,                       => 'GPL 1'],
44
45     [qr,GNU AFFERO GENERAL PUBLIC LICENSE\s+Version 3, => 'AGPL 3'],
46     [qr,(?i)The Artistic License 2\.0,             => 'Artistic 2.0'],
47     [qr,COMMON DEVELOPMENT AND DISTRIBUTION LICENSE \(CDDL\), => 'CDDL'],
48     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL(?!-), => 'CeCILL'],
49     [qr,CeCILL FREE SOFTWARE LICENSE AGREEMENT,    => 'CeCILL'],
50     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B, => 'CeCILL-B'],
51     [qr,CeCILL-B FREE SOFTWARE LICENSE AGREEMENT,  => 'CeCILL-B'],
52     [qr,CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-C, => 'CeCILL-C'],
53     [qr,CeCILL-C FREE SOFTWARE LICENSE AGREEMENT,  => 'CeCILL-C'],
54     [qr,(?i)creative\s+commons\s+attribution\s+3\.0, => 'CC-BY 3.0'],
55     [qr,(?i)creative\s+commons\s+attribution[-\s]+share\s*alike\s+3\.0, => 'CC-BY-SA 3.0'],
56     [qr,GNU GENERAL PUBLIC LICENSE\s+Version 1,    => 'GPL 1'],
57     [qr,LPPL Version,                              => 'LaTeX PPL (any)'],
58     [qr,LPPL Version 1\.3a,                        => 'LaTeX PPL 1.3a'],
59     [qr,LPPL Version 1\.3c,                        => 'LaTeX PPL 1.3c'],
60     [qr,MOZILLA PUBLIC LICENSE\s+Version 1\.1,     => 'MPL 1.1'],
61     [qr,Mozilla Public License Version 2\.0,       => 'MPL 2.0'],
62     [qr,SIL OPEN FONT LICENSE Version 1\.1,        => 'SIL OFL 1.1'],
63     [qr,SIL OPEN FONT LICENSE Version 1\.0,        => 'SIL OFL 1.0'],
64 );
65
66 my ($package, %counts);
67 my $n = 0;
68
69 sub check_package {
70     return unless (-d $_ && /_binary$/);
71     $File::Find::prune = 1;
72     return if (-d $_ && /_(source|udeb)$/);
73     $n++;
74     print "Checked $n packages\n" if (($n % 100) == 0);
75     local $/;
76     open (COPYRIGHT, '<', "$_/copyright") or return;
77     my $copyright = <COPYRIGHT>;
78     close COPYRIGHT;
79     my %seen;
80     study $copyright;
81     for my $rule (@RULES) {
82         if ($copyright =~ /$rule->[0]/ && !$seen{$rule->[1]}) {
83             $counts{$rule->[1]}++;
84             $seen{$rule->[1]} = 1;
85         }
86     }
87 }
88
89 unless (@ARGV == 1) {
90     die "Usage: license-count <path-to-lintian-lab>\n";
91 }
92 my $lab = $ARGV[0];
93 find (\&check_package, "$lab/pool");
94 my $length = 0;
95 for my $name (keys %counts) {
96     if (length ($name) > $length) {
97         $length = length ($name);
98     }
99 }
100 for my $name (sort keys %counts) {
101     printf "%-${length}s %5d\n", $name, $counts{$name};
102 }
103 print "\nTotal number of packages: $n\n";