-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_version.py
executable file
·70 lines (52 loc) · 1.55 KB
/
set_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
66
67
68
69
70
#!/usr/bin/env python
import sys, os, codecs
f_script = os.path.realpath(__file__)
d_root = os.path.dirname(f_script)
os.chdir(d_root)
args = sys.argv[1:]
if len(args) < 1:
print("ERROR: must supply version as parameter")
sys.exit(1)
new_version = args[0]
to_update = {
"mod.conf": "version =",
"changelog.txt": "next",
os.path.normpath(".ldoc/config.ld"): "local version =",
}
for f in to_update:
f_path = os.path.join(d_root, f)
if not os.path.isfile(f_path):
print("WARNING: {} not found, skipping ...".format(f))
continue
print("\nsetting version to {} in {}".format(new_version, f_path))
buffer = codecs.open(f_path, "r", "utf-8")
if not buffer:
print("WARNING: could not open {} for reading, skipping ...".format(f))
continue
read_in = buffer.read()
buffer.close()
read_in = read_in.replace("\r\n", "\n").replace("\r", "\n")
replacement = to_update[f]
new_lines = []
version_set = False
for li in read_in.split("\n"):
if not version_set:
if "=" in replacement and li.startswith(replacement):
key = li.split(" = ")[0]
li = "{} = {}".format(key, new_version)
version_set = True
elif li == replacement:
li = "v{}".format(new_version)
version_set = True
new_lines.append(li)
write_out = "\n".join(new_lines)
if write_out == read_in:
print("no changes for {}, skipping ...".format(f))
continue
buffer = codecs.open(f_path, "w", "utf-8")
if not buffer:
print("WARNING: could not open {} for writing, skipping ...".format(f))
continue
buffer.write("\n".join(new_lines))
buffer.close()
print("done")