File size: 1,581 Bytes
985c397 | 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 | #! python
# SPDX-License-Identifier: LGPL-2.1-or-later
###
# A convenience script to generate a deployment archive name of the form
# FreeCAD_{Major Version Number}.{Minor Version Number}-{Git Revision Count}.{Git Short SHA}-{OS}-{Arch}
#
import sys, getopt, platform
def deserializeVersionHeader(path):
version = {}
try:
dat = open(path, "r").readlines()
except IOError:
print("Unable to open ", path)
raise
for l in dat:
tokens = l.split()
if len(tokens) > 1 and tokens[0].lower() == "#define":
version[tokens[1]] = tokens[2].replace('"', "")
return version
def main():
OSAbbrev = {"Windows": "WIN", "Darwin": "OSX"}
SHA = None
if len(sys.argv) < 2:
sys.stderr.write("Usage: archiveNameFromVersion <path to Version.h> [--git-SHA=]\n")
try:
opts, args = getopt.getopt(sys.argv[2:], "g:", ["git-SHA="])
except getopt.GetoptError:
pass
for o, a in opts:
if o in ("-g", "--git-SHA"):
SHA = a
version = deserializeVersionHeader(sys.argv[1])
if SHA:
version["FCRepositoryHash"] = SHA
print(
"FreeCAD_{Major}.{Minor}-{RevCount}.{GitShortSHA}-{OS}-{Arch}".format(
Major=version["FCVersionMajor"],
Minor=version["FCVersionMinor"],
RevCount=version["FCRevision"],
GitShortSHA=version["FCRepositoryHash"][0:7],
OS=OSAbbrev.get(platform.system(), "LIN"),
Arch=platform.machine(),
)
)
if __name__ == "__main__":
main()
|