update_characteristics.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. #
  3. # SuperTuxKart - a fun racing game with go-kart
  4. # Copyright (C) 2006-2015 SuperTuxKart-Team
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 3
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. # This script uses create_kart_properties.py to create code and then replaces
  20. # the code in the source files. The parts in the source are marked with tags, that
  21. # contain the argument that has to be passed to create_kart_properties.py.
  22. # The script has to be run from the root directory of this project.
  23. import os
  24. import re
  25. import subprocess
  26. from create_kart_properties import functions
  27. def main():
  28. # Check, if it runs in the root directory
  29. if not os.path.isfile("tools/update_characteristics.py"):
  30. print("Please run this script in the root directory of the project.")
  31. exit(1)
  32. for operation, function in functions.items():
  33. result = subprocess.Popen("tools/create_kart_properties.py " +
  34. operation, shell = True,
  35. stdout = subprocess.PIPE).stdout.read().decode('UTF-8')
  36. with open("src/" + function[2], "r") as f:
  37. text = f.read()
  38. # Replace the text by using look behinds and look forwards
  39. text = re.sub("(?<=/\* \<characteristics-start " + operation +
  40. "\> \*/\\n)(.|\n)*(?=\\n\s*/\* <characteristics-end " + operation + "> \*/)", result, text)
  41. with open("src/" + function[2], "w") as f:
  42. f.write(text)
  43. if __name__ == '__main__':
  44. main()