This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
update_version.py
executable file
·65 lines (53 loc) · 2.2 KB
/
update_version.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
#!/usr/bin/env python3
import re
import argparse
import difflib
from urllib.request import urlopen
parser = argparse.ArgumentParser(
description='Script to update release version on spacewalk webpage. Always check the output!')
parser.add_argument('--version', action='store', required='true', help='For example "2.8"')
parser.add_argument('--config', action='store', help='Specify path to _config.yml', default='_config.yml')
parser.add_argument('--frontpage_header', action='store', help='Specify path to frontpage_header.html',
default='_includes/frontpage_header.html')
args = parser.parse_args()
def diff(old, new):
old = old.splitlines(1)
new = new.splitlines(1)
uni = difflib.unified_diff(old, new)
print(''.join(uni))
def update_config():
with open(args.config, "r") as f:
old = f.read()
new = re.sub("(?<=spacewalk_version: )(.*)", args.version, old)
new = re.sub("(?<=spacewalk_version_short: )(.*)", re.sub("\.", "", args.version), new)
diff(old, new)
answer = input("Please review above patch, does it make sense? [Y/N]: ")
if answer and str.lower(answer) == 'y':
f = open(args.config, 'w')
f.write(new)
f.close()
return
else:
print("Skipping...")
return
def update_release_notes():
with open(args.config, "r") as f:
version = re.search("(?<=spacewalk_version_short: )(.*)", f.read()).group(1)
response = urlopen('https://github.com/spacewalkproject/spacewalk/wiki/ReleaseNotes' + version)
data = response.read().decode('utf-8')
data = re.search("Features & Enhancements in Spacewalk .*?h2>(.*?)<h2>", data, re.DOTALL).group(1)
with open(args.frontpage_header, "r") as f:
old = f.read()
new = re.sub("(?<=release-notes-inner\">).*?(?=<\/div>)", data, old, flags=re.DOTALL)
diff(old, new)
answer = input("Please review above patch, does it make sense? [Y/N]: ")
if answer and str.lower(answer) == 'y':
f = open(args.frontpage_header, 'w')
f.write(new)
f.close()
return
else:
print("Skipping...")
return
update_config()
update_release_notes()