Repository navigation
Expand file tree
/
Copy pathmake-changelog.py
More file actions
112 lines (93 loc) · 3.79 KB
/
Copy pathmake-changelog.py
File metadata and controls
112 lines (93 loc) · 3.79 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import xml.etree.ElementTree as et
import argparse
import sys
import utils
import datetime
import json
class Changes:
def __init__(self, version, codename, date, changes_list, description):
self.version = version
self.codename = codename
self.date = date
self.changes_list = changes_list
self.description = description
def get_xml_element_content(el):
return "".join(et.tostring(e, encoding="unicode") for e in el)
def get_changes_from_xml(file_path, version, codename):
utils.check_file_existence(file_path)
root = et.parse(file_path).getroot()
version_el = root.find(f'.//release[@version="{version}"]')
if version_el is None:
print(f"Could not find release {version} in {file_path}!")
sys.exit(1)
date = datetime.datetime.strptime(version_el.get("date"), "%Y-%m-%d").date()
description = version_el.find("description")
if description is None:
print(f"Could not find description for release {version} in {file_path}!")
sys.exit(1)
changes = description.findall(f"ul/li")
if changes == []:
print(f"Could not find list of changes for release {version} in {file_path}!")
sys.exit(1)
changes_list = [li.text.strip() for li in changes]
return Changes(
version, codename, date, changes_list, get_xml_element_content(description)
)
def update_app_changelog(file_path, changes):
utils.check_file_existence(file_path)
with open(file_path, "r") as f:
content = f.read()
if f"{changes.version} ---" in content:
print(
f"App changelog already compiled for version {changes.version}, nothing to do"
)
return
changes_txt = f"{changes.version} --- {changes.date.strftime("%Y . %m . %d")}\n"
for change in changes.changes_list:
changes_txt += (
f"- {change.rstrip(";.")}\n" # Remove . and ; characters at the end
)
changes_txt += "\n\n"
with open(file_path, "w") as f:
f.write(changes_txt + content)
def update_web_changelog(file_path, changes):
utils.check_file_existence(file_path)
with open(file_path, "w") as f:
f.write(changes.description)
def update_web_release(file_path, changes):
utils.check_file_existence(file_path)
with open(file_path, "w") as f:
release = {
"version": changes.version,
"codename": changes.codename,
"date": changes.date.strftime("%B %d, %Y"),
}
json.dump(release, f, indent=4)
f.write("\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Changelog generator")
parser.add_argument("--version", help="Version number, e.g. 1.0.0", required=True)
parser.add_argument("--codename", help="Codename, e.g. Jackalope", required=True)
parser.add_argument(
"--giada-app-folder",
help="Path to Giada app folder, e.g ../giada",
required=True,
)
parser.add_argument(
"--giada-www-folder",
help="Path to Giada website folder, e.g ../giada-www",
required=True,
)
args = vars(parser.parse_args())
version = args["version"]
codename = args["codename"]
giada_app_folder = args["giada_app_folder"]
giada_www_folder = args["giada_www_folder"]
source_xml_path = f"{giada_app_folder}/extras/com.giadamusic.Giada.metainfo.xml"
changelog_app_path = f"{giada_app_folder}/ChangeLog"
changelog_web_path = f"{giada_www_folder}/src/data/changes.html"
release_web_path = f"{giada_www_folder}/src/data/release.json"
changes = get_changes_from_xml(source_xml_path, version, codename)
update_app_changelog(changelog_app_path, changes)
update_web_changelog(changelog_web_path, changes)
update_web_release(release_web_path, changes)