-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinc_version.py
66 lines (55 loc) · 2.21 KB
/
inc_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
import os
import re
# Regex to find string
findVersion: str = "(?<=version =)(.*)"
def inc_version(path: str):
try:
# Save current contents
text: str = ""
version: int = 0
new_version: int = 0
# Check file if exists
#print(f"Checking filepath => {path}")
if os.path.exists(path):
# Read contents
with open(path, "r", encoding='utf-8') as file:
#print("Read file..")
text: str = file.read()
# Iterate over string
for t in text.split('\n'):
if t.startswith("version"):
try:
version = int(t.split("=", 1)[1].strip())
new_version = version + 1
print(f"Version: {version} => {new_version}")
except Exception as ex:
print("Error => {0}: {1}".format(t, ex))
break
# Close file
file.close()
#print("Reading file closed!")
# Update version on file
with open(path, "w", encoding='utf-8') as file:
print("Replacing file contents..")
newText: str = re.sub(findVersion, f" {str(new_version)}", text)
#newText: str = text.replace("com.lagradost.cloudstream3", newAppPackage)
#print("New text => {0}".format(newText))
file.truncate(0)
print("File cleared!")
file.write(newText)
print("Done writing!")
file.close()
print("File closed!")
except Exception as ex:
print("Error => {0}: {1}".format(path, ex))
if __name__ == '__main__':
for name in os.listdir("."):
if os.path.isdir(name):
#print(f"Folder name: {name}")
if name == "Example":
continue
filepath = os.path.join(name, "build.gradle.kts")
if os.path.exists(filepath):
print(f"Gradle exist => {filepath}")
# Replace language to english
inc_version(filepath)