12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/env python3
- # This script replaces in place.
- import os
- from glob import glob
- import fileinput
- import re
- import sys
- import variables
- path = os.path.join("sugarcube","src")
- filesNames = [y for x in os.walk(path) for y in glob(os.path.join(x[0], '*.tw'))]
- filesNames = ["sugarcube/src/sidebar/Sidebar.tw"]
- for filesName in filesNames:
- print(filesName)
- for line in fileinput.input(filesName, inplace=True):
- output = line
- for variable_replacement in variables.variable_replacements:
- if len(variable_replacement) > 2:
- if variable_replacement[2] == 1:
- output = re.sub(variable_replacement[0],variable_replacement[1],output)
- else:
- output = output.replace(variable_replacement[0],variable_replacement[1])
- else:
- output = output.replace(variable_replacement[0],variable_replacement[1])
- print(output, end='')
- #print(result)
|