-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenversion.py
More file actions
43 lines (36 loc) · 1.08 KB
/
genversion.py
File metadata and controls
43 lines (36 loc) · 1.08 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
import re
from datetime import datetime
key = 'VERSION'
value = '1.0.0'
contents = ''
filePath = "main/__version__.py"
try:
fr = open(filePath, "r")
contents = fr.read()
contents = re.sub(
r'(\"\"\")+[a-zA-Z0-9,. \n:-]+(\"\"\")+[\n ]', "", contents)
contents = contents.replace(" ", "").strip()
fr.close()
except:
pass
fd = open(filePath, "w")
if contents and contents.__contains__('='):
version = contents.split("=")
key = version[0]
version[1] = version[1].strip('\'')
print(f"Last version: {version[1]}")
vParts = version[1].replace('v', '').split('.')
if int(vParts[2]) < 9:
vParts[2] = f"{int(vParts[2])+1}"
else:
vParts[2] = "0"
if int(vParts[1]) < 9:
vParts[1] = f"{int(vParts[1])+1}"
else:
vParts[1] = "0"
vParts[0] = f"{int(vParts[0])+1}"
value = f"{'.'.join(vParts)}"
fd.write(
f"\"\"\"\nThis is an autogenerated file, do not modify manually.\nLast update {datetime.now()}\n\"\"\"\n\n{key} = \'{value}\'")
fd.close()
print(f"New version: {value}")