INNER CODE UNIT · Python
transform_file
wikimedia/apps-android-wikipedia · scripts/bump-version-code.py:52
def transform_file(file_path, *funcs):
"""
Transforms the file given in file_path by passing it
serially through all the functions in *func and then
writing it back out to file_path
"""
with open(file_path, 'r+') as f:
data = f.read()
f.seek(0)
for func in funcs:
data = func(data)
f.write(data)
f.truncate() # Ensure file is properly truncated if new content is shorter
print(file_path)
def bump(file_path):
transform_file(file_path, set_version_code)