[Koha-patches] [FSF address update 02/33] Add script to replace old FSF address on Temple Street with new one.

Lars Wirzenius lars at catalyst.net.nz
Tue Mar 16 03:30:56 CET 2010


This assumes certain patterns for the paragraph that contains
the FSF's address. It is not a generic tool.
---
 fix-old-fsf-address         |  167 +++++++++++++++++++++++++++++++++++++++++++
 fix-old-fsf-address.exclude |    7 ++
 2 files changed, 174 insertions(+), 0 deletions(-)
 create mode 100755 fix-old-fsf-address
 create mode 100644 fix-old-fsf-address.exclude

diff --git a/fix-old-fsf-address b/fix-old-fsf-address
new file mode 100755
index 0000000..c996287
--- /dev/null
+++ b/fix-old-fsf-address
@@ -0,0 +1,167 @@
+#!/usr/bin/perl
+#
+# Fix GPLv2 license blurbs that have the old FSF address at Temple Street,
+# instead of the Franklin Street one. Files to be fixed are read from
+# stdin. Typical usage would be:
+#
+#   ./find-license-problems . | 
+#   grep -vFx -f fix-old-fsf-address.exclude | 
+#   ./fix-old-fsf-address
+#
+# Copyright 2010 Catalyst IT Ltd
+#
+# This file is part of Koha.
+#
+# 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 of the License, 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+use strict;
+use warnings;
+
+use File::Basename;
+use File::Copy;
+use File::Temp qw/ tempfile /;
+
+
+my $temple = << 'eof';
+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,
+Suite 330, Boston, MA  02111-1307 USA
+eof
+
+my $franklin = << 'eof';
+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, Fifth Floor, Boston, MA 02110-1301 USA.
+eof
+
+
+my $temple2 = << 'eof';
+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,
+Suite 330, Boston, MA  02111-1307 USA
+eof
+
+my $franklin2 = << 'eof';
+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,
+Fifth Floor, Boston, MA 02110-1301 USA.
+eof
+
+
+my $temple3 = << 'eof';
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 50 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+eof
+
+my $franklin3 = << 'eof';
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software Foundation, Inc., 
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+eof
+
+
+my $temple4 = << 'eof';
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+eof
+
+my $franklin4 = << 'eof';
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra.  If not, write to the
+Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, 
+MA 02110-1301 USA.
+eof
+
+
+my @patterns = ($temple, $temple2, $temple3, $temple4);
+my @replacements = ($franklin, $franklin2, $franklin3, $franklin4);
+
+
+sub hashcomment {
+    my ($str) = @_;
+    my @lines = split /\n/, $str;
+    my @result;
+    foreach my $line (@lines) {
+        push @result, "# $line\n";
+    }
+    return join "", @result
+}
+
+
+sub dashcomment {
+    my ($str) = @_;
+    my @lines = split /\n/, $str;
+    my @result;
+    foreach my $line (@lines) {
+        push @result, "-- $line\n";
+    }
+    return join "", @result
+}
+
+
+sub readfile {
+    my ($filename) = @_;
+    open(FILE, $filename) || die("Can't open $filename for reading");
+    my @lines;
+    while (my $line = <FILE>) {
+        push @lines, $line;
+    }
+    close(FILE);
+    return join '', @lines;
+}
+
+
+sub try_to_fix {
+    my ($data, @patterns) = @_;
+    return undef;
+}
+
+
+sub overwrite {
+    my ($filename, $data) = @_;
+    my ($fh, $tempname) = tempfile(DIR => dirname($filename));
+    print $fh $data;
+    close($fh);
+    copy($tempname, $filename);
+    unlink($tempname);
+}
+
+
+sub fix_temple_street {
+    my ($filename) = @_;
+    my $data = readfile($filename);
+    my @pats = map { ($_, hashcomment($_), dashcomment($_)) } @patterns; 
+    my @repls = map { ($_, hashcomment($_), dashcomment($_)) } @replacements;
+    while (@pats) {
+        my $pat = shift @pats;
+        my $repl = shift @repls;
+        my $index = index($data, $pat);
+        next if $index == -1;
+        my $length = length($pat);
+        my $before = substr($data, 0, $index);
+        my $after = substr($data, $index + $length);
+        overwrite($filename, "$before$repl$after");
+        return;
+    }
+    die("Cannot find old address in $filename");
+}
+
+
+while (my $filename = <>) {
+    chomp $filename;
+    fix_temple_street($filename);
+}
diff --git a/fix-old-fsf-address.exclude b/fix-old-fsf-address.exclude
new file mode 100644
index 0000000..6925560
--- /dev/null
+++ b/fix-old-fsf-address.exclude
@@ -0,0 +1,7 @@
+INSTALL.fedora7
+t/smolder_smoke_signal
+misc/cronjobs/check-url.pl
+misc/cronjobs/cloud-kw.pl
+misc/installer_devel_notes/data/en/marcflavour/marc21/mandatory/marc21_framework_DEFAULT.sql
+misc/installer_devel_notes/data/en/marcflavour/marc21/optional/marc21_simple_bib_frameworks.sql
+koha-tmpl/
-- 
1.6.3.3



More information about the Koha-patches mailing list