Skip to content

Instantly share code, notes, and snippets.

@SebastianBoe
Created March 12, 2018 09:54
Show Gist options
  • Save SebastianBoe/8d36b5b1af0491e5abc8fd598ded976c to your computer and use it in GitHub Desktop.
Save SebastianBoe/8d36b5b1af0491e5abc8fd598ded976c to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/a/6257321/1134134
import os, fnmatch
def findReplace(directory, find, replace, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
s = ""
with open(filepath) as f:
for line in f:
if ("source \"" in line) and ("*" in line):
possibly_modified_line = line.replace('source', 'gsource')
else:
possibly_modified_line = line
s += possibly_modified_line
with open(filepath, "w") as f:
f.write(s)
findReplace(".", "not_in_use", "not_in_use", "*Kconfig*")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment