#!/usr/bin/python import os import re from shutil import move,copymode from tempfile import mkstemp header = """################################################################################ # $Id$ ################################################################################ """ # Ok, really this would probably be quicker to do with ed / sed # But maybe it's just because my python skillz are weaksauce for root, dirs, files in os.walk('/some/dir/nagios-cfg'): # exclude the .svn directories if '.svn' in dirs: dirs.remove('.svn') for name in files: # skip files not ending in .cfg if not re.search('\.cfg$',name): continue filename = os.path.join(root, name) # suck in the original file orig_file = open (filename,'r') orig_str = orig_file.read() orig_file.close # check to make sure $Id$ isn't already there if re.search('# \$Id\$',orig_str): # skip if it is print "$Id$ tag already found in ", filename continue print "Editing ", filename # create a temporary file to add the header to tmpfn = filename+".tmp" tmpfile = open(tmpfn,'w') copymode(filename,tmpfn) # append header and original contents of file to temp file tmpfile.write(header) tmpfile.write(orig_str) tmpfile.close # then copy the file into place move(tmpfn,filename) # and set the keywords properties appropriately os.system("/usr/bin/svn propset svn:keywords \"Author Date Id HeadURL Revision\" "+filename)