From 9148279f3d2b5fe2a195528f384d08b8b974b39d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 27 Jan 2011 22:59:58 -0800 Subject: [PATCH] Script to add missing copyright headers on files. --- misc/copyrightifity | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 misc/copyrightifity diff --git a/misc/copyrightifity b/misc/copyrightifity new file mode 100755 index 000000000..3c3c266c9 --- /dev/null +++ b/misc/copyrightifity @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# +# Copyright 2010 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# This script adds copyright headers to files. + +use strict; +my $header = do { local $/; }; +$header =~ s!\s+$!\n!; +my $yyyy = (localtime())[5] + 1900; +$header =~ s/YYYY/$yyyy/ or die; + +unless (@ARGV == 1) { + die "Usage: copyrightify \n"; +} + +my $file = shift; +open(my $fh, $file) or die "Open $file error: $!\n"; +my $source = do { local $/; <$fh> }; +close($fh); +if ($source =~ /Copyright \d\d\d\d/) { + print STDERR "# $file - OK\n"; + exit; +} + +my $newsource = $source; +if ($file =~ /\.go$/) { + $header = "/*\n$header*/\n\n"; + $newsource = $header . $source; +} elsif ($file =~ /\.py$/) { + $header = join("", map { "# $_\n" } split(/\n/, $header)); + $newsource = $header . $source; +} else { + die "File type not supported."; +} + + +open(my $fh, ">$file") or die "Open $file error: $!\n"; +print $fh $newsource; +close($fh) or die; + +__END__ +Copyright YYYY Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.