View | Details | Raw Unified | Return to bug 4330
Collapse All | Expand All

(-)a/misc/code_fixing/find-license-problems.pl (+69 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Find copyright and license problems in Koha source files. At this
4
# time it only looks for references to the old FSF address in GPLv2
5
# license notices, but it might in the future be extended to look for
6
# other things, too.
7
#
8
# Copyright 2010 Catalyst IT Ltd
9
#
10
# This file is part of Koha.
11
#
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2 of the License, or
15
# (at your option) any later version.
16
#
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
# GNU General Public License for more details.
21
#
22
# You should have received a copy of the GNU General Public License along
23
# with this program; if not, write to the Free Software Foundation, Inc.,
24
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26
27
use strict;
28
use warnings;
29
30
use File::Find;
31
32
33
my @files;
34
sub wanted {
35
    my $name = $File::Find::name;
36
    push @files, $name
37
        unless $name =~ /\/(\.git|koha-tmpl)(\/.*)?$/ ||
38
               $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip)$/ ||
39
               ! -f $name;
40
}
41
42
43
sub has_gpl2plus_and_current_fsf_address {
44
    my ($name) = @_;
45
    my $hascopyright;
46
    my $hasgpl;
47
    my $hasv2;
48
    my $hasorlater;
49
    my $hasfranklinst;
50
    open(FILE, $name) || return 0;
51
    while (my $line = <FILE>) {
52
        $hascopyright = 1 if ($line =~ /Copyright.*\d\d/);
53
        $hasgpl = 1 if ($line =~ /GNU General Public License/);
54
        $hasv2 = 1 if ($line =~ /either version 2/);
55
        $hasorlater = 1 if ($line =~ /any later version/ ||
56
                            $line =~ /at your option/);
57
        $hasfranklinst = 1 if ($line =~ /51 Franklin Street/);
58
    }
59
    return ! $hascopyright ||
60
           ($hasgpl && $hasv2 && $hasorlater && $hasfranklinst);
61
}
62
63
64
find({ wanted => \&wanted, no_chdir => 1 }, @ARGV);
65
foreach my $name (@files) {
66
    if (! has_gpl2plus_and_current_fsf_address($name)) {
67
        print "$name\n";
68
    }
69
}
(-)a/misc/code_fixing/fix-old-fsf-address.exclude (+7 lines)
Line 0 Link Here
1
INSTALL.fedora7
2
t/smolder_smoke_signal
3
misc/cronjobs/check-url.pl
4
misc/cronjobs/cloud-kw.pl
5
misc/installer_devel_notes/data/en/marcflavour/marc21/mandatory/marc21_framework_DEFAULT.sql
6
misc/installer_devel_notes/data/en/marcflavour/marc21/optional/marc21_simple_bib_frameworks.sql
7
koha-tmpl/
(-)a/misc/code_fixing/fix-old-fsf-address.pl (+167 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Fix GPLv2 license blurbs that have the old FSF address at Temple Street,
4
# instead of the Franklin Street one. Files to be fixed are read from
5
# stdin. Typical usage would be:
6
#
7
#   ./xt/find-license-problems . | 
8
#   grep -vFx -f ./xt/fix-old-fsf-address.exclude | 
9
#   ./xt/fix-old-fsf-address
10
#
11
# Copyright 2010 Catalyst IT Ltd
12
#
13
# This file is part of Koha.
14
#
15
# This program is free software; you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation; either version 2 of the License, or
18
# (at your option) any later version.
19
#
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
# GNU General Public License for more details.
24
#
25
# You should have received a copy of the GNU General Public License along
26
# with this program; if not, write to the Free Software Foundation, Inc.,
27
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28
29
30
use strict;
31
use warnings;
32
33
use File::Basename;
34
use File::Copy;
35
use File::Temp qw/ tempfile /;
36
37
38
my $temple = << 'eof';
39
You should have received a copy of the GNU General Public License along with
40
Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
41
Suite 330, Boston, MA  02111-1307 USA
42
eof
43
44
my $franklin = << 'eof';
45
You should have received a copy of the GNU General Public License along
46
with Koha; if not, write to the Free Software Foundation, Inc.,
47
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
48
eof
49
50
51
my $temple2 = << 'eof';
52
You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
53
Suite 330, Boston, MA  02111-1307 USA
54
eof
55
56
my $franklin2 = << 'eof';
57
You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
58
Fifth Floor, Boston, MA 02110-1301 USA.
59
eof
60
61
62
my $temple3 = << 'eof';
63
You should have received a copy of the GNU General Public License
64
along with this program; if not, write to the Free Software
65
Foundation, Inc., 50 Temple Place, Suite 330, Boston, MA 02111-1307  USA
66
eof
67
68
my $franklin3 = << 'eof';
69
You should have received a copy of the GNU General Public License
70
along with this program; if not, write to the Free Software Foundation, Inc., 
71
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72
eof
73
74
75
my $temple4 = << 'eof';
76
You should have received a copy of the GNU General Public License
77
along with Zebra; see the file LICENSE.zebra.  If not, write to the
78
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
79
02111-1307, USA.
80
eof
81
82
my $franklin4 = << 'eof';
83
You should have received a copy of the GNU General Public License
84
along with Zebra; see the file LICENSE.zebra.  If not, write to the
85
Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 
86
MA 02110-1301 USA.
87
eof
88
89
90
my @patterns = ($temple, $temple2, $temple3, $temple4);
91
my @replacements = ($franklin, $franklin2, $franklin3, $franklin4);
92
93
94
sub hashcomment {
95
    my ($str) = @_;
96
    my @lines = split /\n/, $str;
97
    my @result;
98
    foreach my $line (@lines) {
99
        push @result, "# $line\n";
100
    }
101
    return join "", @result
102
}
103
104
105
sub dashcomment {
106
    my ($str) = @_;
107
    my @lines = split /\n/, $str;
108
    my @result;
109
    foreach my $line (@lines) {
110
        push @result, "-- $line\n";
111
    }
112
    return join "", @result
113
}
114
115
116
sub readfile {
117
    my ($filename) = @_;
118
    open(FILE, $filename) || die("Can't open $filename for reading");
119
    my @lines;
120
    while (my $line = <FILE>) {
121
        push @lines, $line;
122
    }
123
    close(FILE);
124
    return join '', @lines;
125
}
126
127
128
sub try_to_fix {
129
    my ($data, @patterns) = @_;
130
    return undef;
131
}
132
133
134
sub overwrite {
135
    my ($filename, $data) = @_;
136
    my ($fh, $tempname) = tempfile(DIR => dirname($filename));
137
    print $fh $data;
138
    close($fh);
139
    copy($tempname, $filename);
140
    unlink($tempname);
141
}
142
143
144
sub fix_temple_street {
145
    my ($filename) = @_;
146
    my $data = readfile($filename);
147
    my @pats = map { ($_, hashcomment($_), dashcomment($_)) } @patterns; 
148
    my @repls = map { ($_, hashcomment($_), dashcomment($_)) } @replacements;
149
    while (@pats) {
150
        my $pat = shift @pats;
151
        my $repl = shift @repls;
152
        my $index = index($data, $pat);
153
        next if $index == -1;
154
        my $length = length($pat);
155
        my $before = substr($data, 0, $index);
156
        my $after = substr($data, $index + $length);
157
        overwrite($filename, "$before$repl$after");
158
        return;
159
    }
160
    die("Cannot find old address in $filename");
161
}
162
163
164
while (my $filename = <>) {
165
    chomp $filename;
166
    fix_temple_street($filename);
167
}
(-)a/xt/find-license-problems (-69 lines)
Lines 1-69 Link Here
1
#!/usr/bin/perl
2
#
3
# Find copyright and license problems in Koha source files. At this
4
# time it only looks for references to the old FSF address in GPLv2
5
# license notices, but it might in the future be extended to look for
6
# other things, too.
7
#
8
# Copyright 2010 Catalyst IT Ltd
9
#
10
# This file is part of Koha.
11
#
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2 of the License, or
15
# (at your option) any later version.
16
#
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
# GNU General Public License for more details.
21
#
22
# You should have received a copy of the GNU General Public License along
23
# with this program; if not, write to the Free Software Foundation, Inc.,
24
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26
27
use strict;
28
use warnings;
29
30
use File::Find;
31
32
33
my @files;
34
sub wanted {
35
    my $name = $File::Find::name;
36
    push @files, $name
37
        unless $name =~ /\/(\.git|koha-tmpl)(\/.*)?$/ ||
38
               $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip)$/ ||
39
               ! -f $name;
40
}
41
42
43
sub has_gpl2plus_and_current_fsf_address {
44
    my ($name) = @_;
45
    my $hascopyright;
46
    my $hasgpl;
47
    my $hasv2;
48
    my $hasorlater;
49
    my $hasfranklinst;
50
    open(FILE, $name) || return 0;
51
    while (my $line = <FILE>) {
52
        $hascopyright = 1 if ($line =~ /Copyright.*\d\d/);
53
        $hasgpl = 1 if ($line =~ /GNU General Public License/);
54
        $hasv2 = 1 if ($line =~ /either version 2/);
55
        $hasorlater = 1 if ($line =~ /any later version/ ||
56
                            $line =~ /at your option/);
57
        $hasfranklinst = 1 if ($line =~ /51 Franklin Street/);
58
    }
59
    return ! $hascopyright ||
60
           ($hasgpl && $hasv2 && $hasorlater && $hasfranklinst);
61
}
62
63
64
find({ wanted => \&wanted, no_chdir => 1 }, @ARGV);
65
foreach my $name (@files) {
66
    if (! has_gpl2plus_and_current_fsf_address($name)) {
67
        print "$name\n";
68
    }
69
}
(-)a/xt/fix-old-fsf-address (-167 lines)
Lines 1-167 Link Here
1
#!/usr/bin/perl
2
#
3
# Fix GPLv2 license blurbs that have the old FSF address at Temple Street,
4
# instead of the Franklin Street one. Files to be fixed are read from
5
# stdin. Typical usage would be:
6
#
7
#   ./xt/find-license-problems . | 
8
#   grep -vFx -f ./xt/fix-old-fsf-address.exclude | 
9
#   ./xt/fix-old-fsf-address
10
#
11
# Copyright 2010 Catalyst IT Ltd
12
#
13
# This file is part of Koha.
14
#
15
# This program is free software; you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation; either version 2 of the License, or
18
# (at your option) any later version.
19
#
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
# GNU General Public License for more details.
24
#
25
# You should have received a copy of the GNU General Public License along
26
# with this program; if not, write to the Free Software Foundation, Inc.,
27
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28
29
30
use strict;
31
use warnings;
32
33
use File::Basename;
34
use File::Copy;
35
use File::Temp qw/ tempfile /;
36
37
38
my $temple = << 'eof';
39
You should have received a copy of the GNU General Public License along with
40
Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
41
Suite 330, Boston, MA  02111-1307 USA
42
eof
43
44
my $franklin = << 'eof';
45
You should have received a copy of the GNU General Public License along
46
with Koha; if not, write to the Free Software Foundation, Inc.,
47
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
48
eof
49
50
51
my $temple2 = << 'eof';
52
You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
53
Suite 330, Boston, MA  02111-1307 USA
54
eof
55
56
my $franklin2 = << 'eof';
57
You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
58
Fifth Floor, Boston, MA 02110-1301 USA.
59
eof
60
61
62
my $temple3 = << 'eof';
63
You should have received a copy of the GNU General Public License
64
along with this program; if not, write to the Free Software
65
Foundation, Inc., 50 Temple Place, Suite 330, Boston, MA 02111-1307  USA
66
eof
67
68
my $franklin3 = << 'eof';
69
You should have received a copy of the GNU General Public License
70
along with this program; if not, write to the Free Software Foundation, Inc., 
71
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72
eof
73
74
75
my $temple4 = << 'eof';
76
You should have received a copy of the GNU General Public License
77
along with Zebra; see the file LICENSE.zebra.  If not, write to the
78
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
79
02111-1307, USA.
80
eof
81
82
my $franklin4 = << 'eof';
83
You should have received a copy of the GNU General Public License
84
along with Zebra; see the file LICENSE.zebra.  If not, write to the
85
Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 
86
MA 02110-1301 USA.
87
eof
88
89
90
my @patterns = ($temple, $temple2, $temple3, $temple4);
91
my @replacements = ($franklin, $franklin2, $franklin3, $franklin4);
92
93
94
sub hashcomment {
95
    my ($str) = @_;
96
    my @lines = split /\n/, $str;
97
    my @result;
98
    foreach my $line (@lines) {
99
        push @result, "# $line\n";
100
    }
101
    return join "", @result
102
}
103
104
105
sub dashcomment {
106
    my ($str) = @_;
107
    my @lines = split /\n/, $str;
108
    my @result;
109
    foreach my $line (@lines) {
110
        push @result, "-- $line\n";
111
    }
112
    return join "", @result
113
}
114
115
116
sub readfile {
117
    my ($filename) = @_;
118
    open(FILE, $filename) || die("Can't open $filename for reading");
119
    my @lines;
120
    while (my $line = <FILE>) {
121
        push @lines, $line;
122
    }
123
    close(FILE);
124
    return join '', @lines;
125
}
126
127
128
sub try_to_fix {
129
    my ($data, @patterns) = @_;
130
    return undef;
131
}
132
133
134
sub overwrite {
135
    my ($filename, $data) = @_;
136
    my ($fh, $tempname) = tempfile(DIR => dirname($filename));
137
    print $fh $data;
138
    close($fh);
139
    copy($tempname, $filename);
140
    unlink($tempname);
141
}
142
143
144
sub fix_temple_street {
145
    my ($filename) = @_;
146
    my $data = readfile($filename);
147
    my @pats = map { ($_, hashcomment($_), dashcomment($_)) } @patterns; 
148
    my @repls = map { ($_, hashcomment($_), dashcomment($_)) } @replacements;
149
    while (@pats) {
150
        my $pat = shift @pats;
151
        my $repl = shift @repls;
152
        my $index = index($data, $pat);
153
        next if $index == -1;
154
        my $length = length($pat);
155
        my $before = substr($data, 0, $index);
156
        my $after = substr($data, $index + $length);
157
        overwrite($filename, "$before$repl$after");
158
        return;
159
    }
160
    die("Cannot find old address in $filename");
161
}
162
163
164
while (my $filename = <>) {
165
    chomp $filename;
166
    fix_temple_street($filename);
167
}
(-)a/xt/fix-old-fsf-address.exclude (-8 lines)
Lines 1-7 Link Here
1
INSTALL.fedora7
2
t/smolder_smoke_signal
3
misc/cronjobs/check-url.pl
4
misc/cronjobs/cloud-kw.pl
5
misc/installer_devel_notes/data/en/marcflavour/marc21/mandatory/marc21_framework_DEFAULT.sql
6
misc/installer_devel_notes/data/en/marcflavour/marc21/optional/marc21_simple_bib_frameworks.sql
7
koha-tmpl/
8
- 

Return to bug 4330