python CI/updateVersion.py %NEW_VERSION%
pyinstaller testApp.py --version-file "CI/version.py"
Created
December 9, 2019 15:57
-
-
Save JarekParal/24e15de33971674a8c0f9955f6ad15e0 to your computer and use it in GitHub Desktop.
Pyinstaller - update version during CI build / automatic update of version file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
FILE_WITH_VERSION_INFORMATIONS = "CI\\version" | |
if len(sys.argv) != 2: | |
print("""Problem with argument.\n | |
Expected exactly one argument with new version number - e.g. '1.23.0.0'""") | |
exit(1) | |
new_version = sys.argv[1] | |
if re.match(r"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", new_version) == None: | |
print("Wrong format of argument:", new_version, | |
"\nRequired format: 1.23.0.0") | |
exit(1) | |
new_version_commas = new_version.replace('.', ', ') | |
# Read data from template file | |
fin = open(FILE_WITH_VERSION_INFORMATIONS + "_template.py", "rt") | |
data = fin.read() | |
data = data.replace('filevers=(78, 0, 3904, 108)', | |
'filevers=(' + new_version_commas + ')') | |
data = data.replace('prodvers=(78, 0, 3904, 108)', | |
'prodvers=(' + new_version_commas + ')') | |
data = data.replace("u'FileVersion', u'78, 0, 3904, 108'", | |
"u'FileVersion', u'" + new_version + "'") | |
data = data.replace("u'ProductVersion', u'78, 0, 3904, 108'", | |
"u'ProductVersion', u'" + new_version + "'") | |
fin.close() | |
# Write the data to new output file | |
fin = open(FILE_WITH_VERSION_INFORMATIONS + ".py", "wt") | |
fin.write(data) | |
fin.close() | |
print(sys.argv[0], "- version updated to:", new_version) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version info from Google Chrome | |
# Get this info with util `pyi-grab_version` | |
# UTF-8 | |
# | |
# For more details about fixed file info 'ffi' see: | |
# http://msdn.microsoft.com/en-us/library/ms646997.aspx | |
VSVersionInfo( | |
ffi=FixedFileInfo( | |
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) | |
# Set not needed items to zero 0. | |
filevers=(78, 0, 3904, 108), | |
prodvers=(78, 0, 3904, 108), | |
# Contains a bitmask that specifies the valid bits 'flags'r | |
mask=0x17, | |
# Contains a bitmask that specifies the Boolean attributes of the file. | |
flags=0x0, | |
# The operating system for which this file was designed. | |
# 0x4 - NT and there is no need to change it. | |
OS=0x4, | |
# The general type of file. | |
# 0x1 - the file is an application. | |
fileType=0x1, | |
# The function of the file. | |
# 0x0 - the function is not defined for this fileType | |
subtype=0x0, | |
# Creation date and time stamp. | |
date=(0, 0) | |
), | |
kids=[ | |
StringFileInfo( | |
[ | |
StringTable( | |
u'040904b0', | |
[StringStruct(u'CompanyName', u'Google LLC'), | |
StringStruct(u'FileDescription', u'Google Chrome'), | |
StringStruct(u'FileVersion', u'78, 0, 3904, 108'), | |
StringStruct(u'InternalName', u'chrome_exe'), | |
StringStruct(u'LegalCopyright', u'Copyright 2019 Google LLC. All rights reserved.'), | |
StringStruct(u'OriginalFilename', u'chrome.exe'), | |
StringStruct(u'ProductName', u'Google Chrome'), | |
StringStruct(u'ProductVersion', u'78.0.3904.108'), | |
StringStruct(u'CompanyShortName', u'Google'), | |
StringStruct(u'ProductShortName', u'Chrome'), | |
StringStruct(u'LastChange', u'4b26898a39ee037623a72fcfb77279fce0e7d648-refs/branch-heads/3904@{#889}'), | |
StringStruct(u'Official Build', u'1')]) | |
]), | |
VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this code. I made a simpler version since I am only using it for argparse
--version
command.At the top of the spec file:
And this at the end to reset so that git doesn't notice changes every time