import re from pathlib import Path version_input = input("New version = ").strip() js_file = Path("melpomene.js") css_file = Path("melpomene.css") JS_CSS_MATCH = r"(?<=/\* Version ).*(?= \*/)" JS_VARIABLE_MATCH = r"(?<=const MELPOMENE_VERSION = \").*(?=\";)" 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") HTML_MATCH = r"(?<=)" zoom_generator_file = Path("zooms_generator.py") ZOOM_GENERATOR_MATCH = r"(?<=# Version ).*(?=$)" def replace_version(version, file_path, matcher): with open(file=file_path, mode="r", encoding="UTF8") as file: file_data = file.read() file_data = re.sub(matcher, version, file_data, flags=re.MULTILINE) with open(file=file_path, mode="w", encoding="UTF8") as file: file.write(file_data) 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) replace_version(version_input, css_file, JS_CSS_MATCH) 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) replace_version(version_input, zoom_generator_file, ZOOM_GENERATOR_MATCH) print("Done") else: print("Input is not valid : only use letters, numbers, spaces, dots and dashes")