forked from JohanAnim/Note-diary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
50 lines (39 loc) · 1.7 KB
/
update.py
File metadata and controls
50 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import re
import os
def main():
"""
Función principal para generar el archivo de cambios de la última versión.
"""
try:
# 1. Leer la versión desde buildVars.py
with open("buildVars.py", "r", encoding="utf-8") as f:
content = f.read()
match = re.search(r'addon_version":\s*"([^"]+)"', content)
if not match:
raise ValueError("No se pudo encontrar la versión en buildVars.py")
current_version = match.group(1)
# 2. Leer CHANGELOG.md
with open("CHANGELOG.md", "r", encoding="utf-8") as f:
changelog_content = f.read()
# 3. Extraer los cambios para la versión actual
pattern = re.compile(
r"(##\s+" + re.escape(current_version) + r".*?)(?=##\s+\d|\Z)",
re.DOTALL | re.IGNORECASE
)
match = pattern.search(changelog_content)
if not match:
raise ValueError(f"No se encontraron cambios para la versión {current_version} en CHANGELOG.md")
version_changes = match.group(1).strip()
# 4. Escribir en cambios.txt
output_path = os.path.join("addon", "globalPlugins", "note diary", "cambios.txt")
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "w", encoding="utf-8") as f:
f.write(version_changes)
print(f"Archivo de cambios generado exitosamente para la versión {current_version} en {output_path}")
except FileNotFoundError as e:
print(f"Error: No se encontró el archivo {e.filename}")
except Exception as e:
print(f"Ocurrió un error inesperado: {e}")
if __name__ == "__main__":
main()