-
Notifications
You must be signed in to change notification settings - Fork 3
/
lib.py
59 lines (42 loc) · 1.31 KB
/
lib.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
#!/usr/local/bin/python3.5
import re
from sys import argv
isFn = lambda fn: hasattr(fn, '__call__')
def call(val, args=None):
return val(args) if isFn(val) else val
def getNextVersion(args):
release = args[-2]
version = APPDATA['version'].split('.')
if release == 'patch':
nnext = str(int(version[-1]) + 1)
version[-1] = nnext
if release == 'minor':
version[-2] = str(int(version[-2]) + 1)
version[-1] = '0'
if release == 'major':
version[-3] = str(int(version[-3]) + 1)
version[-2] = '0'
version[-1] = '0'
return '.'.join(version)
def trace(argv):
print(argv)
def update(args):
version = args[-2]
filename = args[-3]
with open(filename, 'r') as f:
content = f.read()
if filename == 'setup.py':
content = re.sub(r"version = '\d+\.\d+\.\d+'", "version = '{}'".format(version), content)
content = re.sub(r"v\d+\.\d+\.\d+", "v{}".format(version), content)
if filename == 'lib.py':
content = re.sub(r"'version': '\d+\.\d+\.\d+'", "'version': '{}'".format(version), content)
if filename == 'README.md':
content = re.sub(r"# v\d+\.\d+\.\d+", "# v{}".format(version), content)
return content
APPDATA = {
'version': '0.1.5',
'next-version': getNextVersion,
'trace': trace,
'update': update
}
print(call(APPDATA[argv[-1]], argv))