Fixed issue with zooms_generator.py match regex.

Applied right prospector arguments.
This commit is contained in:
Kronk 2023-06-24 23:14:50 +02:00 committed by kronk
parent 426c18bfef
commit e44c260430
1 changed files with 14 additions and 15 deletions

View File

@ -1,44 +1,43 @@
import re
from pathlib import Path
version = input("New version = ").strip()
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 = \").*(?=\";)"
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"(?<=<!-- Version ).*(?= -->)"
HTML_MATCH = r"(?<=<!-- Version ).*(?= -->)"
zoom_generator_file = Path("zooms_generator.py")
zoom_generator_match = r"(?<=# Version ).*(?=$)"
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)
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):
replace_version(version, js_file, js_css_match)
replace_version(version, js_file, js_variable_match)
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, css_file, js_css_match)
replace_version(version_input, css_file, JS_CSS_MATCH)
replace_version(version, html_file, html_match)
replace_version(version, demo_high_res_file, html_match)
replace_version(version, demo_low_res_file, html_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, zoom_generator_file, zoom_generator_match)
replace_version(version_input, zoom_generator_file, ZOOM_GENERATOR_MATCH)
print("Done")
else: