-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_version.py
More file actions
executable file
·73 lines (52 loc) · 1.87 KB
/
bump_version.py
File metadata and controls
executable file
·73 lines (52 loc) · 1.87 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
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
#!/usr/bin/env python
import sys
import os
import fnmatch
import json
import argparse
import copy
from zaplib.version import GameVersion
def find_file(search_file, parents=[]):
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, search_file):
abspath = os.path.abspath(os.path.join(root, filename))
if not all(p in abspath for p in parents):
continue
return abspath
print "> error: '{}' not found with parent dirs: '{}'".format(search_file, "/".join(parents))
sys.exit(-1)
def update_file(ver, path):
ver.saveToFile(path)
print "> successfully updated to version {}".format(ver)
def main():
# parse the arguments
parser = argparse.ArgumentParser(description='Increment the project version.')
group = parser.add_mutually_exclusive_group()
group.add_argument('--major', action='store_true', help='bump the major version.')
group.add_argument('--minor', action='store_true', help='bump the minor version.')
group.add_argument('--patch', action='store_true', help='bump the patch version.')
group.add_argument('--set', metavar='version', help='set the version to a higher number')
args = parser.parse_args()
# first, ensure that we can find version_data below this directory
path = find_file('version_data.json', ['Resources', 'AppInfo'])
curver = GameVersion.from_path(path)
if args.set:
newver = GameVersion.from_string(args.set)
if newver <= curver:
print "> error: ({}) does not increment the current version ({})".format(newver, curver)
sys.exit(-1)
else:
update_file(path, newver)
elif args.major or args.minor or args.patch:
newver = copy.copy(curver)
if args.major:
newver.bumpMajor()
elif args.minor:
newver.bumpMinor()
elif args.patch:
newver.bumpPatch()
update_file(newver, path)
else:
print "> current version: {}".format(curver)
if __name__ == '__main__':
main()