Version eingebaut

This commit is contained in:
hubobel 2025-12-28 17:23:25 +01:00
parent 98d9a84031
commit e578d43f9c
2 changed files with 161 additions and 0 deletions

View file

@ -1,4 +1,5 @@
#V0.1.1b @PC #V0.1.1b @PC
from __future__ import annotations
import requests import requests
import json import json
from pathlib import Path from pathlib import Path
@ -12,6 +13,76 @@ import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from version import VERSION from version import VERSION
import subprocess
VERSION = "0.1.1"
APP_NAME = "Simbriefimport"
COMPANY = "Carsten"
COPYRIGHT = "© 2025 Carsten"
VERSION_INFO_FILE = Path("version_info.txt")
def _git_build_number() -> int:
try:
out = subprocess.check_output(
["git", "rev-list", "--count", "HEAD"],
stderr=subprocess.DEVNULL
)
return int(out.decode().strip())
except Exception:
return 0
def ensure_version_info(force: bool = False) -> str:
"""
Erzeugt version_info.txt für PyInstaller.
Gibt die Textversion zurück, z.B. '1.4.0.237'.
"""
build = _git_build_number()
major, minor, patch = map(int, VERSION.split("."))
filevers = f"{major},{minor},{patch},{build}"
textvers = f"{VERSION}.{build}"
if VERSION_INFO_FILE.exists() and not force:
return textvers
content = f"""VSVersionInfo(
ffi=FixedFileInfo(
filevers=({filevers}),
prodvers=({filevers}),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0,0)
),
kids=[
StringFileInfo(
[
StringTable(
'040904B0',
[
StringStruct('CompanyName', '{COMPANY}'),
StringStruct('FileDescription', '{APP_NAME}'),
StringStruct('ProductName', '{APP_NAME}'),
StringStruct('InternalName', '{APP_NAME}'),
StringStruct('OriginalFilename', '{APP_NAME}.exe'),
StringStruct('FileVersion', '{textvers}'),
StringStruct('ProductVersion', '{textvers}'),
StringStruct('LegalCopyright', '{COPYRIGHT}')
]
)
]
)
]
)
"""
VERSION_INFO_FILE.write_text(content, encoding="utf-8")
return textvers
def get_build(): def get_build():
try: try:
import subprocess import subprocess
@ -367,6 +438,9 @@ def delete(pfad_ogg):
pfad_ogg.unlink() pfad_ogg.unlink()
logging.info("Datei gelöscht: %s", pfad_ogg) logging.info("Datei gelöscht: %s", pfad_ogg)
return None return None
host = os.getcwd() host = os.getcwd()
Pfad = os.getcwd() + '/Announcements/' Pfad = os.getcwd() + '/Announcements/'
_airports_cache = None _airports_cache = None
@ -545,3 +619,6 @@ logging.info(" F E R T S C H ")
logging.info("--------------------------------------------------") logging.info("--------------------------------------------------")
logging.info("Version: %s.%s", VERSION, get_build()) logging.info("Version: %s.%s", VERSION, get_build())
#VERSION = str("Version: %s.%s", VERSION, get_build())
ver = ensure_version_info() # erzeugt version_info.txt im Dev-Workspace
logging.info("Programmversion: %s", ver)

84
make_version_info.py Normal file
View file

@ -0,0 +1,84 @@
from pathlib import Path
import subprocess
from version import VERSION
# =========================
# Konfiguration
# =========================
APP_NAME = "Simbriefimport"
COMPANY = "Carsten"
COPYRIGHT = "© 2025 Carsten"
OUTPUT_FILE = Path("version_info.txt")
def get_build_number() -> int:
"""
Ermittelt die Buildnummer aus Git (Commit-Zähler).
Fällt sauber auf 0 zurück, wenn Git nicht verfügbar ist.
"""
try:
out = subprocess.check_output(
["git", "rev-list", "--count", "HEAD"],
stderr=subprocess.DEVNULL
)
return int(out.decode().strip())
except Exception:
return 0
def main():
build = get_build_number()
try:
major, minor, patch = map(int, VERSION.split("."))
except ValueError:
raise RuntimeError(
f"VERSION '{VERSION}' muss dem Schema Major.Minor.Patch entsprechen"
)
filevers = f"{major},{minor},{patch},{build}"
textvers = f"{VERSION}.{build}"
content = f"""VSVersionInfo(
ffi=FixedFileInfo(
filevers=({filevers}),
prodvers=({filevers}),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0,0)
),
kids=[
StringFileInfo(
[
StringTable(
'040904B0',
[
StringStruct('CompanyName', '{COMPANY}'),
StringStruct('FileDescription', '{APP_NAME}'),
StringStruct('ProductName', '{APP_NAME}'),
StringStruct('InternalName', '{APP_NAME}'),
StringStruct('OriginalFilename', '{APP_NAME}.exe'),
StringStruct('FileVersion', '{textvers}'),
StringStruct('ProductVersion', '{textvers}'),
StringStruct('LegalCopyright', '{COPYRIGHT}')
]
)
]
)
]
)
"""
OUTPUT_FILE.write_text(content, encoding="utf-8")
print(f"Version_info erzeugt:")
print(f" Version: {textvers}")
print(f" Datei: {OUTPUT_FILE.resolve()}")
if __name__ == "__main__":
main()