mirror of
https://github.com/fmtr/haco.git
synced 2026-10-25 18:40:15 -04:00
29 lines
954 B
Python
29 lines
954 B
Python
import sys
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
PATH_ROOT = Path(__file__).parent.absolute()
|
|
ENCODING = 'UTF-8'
|
|
PATTERN_VERSION = r'(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<pre>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?(?:\+(?P<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?'
|
|
STEMS_MASKS = {
|
|
'berry/haco_version.be': r"var\s+VERSION\s*=\s*'({})'",
|
|
'ha/addon/config.yaml': r"version:\s+({})"
|
|
}
|
|
VERSION = sys.argv[1]
|
|
|
|
|
|
def replacer(match):
|
|
text_new = match.group(0).replace(match.group(1), VERSION)
|
|
return text_new
|
|
|
|
|
|
if __name__ == '__main__':
|
|
for stem, mask in STEMS_MASKS.items():
|
|
path = PATH_ROOT / stem
|
|
text_old = path.read_text(encoding=ENCODING)
|
|
pattern = mask.format(PATTERN_VERSION)
|
|
replacement = pattern.format(VERSION)
|
|
text = re.sub(pattern, replacer, text_old)
|
|
path.write_text(text, encoding=ENCODING)
|
|
print(f'Wrote versions to file: "{path}"')
|