Skip to content

Commit

Permalink
Tweaked the set_version.py file so it can set just the revision numbe…
Browse files Browse the repository at this point in the history
…r without changing the primary build numbers
  • Loading branch information
AlfieJ committed Jul 17, 2019
1 parent f7bdc04 commit 7636680
Showing 1 changed file with 59 additions and 20 deletions.
79 changes: 59 additions & 20 deletions src/set_version.py
Expand Up @@ -5,30 +5,43 @@
import shutil
import re
import codecs
import datetime

av = "[assembly: AssemblyVersion("
afv = "[assembly: AssemblyFileVersion("
ac = "[assembly: AssemblyCopyright(\""
ac = "[assembly: AssemblyCopyright("

p = re.compile("\"(\d+\.\d+\.\d+)(.\d+)?\"")
version = ""
revision = None
year = str(datetime.datetime.now().year)

def main(argv):
if len(argv) < 2:
show_usage()
return

# There's a limit of 65k for each segment of the
# version string, so go through each segment and
# mask out everything above that, then reassemble.
segments = argv[1].split(".")
for index, segment in enumerate(segments):
segments[index] = str(int(segment) % 0x0000FFFF)
global version, revision

if argv[1] == "-r" and len(argv) >= 3:
revision = argv[2]

print ("Setting revision to " + revision)

version = ""
for segment in segments:
if version != "":
version += "."
version += segment
if revision == None:
# There's a limit of 65k for each segment of the
# version string, so go through each segment and
# mask out everything above that, then reassemble.
segments = argv[1].split(".")
for index, segment in enumerate(segments):
segments[index] = str(int(segment) % 0x0000FFFF)

print ("Updating to " + version)
for segment in segments:
if version != "":
version += "."
version += segment

print ("Updating to " + version)

for root, dirs, files in os.walk("."):
for file in files:
Expand All @@ -38,9 +51,24 @@ def main(argv):
# NuGet packages folder. May want to revisit this
# to make it more flexible.
if path.startswith(".\\packages") == False and path.startswith(".\\HTMLRenderer") == False:
setVersion(path, version)
walkFile(path)

def fixBuild(prefix):
return prefix + "\"" + version + "\")]\r\n"

def setVersion(file, version):
def fixRevision(prefix, line):
m = p.search(line)
if m:
v = m.group(1) + "." + revision
# print ("Changing " + m.group(0) + " to " + v)

line = prefix + "\"" + v + "\")]\r\n"
else:
print ("Didn't match: " + line)

return line

def walkFile(file):
print (" - " + file)

lines = []
Expand All @@ -52,23 +80,34 @@ def setVersion(file, version):
# Could use regular expressions here, but this is
# probably faster and simpler
if line.startswith(av):
line = av + "\"" + version + "\")]\r\n"
if revision == None:
line = fixBuild(av)
else:
line = fixRevision(av, line)
elif line.startswith(afv):
line = afv + "\"" + version + "\")]\r\n"
if revision == None:
line = fixBuild(afv)
else:
line = fixRevision(afv, line)
elif line.startswith(ac):
line = u"[assembly: AssemblyCopyright(\"Copyright © Sandia National Laboratories 2019\")]\r\n"

line = u"[assembly: AssemblyCopyright(\"Copyright © Sandia National Laboratories " + year + "\")]\r\n"
# else:
# print ("Didn't match: " + line)

newLines.append(line)

with codecs.open(file, 'w', encoding="utf-8") as f:
f.writelines(newLines)

def show_usage():
print ("python set_version <version>")
print ("python set_version <version> | [-r <revision>]")
print (" where <version> is like x.y.z[.r]")
print (" x is major")
print (" y is minor")
print (" z is build")
print (" r is revision (optional)")
print (" or <revision> represents r")
print (" the existing x.y.z will be maintained, and will")
print (" be followed by .<revision>")

main(sys.argv)

0 comments on commit 7636680

Please sign in to comment.