2023-06-18 17:05:36 +02:00
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
version_input = input("New version = ").strip()
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
js_file = Path("melpomene.js")
|
|
|
|
css_file = Path("melpomene.css")
|
2023-06-24 23:14:50 +02:00
|
|
|
JS_CSS_MATCH = r"(?<=/\* Version ).*(?= \*/)"
|
|
|
|
JS_VARIABLE_MATCH = r"(?<=const MELPOMENE_VERSION = \").*(?=\";)"
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
html_file = Path("melpomene.html")
|
|
|
|
demo_high_res_file = Path("demos/pepper_and_carrot_e35_highres.html")
|
|
|
|
demo_low_res_file = Path("demos/pepper_and_carrot_e35_lowres.html")
|
2023-06-24 23:14:50 +02:00
|
|
|
HTML_MATCH = r"(?<=<!-- Version ).*(?= -->)"
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
zoom_generator_file = Path("zooms_generator.py")
|
2023-06-24 23:14:50 +02:00
|
|
|
ZOOM_GENERATOR_MATCH = r"(?<=# Version ).*(?=$)"
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def replace_version(version, file_path, matcher):
|
|
|
|
with open(file=file_path, mode="r", encoding="UTF8") as file:
|
|
|
|
file_data = file.read()
|
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
file_data = re.sub(matcher, version, file_data, flags=re.MULTILINE)
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
with open(file=file_path, mode="w", encoding="UTF8") as file:
|
|
|
|
file.write(file_data)
|
|
|
|
|
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
if re.match(r"[.a-zA-Z\ \-0-9]{1,30}", version_input):
|
|
|
|
replace_version(version_input, js_file, JS_CSS_MATCH)
|
|
|
|
replace_version(version_input, js_file, JS_VARIABLE_MATCH)
|
2023-06-18 17:05:36 +02:00
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
replace_version(version_input, css_file, JS_CSS_MATCH)
|
2023-06-18 17:05:36 +02:00
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
replace_version(version_input, html_file, HTML_MATCH)
|
|
|
|
replace_version(version_input, demo_high_res_file, HTML_MATCH)
|
|
|
|
replace_version(version_input, demo_low_res_file, HTML_MATCH)
|
2023-06-18 17:05:36 +02:00
|
|
|
|
2023-06-24 23:14:50 +02:00
|
|
|
replace_version(version_input, zoom_generator_file, ZOOM_GENERATOR_MATCH)
|
2023-06-18 17:05:36 +02:00
|
|
|
|
|
|
|
print("Done")
|
|
|
|
else:
|
|
|
|
print("Input is not valid : only use letters, numbers, spaces, dots and dashes")
|