A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.5KB

  1. #!/usr/bin/python3
  2. import argparse
  3. import re
  4. # this assumes a mostly semver-complient version number
  5. if __name__ == "__main__":
  6. parser = argparse.ArgumentParser(description="Increment TechbloxModdingAPI version")
  7. parser.add_argument('version', metavar="VN", type=str, help="The version number to increment, or the index of the number (zero-indexed).")
  8. args = parser.parse_args()
  9. version_index = -1
  10. try:
  11. version_index = int(args.version)
  12. except Exception:
  13. if args.version.lower() == "major":
  14. version_index = 0
  15. elif args.version.lower() == "minor":
  16. version_index = 1
  17. elif args.version.lower() == "patch":
  18. version_index = 2
  19. if version_index < 0:
  20. print("Could not parse version argument.")
  21. exit(version_index)
  22. print(version_index)
  23. old_version = ""
  24. new_version = ""
  25. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "r") as xmlFile:
  26. print("Parsing TechbloxModdingAPI.csproj")
  27. fileStr = xmlFile.read()
  28. versionMatch = re.search(r"<Version>(.+)</Version>", fileStr)
  29. if versionMatch is None:
  30. print("Unable to find version number in TechbloxModdingAPI.csproj")
  31. exit(1)
  32. old_version = versionMatch.group(1)
  33. versionList = old_version.split(".")
  34. if len(versionList) <= version_index:
  35. print("Invalid version string")
  36. exit(1)
  37. versionList[version_index] = str(int(versionList[version_index]) + 1)
  38. for i in range(version_index + 1, len(versionList)):
  39. try:
  40. int(versionList[i])
  41. versionList[i] = "0"
  42. except Exception:
  43. tmp = versionList[i].split("-")
  44. tmp[0] = "0"
  45. versionList[i] = "-".join(tmp)
  46. new_version = ".".join(versionList)
  47. print(new_version)
  48. newFileContents = fileStr.replace("<Version>"+old_version+"</Version>", "<Version>"+new_version+"</Version>")
  49. with open("../TechbloxModdingAPI/TechbloxModdingAPI.csproj", "w") as xmlFile:
  50. print("Writing new version to project file")
  51. xmlFile.write(newFileContents)
  52. with open("../doxygen.conf", "r") as doxFile:
  53. print("Parsing doxygen.conf")
  54. doxStr = doxFile.read()
  55. newFileContents = doxStr.replace("= \"v" + old_version + "\"", "= \"v" + new_version + "\"")
  56. with open("../doxygen.conf", "w") as doxFile:
  57. print("Writing new version to doxygen config")
  58. doxFile.write(newFileContents)