-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_change_log.py
80 lines (62 loc) · 2.01 KB
/
generate_change_log.py
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
#!/usr/bin/python
"""
Script to generate the change log, as well as using regex to change it into a yaml file.
Uses the git remote origin
sudo gem install github_changelog_generator
"""
import os
import sys
import re
change_log_dir = './site/_data/change_log.yml'
def create_yaml():
with open(change_log_dir, 'r') as f:
old_data = f.read()
block_regex = '(?s)##.*?\n\n'
releases = re.findall(block_regex, old_data)
release_regexes = [
('##.*?\[(.*?)\].*', r'\1\n'),
(' \[\\\\.*', ''),
('(v\d\d.*\n)', r'-\n title: \1 notes:'),
# ('\n\- (.)', r'\n - \U\1')
]
data_regexes = [
("([,'\"!?])", ""),
('\\\_', '_'),
('\ntc1-mig.*\n', '\n'),
]
translations = [
('service recipient|sr|recipient', 'Student'),
('service', 'Job'),
('contractor', 'Tutor'),
('appointment|appt|apt', 'Lesson'),
('&', ' ')
]
print('Formatting for YAML')
def upper(match):
return '\n - ' + match.group(1)[0].capitalize()
new_data = []
for release in releases:
for p, r in release_regexes:
release = re.sub(p, r, release)
release = re.sub(r'\n\- (.)', upper, release)
new_data.append(release)
data = ''.join(new_data)
for p, r in data_regexes:
data = re.sub(p, r, data)
print('Creating rough translation')
for p, r in translations:
data = re.sub(p, r, data, flags=re.I)
with open(change_log_dir, 'w') as f:
f.write(data)
def download_data():
command = 'github_changelog_generator tutorcruncher/TutorCruncher2'
os.system(command)
if __name__ == '__main__':
command = sys.argv[-1].lower()
assert command in {'download', 'create', 'all'}, '%s not a valid command: download, create all' % command
if command in {'download', 'all'}:
print('Downloading the change log')
download_data()
if command in {'create', 'all'}:
print('Creating YAML file')
create_yaml()