-
Notifications
You must be signed in to change notification settings - Fork 7
/
updateVersion.py
47 lines (35 loc) · 1.46 KB
/
updateVersion.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
import os
import argparse
# -------------------------------------------------------------------------------------------------
def updateVersion(currentVersion: str, nextVersion: str):
file = f"{os.path.dirname(os.path.realpath(__file__))}/pygazpar/version.py"
print(f"file={file}")
# read input file
fin = open(file, "rt")
# read file contents to string
data = fin.read()
# replace all occurrences of the required string
data = data.replace(currentVersion, nextVersion)
# close the input file
fin.close()
# open the input file in write mode
fin = open(file, "wt")
# overrite the input file with the resulting data
fin.write(data)
# close the file
fin.close()
# -------------------------------------------------------------------------------------------------
if __name__ == "__main__":
# Execute only if run as a script
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--currentVersion",
required=False,
type=str,
default="0.0.0-initial",
help="Current version number to be replaced in the file version.py")
parser.add_argument("-n", "--nextVersion",
required=True,
type=str,
help="Next version number to place in the file version.py")
args = parser.parse_args()
updateVersion(args.currentVersion, args.nextVersion)