#!/usr/bin/python3 # # Copyright (C) 2020-2024 Soleta Networks # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the # Free Software Foundation; either version 3 of the License, or # (at your option) any later version. import subprocess from datetime import datetime version_template = """ VSVersionInfo( ffi=FixedFileInfo( filevers=({major}, {minor}, {patch}, 0), prodvers=({major}, {minor}, {patch}, 0), mask=0x3f, flags=0x0, OS=0x40004, fileType=0x1, subtype=0x0, date=(0, 0) ), kids=[ StringFileInfo( [ StringTable( '040904B0', [ StringStruct('CompanyName', 'Soleta Networks'), StringStruct('FileDescription', '{appname} - OpenGnsys Client Application'), StringStruct('FileVersion', '{version}'), StringStruct('InternalName', '{appname}'), StringStruct('LegalCopyright', 'Copyright © {year} Soleta Networks'), StringStruct('OriginalFilename', '{appname}.exe'), StringStruct('ProductName', '{appname}'), StringStruct('ProductVersion', '{version}') ] ) ] ), VarFileInfo([VarStruct('Translation', [1033, 1200])]) ] ) """ def get_git_version(): try: version = subprocess.check_output( ["git", "describe", "--tags", "--always"], stderr=subprocess.STDOUT, text=True ).strip() return version except subprocess.CalledProcessError: return "0.0.0" def version_to_tuple(version): parts = version.lstrip("v").split("-")[0].split(".") version_tuple = [] for part in parts: if part.isdigit(): version_tuple.append(int(part)) else: version_tuple.append(0) return tuple(version_tuple) if __name__ == "__main__": version = get_git_version() major, minor, patch = version_to_tuple(version) current_year = datetime.now().year version_file = version_template.format(major=major, minor=minor, patch=patch, version=version, year=current_year, appname='ogclient') with open('ogclient-version-info.txt', 'w', encoding='utf-8') as f: f.write(version_file) version_file = version_template.format(major=major, minor=minor, patch=patch, version=version, year=current_year, appname='ogclient-systray') with open('systray-version-info.txt', 'w', encoding='utf-8') as f: f.write(version_file)