tw_update.py 976 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # This script replaces in place.
  3. import os
  4. from glob import glob
  5. import fileinput
  6. import re
  7. import sys
  8. import variables
  9. path = os.path.join("sugarcube","src")
  10. filesNames = [y for x in os.walk(path) for y in glob(os.path.join(x[0], '*.tw'))]
  11. filesNames = ["sugarcube/src/sidebar/Sidebar.tw"]
  12. for filesName in filesNames:
  13. print(filesName)
  14. for line in fileinput.input(filesName, inplace=True):
  15. output = line
  16. for variable_replacement in variables.variable_replacements:
  17. if len(variable_replacement) > 2:
  18. if variable_replacement[2] == 1:
  19. output = re.sub(variable_replacement[0],variable_replacement[1],output)
  20. else:
  21. output = output.replace(variable_replacement[0],variable_replacement[1])
  22. else:
  23. output = output.replace(variable_replacement[0],variable_replacement[1])
  24. print(output, end='')
  25. #print(result)