blob: 14eb235e5bf98e035ac0bdfce52a52603237e584 [file] [log] [blame]
Phil Nash21f7ef62015-06-29 18:05:23 +01001from __future__ import print_function
2
3import os
4import sys
5import re
6import string
7
8from scriptCommon import catchPath
9
10versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
11rootPath = os.path.join( catchPath, 'include/' )
12versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
13readmePath = os.path.join( catchPath, "README.md" )
14
15class Version:
16 def __init__(self):
17 f = open( versionPath, 'r' )
18 for line in f:
19 m = versionParser.match( line )
20 if m:
21 self.variableDecl = m.group(1)
22 self.majorVersion = int(m.group(2))
23 self.minorVersion = int(m.group(3))
24 self.patchNumber = int(m.group(4))
25 self.branchName = m.group(5)
26 self.buildNumber = int(m.group(6))
27 f.close()
28
29 def nonDevelopRelease(self):
30 if self.branchName != "":
31 self.branchName = ""
32 self.buildNumber = 0
33 def developBuild(self):
34 if self.branchName == "":
35 self.branchName = "develop"
36 self.buildNumber = 0
37
38 def incrementBuildNumber(self):
39 self.developBuild()
40 self.buildNumber = self.buildNumber+1
41
42 def incrementPatchNumber(self):
43 self.nonDevelopRelease()
44 self.patchNumber = self.patchNumber+1
45
46 def incrementMinorVersion(self):
47 self.nonDevelopRelease()
48 self.patchNumber = 0
49 self.minorVersion = self.minorVersion+1
50
51 def incrementMajorVersion(self):
52 self.nonDevelopRelease()
53 self.patchNumber = 0
54 self.minorVersion = 0
55 self.majorVersion = self.majorVersion+1
56
57 def getVersionString(self):
58 versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
59 if self.branchName != "":
60 versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
61 return versionString
62
63 def updateVersionFile(self):
64 f = open( versionPath, 'r' )
65 lines = []
66 for line in f:
67 m = versionParser.match( line )
68 if m:
69 lines.append( '{0}( {1}, {2}, {3}, "{4}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
70 else:
71 lines.append( line.rstrip() )
72 f.close()
73 f = open( versionPath, 'w' )
74 for line in lines:
75 f.write( line + "\n" )
76
77 def updateReadmeFile(self):
78 f = open( readmePath, 'r' )
79 lines = []
80 for line in f:
81 lines.append( line.rstrip() )
82 f.close()
83 f = open( readmePath, 'w' )
84 for line in lines:
85 if line.startswith( "*v" ):
86 f.write( '*v{0}*\n'.format( self.getVersionString() ) )
87 else:
88 f.write( line + "\n" )
89