|
| 1 | +""" |
| 2 | +
|
| 3 | +This script accepts a version number in the form X.Y.Z, where X, Y, and Z are integers. |
| 4 | +It will then update all LibRapid version numbers to the specified version. |
| 5 | +
|
| 6 | +""" |
| 7 | + |
| 8 | +import regex |
| 9 | +import argparse |
| 10 | +from datetime import datetime |
| 11 | + |
| 12 | +# Extract current version number |
| 13 | +currentMajorVersion = None |
| 14 | +currentMinorVersion = None |
| 15 | +currentPatchVersion = None |
| 16 | + |
| 17 | +try: |
| 18 | + with open("../version.txt", "r") as versionFile: |
| 19 | + text = versionFile.read() |
| 20 | + currentMajorVersion = regex.search("MAJOR [0-9]+", text).group().split()[1] |
| 21 | + currentMinorVersion = regex.search("MINOR [0-9]+", text).group().split()[1] |
| 22 | + currentPatchVersion = regex.search("PATCH [0-9]+", text).group().split()[1] |
| 23 | + print(f"Current Version: v{currentMajorVersion}.{currentMinorVersion}.{currentPatchVersion}") |
| 24 | +except Exception as e: |
| 25 | + print("[ ERROR ] Failed to read version.txt") |
| 26 | + print(e) |
| 27 | + exit(1) |
| 28 | + |
| 29 | +argParser = argparse.ArgumentParser() |
| 30 | +argParser.add_argument("-v", "--version", type=str, help="Full Version") |
| 31 | +argParser.add_argument("-M", "--major", type=int, help="Major Version") |
| 32 | +argParser.add_argument("-m", "--minor", type=int, help="Minor Version") |
| 33 | +argParser.add_argument("-p", "--patch", type=int, help="Patch Version") |
| 34 | + |
| 35 | +args = argParser.parse_args() |
| 36 | + |
| 37 | +if args.version and any([args.major, args.minor, args.patch]): |
| 38 | + print("[ ERROR ] -v and -M options cannot be used together") |
| 39 | + exit(1) |
| 40 | + |
| 41 | +newMajorVersion = args.major if args.major else currentMajorVersion |
| 42 | +newMinorVersion = args.minor if args.minor else currentMinorVersion |
| 43 | +newPatchVersion = args.patch if args.patch else currentPatchVersion |
| 44 | +print(f"New Version: v{newMajorVersion}.{newMinorVersion}.{newPatchVersion}\n\n") |
| 45 | + |
| 46 | +# Write to version.txt |
| 47 | +with open("../version.txt", "w") as versionFile: |
| 48 | + versionFile.write(f"MAJOR {newMajorVersion}\n") |
| 49 | + versionFile.write(f"MINOR {newMinorVersion}\n") |
| 50 | + versionFile.write(f"PATCH {newPatchVersion}\n") |
| 51 | + print("Written to version.txt") |
| 52 | + |
| 53 | +# Write to Doxyfile |
| 54 | +template = None |
| 55 | +with open("tmp/doxyTemplate", "r") as templateFile: |
| 56 | + template = templateFile.read() |
| 57 | + print("Loaded Doxyfile template") |
| 58 | + |
| 59 | +with open("../Doxyfile", "w") as doxyfile: |
| 60 | + versionString = f"PROJECT_NUMBER = v{newMajorVersion}.{newMinorVersion}.{newPatchVersion}" |
| 61 | + template = template.replace("$${{ INSERT_VERSION_NUMBER_HERE }}$$", versionString) |
| 62 | + doxyfile.write(template) |
| 63 | + print("Written to Doxyfile") |
| 64 | + |
| 65 | +# Write to CITATION.cff |
| 66 | +with open("tmp/citationTemplate.cff", "r") as templateFile: |
| 67 | + template = templateFile.read() |
| 68 | + print("Loaded CITATION.cff template") |
| 69 | + |
| 70 | +with open("../CITATION.cff", "w") as citationFile: |
| 71 | + versionString = f"version: {newMajorVersion}.{newMinorVersion}.{newPatchVersion}" |
| 72 | + dateString = f"date-released: \"{datetime.now().strftime('%Y-%m-%d')}\"" |
| 73 | + template = template.replace("$${{ INSERT_VERSION_NUMBER_HERE }}$$", versionString) |
| 74 | + template = template.replace("$${{ INSERT_DATE_HERE }}$$", dateString) |
| 75 | + citationFile.write(template) |
| 76 | + print("Written to CITATION.cff") |
0 commit comments