Debian Codegraph @

util/winversion.py

raw
1 import os
2 import sys
3 import tempfile
4
5 sys.path.insert(
6 1,
7 os.path.join(
8 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "DisplayCAL"
9 ),
10 )
11
12
13 from DisplayCAL.meta import AUTHOR, DESCRIPTION, DOMAIN, NAME, VERSION_STRING, VERSION_TUPLE
14
15
16 def mktempver(
17 version_template_path, name_=NAME, description_=DESCRIPTION, encoding="UTF-8"
18 ):
19 version_template = open(version_template_path, "rb")
20 tempver_str = version_template.read().decode(encoding, "replace") % {
21 "filevers": str(VERSION_TUPLE),
22 "prodvers": str(VERSION_TUPLE),
23 "CompanyName": DOMAIN,
24 "FileDescription": description_,
25 "FileVersion": f"{VERSION_STRING}",
26 "InternalName": name_,
27 "LegalCopyright": f"© {AUTHOR}",
28 "OriginalFilename": f"{name_}.exe",
29 "ProductName": name_,
30 "ProductVersion": f"{VERSION_STRING}",
31 }
32 version_template.close()
33 tempdir = tempfile.mkdtemp()
34 tempver_path = os.path.join(tempdir, "winversion.txt")
35 if not os.path.exists(tempdir):
36 os.makedirs(tempdir)
37 tempver = open(tempver_path, "wb")
38 tempver.write(tempver_str.encode(encoding, "replace"))
39 tempver.close()
40 return tempver_path