

def updateFiles(dirs, map_old2new, counter, suffixes, regex_restrict=None, dry_run=False):
    'iterate through all files in dirs and\n    replace patterns is map_old2new'
    if regex_restrict:
        rx = re.compile(regex_restrict)
    else:
        rx = None
    for d in dirs:
        for (root, dirs, files) in os.walk(d):
            for f in files:
                (_, ext) = os.path.splitext(f)
                if (rx and (not rx.search(ext))):
                    continue
                if (ext not in suffixes):
                    continue
                counter.files_examined += 1
                fn = os.path.join(root, f)
                with IOTools.openFile(fn, 'r') as inf:
                    old_data = inf.read()
                changed = False
                for (old_name, new_name) in map_old2new.items():
                    old_name += '([\'`\\s"=])'
                    new_name += '\\1'
                    new_data = re.sub(old_name, new_name, old_data)
                    if (old_data != new_data):
                        changed = True
                        E.info(('changed: %s : %s to %s' % (fn, old_name, new_name)))
                    old_data = new_data
                if changed:
                    counter.files_changed += 1
                    if (not dry_run):
                        with IOTools.openFile(fn, 'w') as outf:
                            outf.write(new_data)

dataset/ETHPy150Open CGATOxford/cgat/refactor/cgat_refactor.py updateFiles/VarMisuse@107/158 `f`->`ext`