Added script to update version in headers and variables.
This commit is contained in:
parent
b12cf2c4f1
commit
b3fddef4e0
|
@ -0,0 +1,45 @@
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
version = 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"(?<=<!-- Version ).*(?= -->)"
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
replace_version(version, 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, zoom_generator_file, zoom_generator_match)
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
else:
|
||||||
|
print("Input is not valid : only use letters, numbers, spaces, dots and dashes")
|
Loading…
Reference in New Issue