summaryrefslogtreecommitdiffstats
path: root/utils/create_version_file.py
blob: 46647662ec5998de4d0cc2e1def9120fe479e93a (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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', '{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)