-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversion.py
133 lines (111 loc) · 4.57 KB
/
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'''
updates the version numbers in the build files according to our design
simply run the script with the name of the build you wish to increment
and it will increment the version number in the ios/Flutter/Generate.xcconfig
file and the android/local.properties file respective to the specified platform.
once modifications are made to the build files, the script will also save
it locally to the version file.
if you wish to only view the version, simply add no flags
if you wish to increment only the build number, simply add the -b flag
if you wish to increment the patch number and build number, simply add the -p flag
if you wish to increment the minor number and build number, simply add the --minor flag
if you wish to increment the major number and build number, simply add the --major flag
if you wish to specify the entire version, simply add the --set flag
examples:
> python version.py ios
1.4.1+13
> python version.py android
1.0.1+2
> python version.py ios -b
1.4.1+13 -> 1.4.1+14
saved!
> python version.py android -p
1.0.1+2 -> 1.0.2+3
saved!
> python version.py android --minor
1.0.1+3 -> 1.1.0+4
saved!
> python version.py android --set 1.2.3+4
1.1.0+4 -> 1.2.3+4
saved!
'''
def user():
''' if you want to ask the user for input... '''
import argparse
parser = argparse.ArgumentParser()
# parser.add_argument('-o', "--opts",)
parser.add_argument('-b', "--build", default=False,
help="increments the build number")
parser.add_argument('-p', "--patch", default=False,
help="increments the patch number")
parser.add_argument('-n', "--minor", default=False,
help="increments the minor number")
parser.add_argument('-j', "--major", default=False,
help="increments the major number")
args = parser.parse_args()
if args.patch or args.minor or args.major:
args.build = True
# do the thing...
class client_back():
''' if you want to look up the version from the ravencoin repo... '''
def __init__(self):
self.existingVersion = ''
self.existingBuild = ''
self.newVersion = ''
self.newBuild = ''
self.existingVersions = []
self.newVersions = []
self.versionLocation = 'client_back/lib/version.dart'
self.iosLocation = 'client_front/ios/Flutter/Generated.xcconfig'
self.androidLocation = 'client_front/android/local.properties'
def __call__(self):
import json
with open(self.versionLocation, mode='r') as f:
versions = (f
.read()
.split('const VERSIONS = ')[1]
.split(';')[0]
.replace("'", '"'))
with open(self.iosLocation, mode='r') as f:
ios = f.readlines()
with open(self.androidLocation, mode='r') as f:
android = f.readlines()
self.versions = json.loads(versions)
ios = self._replaceValues(
versionName='FLUTTER_BUILD_NAME=',
buildName='FLUTTER_BUILD_NUMBER=',
platformName='ios',
lines=ios)
android = self._replaceValues(
versionName='flutter.versionName=',
buildName='flutter.versionCode=',
platformName='android',
lines=android)
with open(self.iosLocation, mode='w') as f:
f.writelines(ios)
with open(self.androidLocation, mode='w') as f:
f.writelines(android)
for e, n in zip(self.existingVersions, self.newVersions):
print(f'{e} -> {n}')
def _replaceValues(self, versionName, buildName, platformName, lines, version='beta'):
def replacement(x):
if x.startswith(versionName):
self.existingVersion = x.split('=')[1].strip()
self.newVersion = self.versions[platformName][version].split(
'+')[0].split('~')[0]
return versionName + self.newVersion + '\n'
elif x.startswith(buildName):
self.existingBuild = x.split('=')[1].strip()
self.newBuild = self.versions[platformName][version].split(
'+')[1].split('~')[0]
return buildName + self.newBuild + '\n'
else:
return x
items = [replacement(x) for x in lines]
self.existingVersions.append(
self.existingVersion + '+' + self.existingBuild)
self.newVersions.append(self.newVersion + '+' + self.newBuild)
return items
if __name__ == '__main__':
# user()
client_back()()