From ffaf2aac05cf8d3664322b6ca349a5401c70ca34 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 28 Nov 2024 12:26:41 +0100 Subject: install: add script to generate the windows metadata information file Add create_version_file.py, running this script creates a file version_info.txt with the data required for the Windows ogClient binary metadata. --- utils/create_version_file.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 utils/create_version_file.py (limited to 'utils') diff --git a/utils/create_version_file.py b/utils/create_version_file.py new file mode 100644 index 0000000..3d0a295 --- /dev/null +++ b/utils/create_version_file.py @@ -0,0 +1,77 @@ +#!/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', 'ogClient - OpenGnsys Client Application'), + StringStruct('FileVersion', '{version}'), + StringStruct('InternalName', 'ogclient'), + StringStruct('LegalCopyright', 'Copyright © {year} Soleta Networks'), + StringStruct('OriginalFilename', 'ogclient.exe'), + StringStruct('ProductName', 'ogClient'), + 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) + with open('version_info.txt', 'w', encoding='utf-8') as f: + f.write(version_file) -- cgit v1.2.3-18-g5258