|
| 1 | +#!/usr/bin/env python |
| 2 | +# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang |
| 3 | +# https://github.com/mathoudebine/turing-smart-screen-python/ |
| 4 | +# |
| 5 | +# Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine) |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | +# generate-version-info.py: generate PyInstaller .exe version file from version number in argument |
| 20 | +# Inspired from PyInstaller/utils/cliutils/grab_version.py and PyInstaller/utils/win32/versioninfo.py |
| 21 | + |
| 22 | +import codecs |
| 23 | +import sys |
| 24 | +from pathlib import Path |
| 25 | + |
| 26 | +from PyInstaller.utils.win32 import versioninfo |
| 27 | + |
| 28 | +# Load generic file and parse version info |
| 29 | +VERSION_INFO_FILE = str(Path(__file__).parent.resolve()) + "/pyinstaller-version-info.txt" |
| 30 | +info = versioninfo.load_version_info_from_text_file(VERSION_INFO_FILE) |
| 31 | + |
| 32 | +if not info: |
| 33 | + raise SystemExit("Error: VersionInfo resource not found in exe") |
| 34 | + |
| 35 | +# Get version number from argument |
| 36 | +version = sys.argv[1].split('.') |
| 37 | +major = int(version[0]) |
| 38 | +minor = int(version[1]) |
| 39 | +revision = int(version[2]) |
| 40 | +build = 0 # For this project we only use 3-digit versions |
| 41 | + |
| 42 | +# Update FixedFileInfo version |
| 43 | +info.ffi.fileVersionMS = (major << 16) + minor |
| 44 | +info.ffi.fileVersionLS = (revision << 16) + build |
| 45 | +info.ffi.productVersionMS = (major << 16) + minor |
| 46 | +info.ffi.productVersionLS = (revision << 16) + build |
| 47 | + |
| 48 | +# Update StringFileInfo version |
| 49 | +for elem in info.kids[0].kids[0].kids: |
| 50 | + if elem.name == 'ProductVersion' or elem.name == 'FileVersion': |
| 51 | + elem.val = f"{major}.{minor}.{revision}" |
| 52 | + |
| 53 | +# Update version file with new info, to be used by PyInstaller |
| 54 | +with codecs.open(VERSION_INFO_FILE, 'w', 'utf-8') as fp: |
| 55 | + fp.write(str(info)) |
| 56 | + |
| 57 | +print(f"Version info written to: {VERSION_INFO_FILE}") |
0 commit comments