-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset_version.py
More file actions
executable file
·60 lines (46 loc) · 1.61 KB
/
set_version.py
File metadata and controls
executable file
·60 lines (46 loc) · 1.61 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
#!/usr/bin/env python3
import sys
# Get script location
VERSION_FILE = './VERSION'
SCRIPT_FILE = './casper-node-util/usr/bin/casper-node-util'
DEBIAN_CONTROL_FILE = './casper-node-util/DEBIAN/control'
def set_version_file(version):
print(f"Updating {VERSION_FILE}")
with open(VERSION_FILE, "w") as f:
f.write(version)
def _line_start_replace(line_start, new_text, file_path):
found = False
with open(file_path, "r") as f:
lines = f.readlines()
with open(file_path, 'w') as f:
for line in lines:
if line.startswith(line_start):
found = True
f.write(f'{new_text}\n')
else:
f.write(line)
if not found:
print(f"WARNING - {file_path} NOT UPDATED - '{line_start}' not found in file")
def set_script_version(version):
print(f"Updating {SCRIPT_FILE}")
line_start = 'VERSION ='
_line_start_replace(line_start,
new_text=f'{line_start} "{version}"',
file_path=SCRIPT_FILE)
def set_control_version(version):
print(f"Updating {DEBIAN_CONTROL_FILE}")
line_start = 'Version:'
_line_start_replace(line_start,
new_text=f"{line_start} {version}",
file_path=DEBIAN_CONTROL_FILE)
def set_version(version):
print(f"setting version '{version}")
set_version_file(version)
set_script_version(version)
set_control_version(version)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("call with version as argument")
exit(0)
version = sys.argv[1]
set_version(version)