fixfiles.py.html CLAWPACK  
 Source file:   fixfiles.py
 Directory:   /Users/rjl/git/rjleveque/clawpack-4.6.3/python
 Converted:   Mon Jan 21 2013 at 20:16:06   using clawcode2html
 This documentation file will not reflect any later changes in the source file.

 

#
# Fix a set of target files in directory tree rootdir by replacing
# oldpat with newpat. 
#
# Now supports wildcards in list of targetfiles.
#

import os,sys,glob

rootdir = '..'
targetfiles = ['README.txt']

oldpat = "http://kingkong.amath.washington.edu/clawpack/users"
newpat = "http://www.clawpack.org/users"

for (dirpath, subdirs, files) in os.walk(rootdir):
    currentdir = os.path.abspath(os.getcwd())
    os.chdir(os.path.abspath(dirpath))
    tfiles = []
    for fpat in targetfiles:
        for f in glob.glob(fpat):
            tfiles.append(f)
    for file in tfiles:

        infile = open(file,'r')
        lines = infile.read()
        infile.close()

        if lines.find(oldpat) > -1:
            lines = lines.replace(oldpat, newpat)
            print "Fixed file   ",dirpath + '/' + file
        else:
            print "No change to ",dirpath + '/' + file

        outfile = open(file,'w')
        outfile.write(lines)
        outfile.close()

    os.chdir(currentdir)