File: licensecheck2dep5

package info (click to toggle)
cdbs 0.4.181
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,008 kB
  • sloc: sh: 4,175; xml: 2,137; perl: 296; makefile: 117; ansic: 7
file content (155 lines) | stat: -rwxr-xr-x 4,414 bytes parent folder | download | duplicates (5)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl -w

use open ':locale';

use Getopt::Long;
use Pod::Usage;

=head1 NAME

licensecheck2dep5 - reformat licencecheck output to copyright file format

=head1 SYNOPSIS

licensecheck2dep5 [B<options>]

=head1 OPTIONS

=over 12

=item B<--help>

Print a brief help message and exits.

=item B<--man>

Prints the manual page and exits.

=item B<--list-delimiter>

String added between each item in whitelist-based lists.

Default value (without quotes): S<"\n ">

=item B<--rfc822-delimiter>

String added between each item in rfc822-based lists.

Default value (without quotes): S<"\n  ">

=item B<--merge-licenses>

Boolean flag to merge Files sections with same license.

Default value: unset

=item B<--strip-suffix>

Suffix stripped from each input filename.

Default value: F<.metadata>

=back

=head1 DESCRIPTION

B<This program> will readfrom B<STDIN>
the output of the B<licensecheck> command
shipped with Debian B<devscript> package,
reformat to Debian copyright format,
and emit to B<STDOUT>.

=cut

my $list_delimiter = $ENV{'whitespace_list_delimiter'} || "\n ";
my $rfc822_delimiter = $ENV{'rfc822_list_delimiter'} || "\n  ";
my $merge_licenses = $ENV{'merge_same_license'} || "";
my $strip_suffix = $ENV{'metadata_suffix'} || ".metadata";

GetOptions( help => \my $help,
	man      => \my $man,
	'list-delimiter' => \$list_delimiter,
	'rfc822-delimiter' => \$rfc822_delimiter,
	'merge-licenses' => \$merge_licenses,
	'strip-suffix' => \$strip_suffix,
) or pod2usage(2);
pod2usage( -verbose => 1 ) if $help;
pod2usage( -verbose => 2, -exitstatus => 0 ) if $man;

print "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n";
print "Upstream-Name: FIXME\n";
print "Upstream-Contact: FIXME\n";
print "Source: FIXME\n";
print "Disclaimer: Autogenerated by CDBS\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->{name} =~ s/([*?\\])/\\$1/g;
	$file->{name} =~ s/$strip_suffix$//g;
	unless ($file->{copyright}) {
		$file->{copyright} = 'NONE';
		$file->{license} =~ s/^\*No copyright\*\s*//;
	}
	$file->{license} =~ s/^generated-file$/UNKNOWN/;
	$file->{license} =~ s/^generated-file or //;
	$file->{license} =~ s/ or generated-file//;
	$file->{copyright} =~ s/(?:(?<=\A)|(?<=\/ ))\d{4}(?:(?:-|, )\d{4})*\K(?= [\S^\d])/,/g;
	my @ownerlines = grep {/\w\w/} split /\s\/\s/, $file->{copyright};
	my @ownerlines_clean = ();
	my %owneryears = ();
	my $owneryears_seem_correct = 1;
	for $ownerline ( @ownerlines ) {
		my ($owneryear, $owner) = $ownerline =~ /^((?:\d{4}(?:(?:-|, )\d{4})*)?) ?((?:\S.*)?)$/;
		$owneryears_seem_correct = 0 unless ($owneryear);
		push @ownerlines_clean, "$owneryear$owner";
		push @{ $owneryears{"$owner"} }, $owneryear;
	};
	my @owners = sort keys %owneryears;
	@owners = () if ($merge_licenses and $owneryears_seem_correct);
	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($list_delimiter, sort @{ $patternfiles{$pattern} }), "\n";
	print "Copyright: ", join($rfc822_delimiter, @ownerlines_unique), "\n";
	print "License: $patternlicense{$pattern}\n FIXME\n\n";
};

=head1 AUTHOR

Jonas Smedegaard, C<< <dr@jones.dk> >>

=head1 LICENSE AND COPYRIGHT

Copyright 2005-2012, 2016-2017 Jonas Smedegaard

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 3, 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/>.

=cut