I needed to add an LGPL copyright statement to all of our 462 Java source code files, in a deep directory tree. You could think about a shell script with same awt magic, but 12 lines of Python also do the job:
[source:python]
import os
copytext=”"”/*
* Copyright (C) 2007
* Author
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This code 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
“”"
for dirpath, dirnames, filenames in os.walk(‘.’):
for name in filenames:
if name.endswith(“.java”):
f=open(dirpath+”\\”+name,”r”)
data=f.read()
f.close()
if data.find(“Copyright”) == -1:
print “Changing ” + name
data=copytext+data
f=open(dirpath+”\\”+name,”w”)
f.write(data)
f.close()
[/source]