speckle-sketchup/patch_version.py

53 строки
1.3 KiB
Python
Исходник Постоянная ссылка Обычный вид История

2021-11-05 20:35:23 +03:00
import re
import sys
def patch_connector(tag):
"""Patches the connector version within the connector file"""
rb_file = "speckle_connector.rb"
with open(rb_file, "r") as file:
lines = file.readlines()
for (index, line) in enumerate(lines):
if 'CONNECTOR_VERSION = ' in line:
lines[index] = f' CONNECTOR_VERSION = "{tag}"\n'
print(f"Patched connector version number in {rb_file}")
break
with open(rb_file, "w") as file:
file.writelines(lines)
def patch_installer(tag):
"""Patches the installer with the correct connector version"""
iss_file = "speckle-sharp-ci-tools/sketchup.iss"
with open(iss_file, "r") as file:
lines = file.readlines()
2022-06-21 15:10:31 +03:00
lines.insert(11, f'#define AppVersion "{tag.split("-")[0]}"\n')
lines.insert(12, f'#define AppInfoVersion "{tag}"\n')
2021-11-05 20:35:23 +03:00
with open(iss_file, "w") as file:
file.writelines(lines)
print(f"Patched installer with connector v{tag}")
def main():
if len(sys.argv) < 2:
return
tag = sys.argv[1]
2022-06-21 15:02:23 +03:00
if not re.match(r"([0-9]+)\.([0-9]+)\.([0-9]+)", tag):
2021-11-05 20:35:23 +03:00
raise ValueError(f"Invalid tag provided: {tag}")
print(f"Patching version: {tag}")
patch_connector(tag)
patch_installer(tag)
if __name__ == "__main__":
main()