Package: devscripts
Severity: normal

While discussing the topic of using cdbs on pkg-multimedia, I found that
there are some interesting bits in cdbs that might have a better home in
the devscripts package. Among others is the licensecheck2dep5 scripts,
which can be found attached. It is driven by this rules in
1/rules/utils.mk, which can be trivially translated to shell or perl

,----[excerpt from 1/rules/utils.mk.in
| debian/stamp-copyright-check:
|       @set -e; if [ ! -f debian/copyright_hints ]; then \
|               echo; \
|               echo '$(if $(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): 
copyright-check disabled - touch debian/copyright_hints to enable.'; \
|               echo; \
|               $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
|       elif [ licensecheck = $(DEB_COPYRIGHT_CHECK_SCRIPT) ] && ! which 
licensecheck > /dev/null; then \
|               echo; \
|               echo '$(if $(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): 
copyright-check disabled - licensecheck (from devscripts package) is missing.'; 
\
|               echo; \
|               $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
|       elif [ licensecheck = $(DEB_COPYRIGHT_CHECK_SCRIPT) ] && ! licensecheck 
--help | grep -qv -- --copyright; then \
|               echo; \
|               echo '$(if $(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): 
copyright-check disabled - licensecheck (from devscripts package) seems older 
than needed 2.10.7.'; \
|               echo; \
|               $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
|       else \
|               echo; \
|               echo 'Scanning upstream source for new/changed copyright 
notices...'; \
|               echo; \
|               echo "$(DEB_COPYRIGHT_CHECK_INVOKE) | 
$(_cdbs_scripts_path)/licensecheck2dep5 > debian/copyright_newhints"; \
|               export LC_ALL=C; \
|               $(DEB_COPYRIGHT_CHECK_INVOKE) | 
$(_cdbs_scripts_path)/licensecheck2dep5 > debian/copyright_newhints; \
|               echo "`grep -c ^Files: debian/copyright_hints` combinations of 
copyright and licensing found."; \
|               newstrings=`diff -a -u debian/copyright_hints 
debian/copyright_newhints | sed '1,2d' | egrep -a '^\+' - | sed 's/^\+//'`; \
|               if [ -n "$$newstrings" ]; then \
|                       echo "$(if 
$(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): The following (and possibly more) 
new or changed notices discovered:"; \
|                       echo; \
|                       echo "$$newstrings" \
|                               | perl -ne '/^.{0,60}$$/ or 
s/^(.{0,60})\b.*$$/$$1…/;s/[^[:print:][:space:]…]//g;$$_ ne $$prev and 
(($$prev) = $$_) and print' \
|                               | sort -m \
|                               | head -n 200; \
|                       echo; \
|                       echo "To fix the situation please do the following:"; \
|                       echo "  1) Fully compare debian/copyright_hints with 
debian/copyright_newhints"; \
|                       echo "  2) Update debian/copyright as needed"; \
|                       echo "  3) Replace debian/copyright_hints with 
debian/copyright_newhints"; \
|                       $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
|               else \
|                       echo 'No new copyright notices found - assuming no news 
is good news...'; \
|               fi; \
|               rm -f debian/copyright_newhints; \
|       fi
|       touch $@
`----

Please consider merging this into the devscripts package.

I also not that an alternate implementation has been posted to this bug,
which I haven't examined yet. This shows that there is (some) common
interest in this functionality.

-- System Information:
Debian Release: squeeze/sid
  APT prefers lucid-updates
  APT policy: (500, 'lucid-updates'), (500, 'lucid')
Architecture: i386 (i686)
#!/usr/bin/perl -w
# -*- mode: cperl; coding: utf-8 -*-
# Copyright © 2005-2010 Jonas Smedegaard <[email protected]>
# Description: Reformat licencecheck output to DEP5 copyright format
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

print "Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?rev=135\n";;
print "X-Draft: Autogenerated by CDBS snippet copyright-check.mk\n\n";
$n=0; while (<>) {
	if (/^([^:\s][^:]+):[\s]+(\S.*?)\s*$/) {
		$files[$n]{name}=$1;
		$files[$n]{license}=$2;
	};
	if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {
		$files[$n]{copyright}=$1;
	};
	/^$/ and $n++;
};
foreach $file (@files) {
	$file->{license} =~ s/\s*\(unversioned\/unknown version\)//;
	$file->{license} =~ s/\s*\(with incorrect FSF address\)//;
	$file->{license} =~ s/\s+\(v([^)]+) or later\)/-$1+/;
	$file->{license} =~ s/\s+\(v([^)]+)\)/-$1/;
	$file->{license} =~ s/\s*(\*No copyright\*)\s*// and $file->{copyright} = $1;
	$file->{license} =~ s/^\s*(GENERATED FILE)/UNKNOWN/;
	$file->{license} =~ s/\s+(GENERATED FILE)//;
	$file->{copyright} =~ s/^&copy;\s*//;
	$file->{copyright} =~ s/(?<=(\b\d{4}))(?{$y=$^N})\s*[,-]\s*((??{$y+1}))\b/-$2/g;
	$file->{copyright} =~ s/(?<=\b\d{4})\s*-\s*\d{4}(?=\s*-\s*(\d{4})\b)//g;
	$file->{copyright} =~ s/\b(\d{4}),?\s+([\S^\d])/$1, $2/g;
	my @ownerlines = grep {/\w\w/} split /\s\/\s/, $file->{copyright};
	my @ownerlines_clean = ();
	my %owneryears = ();
	for $ownerline ( @ownerlines ) {
		my ($owneryear, $owner) = $ownerline =~ /^([\d\-,\s]*)\s*+(.*)/;
		$owner =~ s/^by\s+//;
		$owner =~ s/,?\s+All Rights Reserved\.?//gi;
		push @ownerlines_clean, "$owneryear$owner";
		push @{ $owneryears{"$owner"} }, $owneryear;
	};
	my @owners = sort keys %owneryears;
	my $pattern = join ("\n", $file->{license}, @owners);
	push @{ $patternfiles{"$pattern"} }, $file->{name};
	push @{ $patternownerlines{"$pattern"} }, @ownerlines_clean;
	$patternlicense{"$pattern"} = $file->{license};
};
foreach $pattern ( sort {
			@{$patternfiles{$b}} <=> @{$patternfiles{$a}}
			||
			$a cmp $b
		} keys %patternfiles ) {
	my $prev;
	@ownerlines_unique = grep((!defined $prev || $_ ne $prev) && (($prev) = $_), sort @{ $patternownerlines{$pattern} });
	print "Files: ", join(",\n\t", sort @{ $patternfiles{$pattern} }), "\n";
	print "Copyright: ", join("\n\t", @ownerlines_unique), "\n";
	print "License: $patternlicense{$pattern}\n FIXME\n\n";
};

Reply via email to