diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-28 12:26:41 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-28 16:58:41 +0100 |
commit | ffaf2aac05cf8d3664322b6ca349a5401c70ca34 (patch) | |
tree | 67398baaa03fcc3af62b75d8e49a4652f10a941b | |
parent | 62b52ff364bf2958a522f6c15ca5b6771d656def (diff) |
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.
-rw-r--r-- | utils/create_version_file.py | 77 |
1 files changed, 77 insertions, 0 deletions
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 <info@soleta.eu> +# +# 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) |