aboutsummaryrefslogtreecommitdiff
path: root/scripts/releaseCommon.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
commit48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (patch)
tree83645ddf58fd9514e1fe6d566839bb2747ee4706 /scripts/releaseCommon.py
downloadlibnitrokey-48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391.tar.gz
libnitrokey-48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391.tar.bz2
Squashed 'unittest/Catch/' content from commit ae5ee2cf
git-subtree-dir: unittest/Catch git-subtree-split: ae5ee2cf63d6d67bd1369b512d2a7b60b571c907
Diffstat (limited to 'scripts/releaseCommon.py')
-rw-r--r--scripts/releaseCommon.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/releaseCommon.py b/scripts/releaseCommon.py
new file mode 100644
index 0000000..14eb235
--- /dev/null
+++ b/scripts/releaseCommon.py
@@ -0,0 +1,89 @@
+from __future__ import print_function
+
+import os
+import sys
+import re
+import string
+
+from scriptCommon import catchPath
+
+versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
+rootPath = os.path.join( catchPath, 'include/' )
+versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
+readmePath = os.path.join( catchPath, "README.md" )
+
+class Version:
+ def __init__(self):
+ f = open( versionPath, 'r' )
+ for line in f:
+ m = versionParser.match( line )
+ if m:
+ self.variableDecl = m.group(1)
+ self.majorVersion = int(m.group(2))
+ self.minorVersion = int(m.group(3))
+ self.patchNumber = int(m.group(4))
+ self.branchName = m.group(5)
+ self.buildNumber = int(m.group(6))
+ f.close()
+
+ def nonDevelopRelease(self):
+ if self.branchName != "":
+ self.branchName = ""
+ self.buildNumber = 0
+ def developBuild(self):
+ if self.branchName == "":
+ self.branchName = "develop"
+ self.buildNumber = 0
+
+ def incrementBuildNumber(self):
+ self.developBuild()
+ self.buildNumber = self.buildNumber+1
+
+ def incrementPatchNumber(self):
+ self.nonDevelopRelease()
+ self.patchNumber = self.patchNumber+1
+
+ def incrementMinorVersion(self):
+ self.nonDevelopRelease()
+ self.patchNumber = 0
+ self.minorVersion = self.minorVersion+1
+
+ def incrementMajorVersion(self):
+ self.nonDevelopRelease()
+ self.patchNumber = 0
+ self.minorVersion = 0
+ self.majorVersion = self.majorVersion+1
+
+ def getVersionString(self):
+ versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
+ if self.branchName != "":
+ versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
+ return versionString
+
+ def updateVersionFile(self):
+ f = open( versionPath, 'r' )
+ lines = []
+ for line in f:
+ m = versionParser.match( line )
+ if m:
+ lines.append( '{0}( {1}, {2}, {3}, "{4}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
+ else:
+ lines.append( line.rstrip() )
+ f.close()
+ f = open( versionPath, 'w' )
+ for line in lines:
+ f.write( line + "\n" )
+
+ def updateReadmeFile(self):
+ f = open( readmePath, 'r' )
+ lines = []
+ for line in f:
+ lines.append( line.rstrip() )
+ f.close()
+ f = open( readmePath, 'w' )
+ for line in lines:
+ if line.startswith( "*v" ):
+ f.write( '*v{0}*\n'.format( self.getVersionString() ) )
+ else:
+ f.write( line + "\n" )
+