-
Notifications
You must be signed in to change notification settings - Fork 13
/
update_version.py
executable file
·55 lines (48 loc) · 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
#!/usr/bin/env python
import json
import shutil
import os
nsolidVersion = input("N|Solid Version:\n")
consolePrevious = input("N|Solid Console Previous Image:\n")
runtimePrevious = input("N|Solid Runtime Previous Image:\n")
consoleNew = input("N|Solid Console New Image:\n")
runtimeNew = input("N|Solid Runtime New Image:\n")
print("\n")
# IMAGE-LIST.md update
if "**" + nsolidVersion + "**" in open('IMAGE-LIST.md').read():
with open('IMAGE-LIST.md') as oldfile, open('.IMAGE-LIST.updated.md', 'w') as newfile:
for line in oldfile:
if "**" + nsolidVersion + "**" not in line:
newfile.write(line)
else:
shutil.copyfile('./IMAGE-LIST.md', './.IMAGE-LIST.updated.md')
with open("./.IMAGE-LIST.updated.md", "r") as inFile:
lines = inFile.readlines()
with open("./.IMAGE-LIST.updated.md", "w") as outFile:
for line in lines:
if line.startswith("|----------------|"):
line = (line + "| **" + nsolidVersion + "** "
"| `" + consoleNew + "` "
"| `" + runtimeNew + "` |\n")
outFile.write(line)
amiFile = open("./.IMAGE-LIST.updated.md").read()
with open('IMAGE-LIST.md', 'w') as originalFile:
originalFile.write(amiFile)
os.remove("./.IMAGE-LIST.updated.md")
# Templates update
templates = [os.path.join(dp, f) for dp, dn, fn in os.walk(os.path.expanduser("./templates")) for f in fn]
for template in templates:
if ".md" not in template:
with open(template, "r") as inFile:
lines = inFile.readlines()
with open(template, "w") as outFile:
for line in lines:
if consolePrevious in line:
updatedLine = line.replace(consolePrevious, consoleNew)
outFile.write(updatedLine)
elif runtimePrevious in line:
updatedLine = line.replace(runtimePrevious, runtimeNew)
outFile.write(updatedLine)
else:
outFile.write(line)
print('Update Complete.')