forked from bretmckee/sxASCOM.old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.py
executable file
·85 lines (66 loc) · 2.94 KB
/
bump_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
from __future__ import print_function, with_statement
import sys, os, tempfile, re
import datetime, time
import subprocess
import errno
import StringIO
from contextlib import nested
from optparse import OptionParser
def runCmd(cmd):
#print(cmd)
try:
cmdProcess = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdoutData, stderrData) = cmdProcess.communicate(None)
return (cmdProcess.returncode, stdoutData, stderrData)
except:
raise
def runCmdOK(cmd):
(returnCode, stdoutData, stderrData) = runCmd(cmd)
if returnCode != 0:
print("{0} returned non-zero status.".format(cmd))
if len(stderrData):
print("stderr output was " + stderrData)
sys.exit(returnCode)
return stdoutData
def runCmdBool(cmd):
(returnCode, stdoutData, stderrData) = runCmd(cmd)
return returnCode == 0
def updateVersion(dirName, fileName, major, minor, revision, build):
print("processing", os.path.join(dirName, fileName))
lines = []
with open(os.path.join(dirName, fileName), "r+b") as file:
for line in file:
line = re.sub(r'AssemblyVersion([^)]*)', 'AssemblyVersion("{0}.{1}.{2}.{3}"'.format(major, minor, revision, build), line)
line = re.sub(r'AssemblyFileVersion([^)]*)', 'AssemblyFileVersion("{0}.{1}.{2}.{3}"'.format(major, minor, revision, build), line)
line = re.sub(r'APP_VERSION ".*"', 'APP_VERSION "{0}.{1}.{2}.{3}"'.format(major, minor, revision, build), line)
lines.append(line)
file.seek(0)
file.writelines(lines)
def updateVersions(major, minor, revision, build):
for root, dirs, files in os.walk("."):
if ".git" in dirs:
dirs.remove(".git")
for name in files:
if name.lower().endswith("assemblyinfo.cs"):
updateVersion(root, name, major, minor, revision, build)
updateVersion(".", "SXAscomInstaller.iss", major, minor, revision, build)
print('commit with:\ngit commit -a -m "changes for version {0}.{1}.{2}.{3}"'.format(major, minor, revision, build))
print('tag with:\ngit tag -a -m "tagging version {0}.{1}.{2}.{3}" v{0}.{1}.{2}.{3}'.format(major, minor, revision, build))
def main():
if len(sys.argv) != 1 and len(sys.argv) != 3:
print("usage: {0} [major minor]".format(sys.argv[0]), file=sys.stderr)
sys.exit(1)
description = runCmdOK("git describe")
if len(description.split("-")) == 1:
version = description
else:
(version, commits, hex) = description.split("-")
if len(sys.argv) == 3:
major = int(sys.argv[1])
minor = int(sys.argv[2])
else:
(major, minor, rest) = version[1:].split(".",2)
now = datetime.datetime.now()
updateVersions(major, minor, now.strftime("%y%j"), now.strftime("%H%M"))
if __name__ == "__main__":
main()