license-count 5.7 KB

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